슬라이드 1 - Korea University

Download Report

Transcript 슬라이드 1 - Korea University

Taekyung Kim
0x410 ~ 0x430
2014. 11. 20
2
• International Standards Organization (ISO) is a multinational
body dedicated to worldwide agreement on international
standards.
– Almost three-fourths of countries in the world are
represented in the ISO.
• An ISO standard that covers all aspects of network
communications is the Open Systems Interconnection (OSI)
model.
– It was first introduced in the late 1970s.
• The OSI model is a layered framework for the design of
network systems that allows communication between all
types of computer systems
3
Physical: transmit bits over a medium
Data link: organize bits into a frame
Network: move packets from source to destination
Transport: provide reliable process-to-process message
delivery
• Session: establish, manage, and terminate sessions
• Presentation: translate, encrypt and compress data
• Application: allow access to the network resources
•
•
•
•
4
• Encapsulation
5
• Message Propagation
Client
Router A
Router B
Server
6
• The physical layer consists of the basic networking
hardware transmission technologies of a network
• The bit stream may be grouped into code words or
symbols and converted to a physical signal that is
transmitted over a hardware transmission medium
7
• The data link layer is the protocol layer that transfers data
between nodes on the same LAN segment
• Data link layer services
– Encapsulation of network layer data packets into frames
– Frame synchronization
– Logic link control sublayer
• Error control (ARQ)
• Flow control
– Media access control (MAC) sublayer
• Multiple access protocols for channel-access control (e.g.
CSMA/CD, CSMA/CA)
• Physical addressing (MAC addressing)
• LAN switching (packet switching)
• Data packet queuing or scheduling
8
• Address Resolution Protocol (ARP)
– is used to convert an IP address to a MAC address
9
• The network layer is responsible for packet forwarding
including routing through intermediate routers
• Protocols
– IPv4 / IPv6: Internet Protocol
– ICMP: Internet Control Message Protocol
– ARP: Address Resolution Protocol
– IGMP: Internet Group Management Protocol
– PIM-SM: Protocol Independent Multicast Sparse
Mode
– PIM-DM: Protocol Independent Multicast Dense
Mode
– RIP: Routing Information Protocol
10
• IPv4 Header Format
11
• IPv4 Fragmentation
– Separated into MTU
(maximum transmission
unit) size
12
• Internet Control Message Protocol (ICMP)
– is used by network devices, like routers, to send
error message indicating
• for example a requested service is not available or a host
or router could not be reached
– is assigned protocol number 1
• But it is still network layer protocol
13
• Internet Control Message Protocol (Cont’d)
– Ping
• operates by sending ICMP echo request packets to the
target host and waiting for an ICMP echo response
– Traceroute
14
• A transport layer provides end-to-end communication
services for applications
• Transport layer services
– Same order delivery
• Segment numbering
– Reliability
• ACK message
– Flow control
– Congestion avoidance
– Multiplexing
• Ports
15
• TCP Header Format
16
• TCP Three Way Handshaking
seq: 8000
UAPRS F
SYN
seq: 15000
ack: 8001
nd: 5000
U A P R S F rw
SYN + ACK
seq: 8000
ack: 15001
UAPRS F
rwnd: 10000
ACK
17
• TCP Congestion Control
18
19
• A socket is an endpoint of an inter-process
communication flow across a computer network
– A socket address is the combination of an IP
address and a port number
• (src_ip, src_port, dst_ip, dst_port)
– Based on this address, sockets deliver incoming
data packets to the appropriate application process
or thread
20
• Header files
– <sys/socket.h>
• Core Berkely Software Distribution (BSD) socket functions
and data structures
– <netinet/in.h>
• AF_INET and AF_INET6 address families
– <arpa/inet.h>
• Functions for manipulating numeric IP addresses
– <netdb.h>
• Functions for translating protocol names and host names
into numeric addresses
21
• socket(int domain, int type, int protocol)
– creates a new socket of a certain socket type and
allocates system resources to it
• connect(int fd, struct sockaddr *remote_host, socklen_t
addr_length)
– is used on the client side, and assigns a free local
port number to a socket
– attempts to establish a new TCP connection
• bind(int fd, struct sockaddr *remote_host, socklen_t
addr_length)
– is used on the server side, and associates a socket
with a socket address structure
22
• listen(int fd, int backlog_queue_size)
– is used on the server side, and causes a bound TCP
socket to enter listening state
– store requests into a backlog queue
• accept(int fd, struct sockaddr *remote_host, socklen_t
*addr_length)
– is used on the server side
– accepts a received incoming attempt to create a
new TCP connection from the remote client
• send(), recv(), write(), read(), sendto(), recvfrom()
– are used for sending and receiving data to/from a
remote host
23
• socket(int domain, int type, int protocol)
– Domain
• AF_INET: IPv4
• AF_INET6: IPv6
– Type
• SOCK_STREAM: reliable stream
• SOCK_DGRAM: datagram service
• SOCK_RAW: raw protocols
– Protocol
• IPPROTO_TCP, IPPROTO_UDP, IPPROTO_RAW, and so on
• The value ‘0’ is used to select a default protocol from the
selected domain and type
24
• AF_INET v.s. PF_INET
– At socket.h
•
•
•
•
/* Protocol families. */
#define PF_INET 2 /* IP protocol family. */
/* Address families. */
#define AF_INET PF_INET
– The current POSIX.1-2008 specification doesn’t
specify any of PF_-constants, but only AF_constants
25
• htonl(), htons(), ntohl(), ntohs()
– convert values between host and network byte
order
– On the i386 the host byte order is LSB first, whereas
the network byte order is MSB first
26
• inet_aton(), inet_ntoa()
– Internet address manipulation routines
– inet_aton() converts the Internet host address, given
in IPv4 dotted notation, to a network bytes
– inet_ntoa() converts the Internet host address, given
in network byte order, to a string in IPv4 dotted
notation
27
• Create a socket
– SO_REUSEADDR option
• the socket can be successfully bound unless there is a
conflict with another socket bound to exactly the same
combination of source address and port
• Specify the address
28
• Bind the socket
• Accept a connection and print received bytes
29
30
• Well-known ports
– The port numbers in the range from 0 to 1023 are
the well-known ports
– They are used by system processes that provide
widely used types of network services
– Example
•
•
•
•
•
•
20: ftp-data
21: ftp-command
22: ssh
23: telnet
80: http
443: https
31
• HTTP HEAD Command
32
• gethostbyname(const char *name)
– returns a structure of type hostent for the given
host name
– name can be either a hostname or an IPv4 address
in dot notation or IPv6 address in colon notation
33
34
• Get webserver id by using a HTTP HEAD command
• Get host address
• Send a HTTP GET command and filter received data
35
36
• Handle HTTP GET and HTTP HEAD command
• Open a socket with an 80 (HTTP) port
37
• handle_connection()
38
• handle_connection() (Cont’d)
39
• ./webserver_id localhost
40
• Web Browser Test
41
42