Transport Protocols Overview

36
Transport Protocols Transport Protocols Overview Overview

description

Transport Protocols Overview. provide logical communication between app processes running on different hosts transport protocols run in end systems send side: breaks app messages into segments , passes to network layer rcv side: reassembles segments into messages, passes to app layer - PowerPoint PPT Presentation

Transcript of Transport Protocols Overview

Page 1: Transport Protocols Overview

Transport Protocols OverviewTransport Protocols Overview

Page 2: Transport Protocols Overview

Transport services and protocolsTransport services and protocols

provide logical communication between app processes running on different hosts

transport protocols run in end systems send side: breaks app

messages into segments, passes to network layer

rcv side: reassembles segments into messages, passes to app layer

more than one transport protocol available to apps Internet: TCP and UDP

application

transportnetworkdata linkphysical

application

transportnetworkdata linkphysical

networkdata linkphysical

networkdata linkphysical

networkdata linkphysical

networkdata linkphysicalnetwork

data linkphysical

logical end-end transport

Page 3: Transport Protocols Overview

TCP versus UDPTCP versus UDP TCP

connection-oriented reliable byte stream

Application: typically concurrent server SMTP(Simple Mail

Transfer Protocol) Telnet FTP HTTP NNTP(Network News

TP)

UDP connectionless unreliable datagram

Applications: typically iterative server SNMP(Simple Network

Management Protocol) TFTP(Trivial FTP) BOOTP(Bootstrap

Protocol) DHCP(Bootstrap

Protocol)

Page 4: Transport Protocols Overview

TCP OverviewTCP Overview

full duplex data: MSS: maximum segment

size

connection-oriented: flow controlled: point-to-point:

reliable, in-order byte steam: no โ€œmessage boundariesโ€

pipelined: TCP congestion and flow

control set window size

send & receive buffers

send() recv()

send() ๋ž€ send buffer ์— ์ผ๋‹ค๋Š” ์˜๋ฏธ์ด์ง€ ,๋ณด๋ƒˆ๋‹ค๋Š” ์˜๋ฏธ๊ฐ€ ์•„๋‹ˆ๋‹ค .send() ๋ž€ send buffer ์— ์ผ๋‹ค๋Š” ์˜๋ฏธ์ด์ง€ ,๋ณด๋ƒˆ๋‹ค๋Š” ์˜๋ฏธ๊ฐ€ ์•„๋‹ˆ๋‹ค .

Page 5: Transport Protocols Overview

TCP segment structureTCP segment structure

source port # dest port #

32 bits

applicationdata

(variable length)

sequence number

acknowledgement numberReceive window

Urg data pnterchecksum

FSRPAUheadlen

notused

Options (variable length)

URG: urgent data (generally not used)

ACK: ACK #valid

PSH: push data now(generally not used)

RST, SYN, FIN:connection estab(setup, teardown

commands)

# bytes rcvr willingto accept

countingby bytes of data(not segments!)

Internetchecksum

(as in UDP)

Page 6: Transport Protocols Overview

Multiplexing/demultiplexingMultiplexing/demultiplexing

application

transport

network

link

physical

P1 application

transport

network

link

physical

application

transport

network

link

physical

P2P3 P4P1

host 1 host 2 host 3

= process= socket

delivering received segmentsto correct socket

Demultiplexing at rcv host:gathering data from multiplesockets, enveloping data with header (later used for demultiplexing)

Multiplexing at send host:

Page 7: Transport Protocols Overview

Connectionless demux (cont)Connectionless demux (cont)

DatagramSocket serverSocket = new DatagramSocket(6428);

ClientIP:B

P2

client IP: A

P1P1P3

serverIP: C

SP: 6428

DP: 9157

SP: 9157

DP: 6428

SP: 6428

DP: 5775

SP: 5775

DP: 6428

SP provides โ€œreturn addressโ€

Page 8: Transport Protocols Overview

Connection-oriented demux (cont)Connection-oriented demux (cont)

ClientIP:B

P1

client IP: A

P1P2P4

serverIP: C

SP: 9157

DP: 80

SP: 9157

DP: 80

P5 P6 P3

D-IP:CS-IP: A

D-IP:C

S-IP: B

SP: 5775

DP: 80

D-IP:CS-IP: B

Page 9: Transport Protocols Overview

Sockets IntroductionSockets Introduction

Page 10: Transport Protocols Overview

Protocols and their ImplementationProtocols and their Implementation Protocol Implementation

๋ณดํ†ต transport layer ์ดํ•˜ protocol ๋“ค์€ kernel (OS) ๋‚ด์— ์ƒ์ฃผํ•œ๋‹ค . Why?

Link layer ๋Š” H/W ์™€ ์ด๋ฅผ ์ปดํ“จํ„ฐ์— ์žฅ์ฐฉํ•˜๊ธฐ ์œ„ํ•œ S/W (์˜ˆ : Ethernet driver) ๋กœ ๊ตฌํ˜„๋œ๋‹ค .

Application protocol ์€ user process ( ์ฆ‰ , application) ์œผ๋กœ ๊ตฌํ˜„๋œ๋‹ค .

Client-server model Internet ์—์„œ ๋งŽ์€ application

protocol ์€ ์ด model ์„ ๊ฐ€์ •ํ•˜๊ณ  ์žˆ๋‹ค .

Server ๋Š” ์—ฌ๋Ÿฌ client ์˜ ์š”์ฒญ์„ ๋™์‹œ์— ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค .

Peer-to-peer model Peer ๋‚ด์— client ์™€ server ๋ชจ๋‘

๊ฐ€์ง€๊ณ  ์žˆ๋Š” model ๋กœ ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ๋‹ค .

S/W

H/W EthernetAdapter

EthernetAdapter

Page 11: Transport Protocols Overview

Socket APISocket API API: Application Program Interface

User process ๊ฐ€ kernel ์‚ฌ์ด์˜ interface ๋ฅผ API ๋ผ๊ณ  ํ•œ๋ฉฐ , ํ”ํžˆ system call ์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค .

Function call vs. system call Socket API is an API for communications

๊ฐ€์žฅ ๋„๋ฆฌ ์“ฐ์ด๋Š” Communication API ์—ฌ๋Ÿฌ protocol suite ์— ๋Œ€ํ•ด generic API ์ œ๊ณต Transport, network, link layer ์˜ ์„œ๋น„์Šค๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” API ๋„ ์ œ๊ณต

Page 12: Transport Protocols Overview

What is a socket?What is a socket? A handle (or descriptor) to a data structure

Not a pointer! The data structure lives in the kernel. UNIX/LINUX ์—์„œ๋Š” socket ๋„ file ์ฒ˜๋Ÿผ ์‚ฌ์šฉ ๊ฐ€๋Šฅ sockfd = socket(PF_INET, SOCK_STREAM, 0);

user-level library of functions send(sockfd, ...), recv(sockfd, โ€ฆ), โ€ฆ

a single system call via trap (special instruction causing software interrrupt) sys_socketcall(SEND, sockfd, โ€ฆ)

File, device

socket

Page 13: Transport Protocols Overview

Data Structure in Kernel (BSD)Data Structure in Kernel (BSD)

ํ”„๋กœ์„ธ์Šค์—์„œ๋Š” handle (descriptor) ๋กœ socket structure ๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค .

Socket (file) ์— ๋Œ€ํ•ด read, write, select, close ๋“ฑ์˜ ์ผ๋ฐ˜์ ์ธ file operation ์„ socket ํŠน์„ฑ์— ๋งž๊ฒŒ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค .

Incoming packet ์˜ header ๋ฅผ ๋ณด๊ณ  ํ•ด๋‹น๋˜๋Š” socket ์„ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค . TCP: (local addr, local port,

foreign addr, foreign port) Connected UDP socket ์ธ

๊ฒฝ์šฐ์—๋„ ํ•ด๋‹น

UDP: (local addr, local port)

UDP socket creationsockfd=socket(PF_INET, SOCK_DGRAM, 0);

sockfd

Page 14: Transport Protocols Overview

Transport Protocol

Sending and Receiving via SocketSending and Receiving via Socket

Address family

Local addr Foreign addr

Local port Foreign port

Recv bufferRecv buffer Send bufferSend buffer

Client App

Server App

Transport Protocol

Address family

Local addr Foreign addr

Local port Foreign port

Recv bufferRecv buffer Send bufferSend buffer

Socket API(Operations)

A TCP connection

Socketdescriptor

Page 15: Transport Protocols Overview

Socket Address StructuresSocket Address Structures

Page 16: Transport Protocols Overview

IPv4 SA structure

Generic SA structure SA structure ์˜ pointer ๋ฅผ casting ํ•  ๋•Œ๋งŒ ์‚ฌ์šฉ

IPv4 Socket Address StructureIPv4 Socket Address Structure SA structure itself are

used only on a given host, not used for communication

POSIX datatypes

always set to 0

Page 17: Transport Protocols Overview

Elementary Elementary Sockets APISockets API

Page 18: Transport Protocols Overview

TCP Client-Server Procedure TCP Client-Server Procedure 12.106.32.254192.168.42.1

206.168.112.219203.253.70.44

foreignlocal

????

foreignlocal

21150012.106.32.254206.168.112.219

foreignlocal

?21?0

foreignlocal

?21?0

foreignlocal

150021206.168.112.21912.106.32.254

Listening socket (=3)

Connected socket (=4)

FIN

TCP segment

foreignlocal

????

INADDR_ANY

Page 19: Transport Protocols Overview

socket(): Create a Socketsocket(): Create a Socket

Socket descriptor is a file descriptor in UNIX systems, but is not a file descriptor in Windows

field local foreign

addr ? ?

port ? ?

TCP socket

#include <sys/socket.h> /* UNIX */#include <winsock2.h> /* Windows */SOCKET socket (int family, int type, int protocol);Returns: socket descriptor on success, -1 (UNIX) or INVALID_SOCKET (Windows) on failure

Page 20: Transport Protocols Overview

#include <sys/socket.h> /* UNIX */#include <winsock2.h> /* Windows */int connect (SOCKET s, const struct sockaddr *peer, int peer_len);Returns: 0 on success, -1 (UNIX) or nonzero (Windows) on failure

connect(): Establish the Connectionconnect(): Establish the Connection

Kernel ์€ ๋ฏธ์‚ฌ์šฉ ์ค‘์ธ port ๋ฒˆํ˜ธ๋ฅผ ํƒํ•˜๊ณ  , forwarding table์„ loopkup ํ•˜์—ฌ peer ๋กœ ์ „์†กํ•  interface ์˜ IP address ๋ฅผ source(local) IP ์ฃผ์†Œ๋กœ ๊ฒฐ์ •ํ•œ๋‹ค .

3-way handshake Error ๊ฐ€ ๋ฐœ์ƒํ•œ ์ด์œ 

extern int errno; /* UNIX */ GetLastError(); /* Windows */ No response to SYN: connection timeout (ETIMEDOUT)

๋‹ค์‹œ 3 ๋ฒˆ retry ํ›„ , ์ด 75 ์ดˆ ์ง€๋‚˜๋ฉด error return Response is RST: no such server process (ECONNREFUSED) Receive ICMP unreachable error message: host unreachable

(EHOSTUNREACH or ENETUNREACH) connection ์ด ์‹คํŒจํ•˜๋ฉด , socket ์€ ๋” ์ด์ƒ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์œผ๋ฏ€๋กœ

close() ํ•ด์•ผ ํ•œ๋‹ค .

field local foreign

addr 206.168.112.219 12.106.32.254

port 1500 13

TCP socket - client

Page 21: Transport Protocols Overview

Send: Put the message (of length len in buf) into the TCP(socket) send buffer

Blocked if not enough space in TCP send buffer

Recv: Get a message(<= bufsize) from the TCP(socket) receive buffer

Blocked until TCP receive buffer becomes non-empty

n-byte message ๋ฅผ send()ํ–ˆ๋‹ค๊ณ  ํ•ด์„œ , ์ˆ˜์‹ ์ธก์—์„œ recv() ํ•  ๋•Œ n-byte ๋ฅผ ๋ฐ›๋Š” ๊ฒŒ ์•„๋‹ˆ๋‹ค .

send(), recv(): TCP Data Transmissionsend(), recv(): TCP Data Transmission

field local foreign

addr 206.168.112.219 12.106.32.254

port 1500 13

TCP socket - client

field local foreign

addr 12.106.32.254 206.168.112.219

port 13 1500

TCP connected socket - server

#include <sys/socket.h> /* UNIX */#include <winsock2.h> /* Windows */int recv (SOCKET s, void *buf, size_t bufsize, int flags);int read (SOCKET s, void *buf, size_t bufsize); /* UNIX */Returns: # of bytes read (>0), 0 if received FIN and no more data, -1 on failure

int send (SOCKET s, const void *buf, size_t len, int flags);int write (SOCKET s, const void *buf, size_t len); /* UNIX */Returns: # of bytes transferred on success, -1 on failure

Page 22: Transport Protocols Overview

bind(): Set My Addressbind(): Set My Address

If port # = 0, the kernel chooses a port (ephemeral port) If wildcard address(INADDR_ANY), the kernel chooses IP addr

Example: IPv4struct sockaddr_in servaddr;sockfd = socket(AF_INET, SOCK_STREAM, 0);bzero(&servaddr, sizeof(servaddr));seraddr.sin_family = AF_INET;seraddr.sin_addr.s_addr = htonl(INADDR_ANY);/* wild card */seraddr.sin_port = htons(13); /* Daytime server */bind(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr));

Example: IPv6struct sockaddr_in6 servaddr;seraddr.sin6_addr.s_addr =in6addr_any; /* wild card */

TCP listening socket - serverfield local foreign

addr * (0) ?

port 13 ?

#include <sys/socket.h> /* UNIX */#include <winsock2.h> /* Windows */int bind (SOCKET s, const struct sockaddr *myaddr, int addrlen);Returns: 0 on success, -1 (UNIX) or SOCKET_ERROR (Windows) on error

Page 23: Transport Protocols Overview

listen(): Convert to the Listening Socketlisten(): Convert to the Listening Socket

Listening socket: connection request ๋ฅผ accept ํ•  ์ˆ˜ ์žˆ๋Š” socket ๋™์‹œ์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ 3-way handshaking ํ•  ์ˆ˜ ์žˆ๊ฒŒ queue ๊ฐ€ ํ•„์š”ํ•จ Queue size ๋Š” backlog( ๋ณดํ†ต 5) ๋กœ ์ •์˜

์ฐธ๊ณ  : backlog ์˜ ์ˆ˜๋Š” ์‹ค์ œ queue size ์™€ ์ผ์น˜ํ•˜์ง€ ์•Š๊ณ  , OS ๋งˆ๋‹ค ๋‹ค๋ฅด๋‹ค .

Data ๋ฅผ ์†ก์ˆ˜์‹  ํ•  ์ˆ˜ ์—†์Œ TCP state transition: CLOSED LISTEN TCP listening socket - server

field local foreign

addr * (0) ?

port 13 ?

queue

#include <sys/socket.h> /* UNIX */#include <winsock2.h> /* Windows */int listen (SOCKET s, int backlog);Returns: 0 on success, -1 (UNIX) or SOCKET_ERROR (Windows) on error

Page 24: Transport Protocols Overview

#include <sys/socket.h> /* UNIX */#include <winsock2.h> /* Windows */SOCKET accept (SOCKET s, struct sockaddr *cliaddr, int *addrlen);Returns: a connected socket on success, -1 (UNIX) or INVALID_SOCKET (Windows) on failure

accept(): Accept a Connection Request accept(): Accept a Connection Request and create the Connected Socketand create the Connected Socket

field local foreign

addr * (0) ?

port 13 ?

blocked if the completed connection queue is empty

If the identity of client is not interested, use NULL pointer instead of cliaddr, addrlen

field local foreign

addr 12.106.32.254 206.168.112.219

port 13 1500

TCP listening socket - server

TCP connected socket - server

Page 25: Transport Protocols Overview

close(): close the socket and terminate the close(): close the socket and terminate the TCP connection if no more usedTCP connection if no more used

Socket send buffer ์— data ๊ฐ€ ๋‚จ์•„ ์žˆ์œผ๋ฉด ๋ณด๋‚ธ๋‹ค Reference_count-- ๋งŒ์ผ , ์ด socket ์„ ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค์™€ ๊ณต์œ ํ•˜๊ณ  ์žˆ๋‹ค๋ฉด (if reference_count >

0), return ๋…์  ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค๋ฉด (if reference_count == o), ์ •์ƒ์ ์ธ TCP connection

termination (graceful termination) ์ด ์ด๋ฃจ์–ด์ง„๋‹ค . ์ฆ‰ , FIN, ACK ๋ฅผ ๊ตํ™˜ํ•œ๋‹ค . Close ๋˜๋ฉด , ๋” ์ด์ƒ send/recv ๋ถˆ๊ฐ€๋Šฅ

#include <unistd.h> /* UNIX */#include <winsock2.h> /* Windows */int close (SOCKET s); /* UNIX */int closesocket (SOCKET s); /* Windows */Returns: 0 on success, -1 on error

Client ๊ฐ€ server ์—๊ฒŒ request ๋ฅผ ๋ชจ๋‘ ๋ณด๋ƒˆ๋‹ค๊ณ  ์•Œ๋ฆฌ๊ณ  ์‹ถ๋‹ค . ( ์ฆ‰ , FIN์„ ๋ณด๋‚ด๊ณ  ์‹ถ๋‹ค .) ๊ทธ๋Ÿฌ๋‚˜ , server ๋กœ ๋ถ€ํ„ฐ์˜ response๋Š” ๊ณ„์† ๋„์ฐฉํ•  ๊ฒƒ์ด๊ณ  , ์ด๋ฅผ recv()ํ•ด์•ผ ํ•œ๋‹ค . ๋ฐฉ๋ฒ•์€ ?

Page 26: Transport Protocols Overview

close close versusversus shutdown shutdown Close

decrease reference count close the socket only if count == 0 terminates both directions of data

transfer: reading and writing Cannot read after close

Shutdown initiate TCPโ€™s normal termination

regardless of reference count terminates one direction (half of

connection)

SHUT_RD (SD_RECEIVE, Windows): read-half of the connection is closed Any data currently in socket receive buffer is discarded Any data received after this call is acknowledged and then silently discarded

SHUT_WR (SD_SEND, Windows): write-half of the connection is closed(half-close) Any data currently in socket send buffer will be sent

SHUT_RDWR (SD_BOTH, Windows): read-half and write-half of connection are both closed SHUT_RD + SHUT_WR

#include <sys/socket.h> /* UNIX */#include <winsock2.h> /* Windows */int shutdown (SOCKET s, int howto);Returns: 0 on success, -1 on error

Page 27: Transport Protocols Overview

#include <sys/socket.h> /* UNIX */#include <winsock2.h> /* Windows */int getsockname (SOCKET s, struct sockaddr *localaddr, int *addrlen);int getpeername (SOCKET s, struct sockaddr *peeraddr, int *addrlen);Returns: 0on success, -1 on error

Finding Protocol Addresses from socketsFinding Protocol Addresses from sockets

When is getsockname function required ? client ๊ฐ€ connect ํ›„ ์ž์‹ ์˜ IP

addr/port # ๋ฅผ ์•Œ๊ณ ์ž ํ•  ๋•Œ 0 ์ธ port # ๋กœ bind ํ•œ ํ›„ assign

๋œ local port # ๋ฅผ ์•Œ๊ณ ์ž ํ•  ๋•Œ socket ์˜ address family ๋ฅผ

์•Œ๊ณ ์ž ํ•  ๋•Œ server ๊ฐ€ wildcard IP addr ๋ฅผ

bind ํ•˜์—ฌ connection ์ด ์ด๋ฃจ์–ด์ง„ ํ›„ (accept ๊ฐ€ return ๋œ ํ›„ ) local IP addr ๋ฅผ ์•Œ๊ณ ์ž ํ•  ๋•Œ

When is getpeername function required ? server ๊ฐ€ accept ํ›„ child

process ๊ฐ€ fork ๋˜๊ณ  exec๋˜๋ฉด client ๋ฅผ ์•Œ ์ˆ˜ ์—†์Œ (์˜ˆ , inetd)

field local foreign

addr 206.168.112.219 12.106.32.254

port 1500 13

Page 28: Transport Protocols Overview

#include <sys/socket.h> /* UNIX */#include <winsock2.h> /* Windows */int recvfrom (SOCKET s, void *buf, size_t bufsize, int flags,

struct sockaddr *from, int *fromlen);int sendto (SOCKET s, const void *buf, size_t len, int flags,

const struct sockaddr *to, int tolen);Returns: datagram length on success, -1 on failure

UDP Datagram TransmissionUDP Datagram Transmission

No connection is needed. Recvfrom: ๋ฉ”์‹œ์ง€๋ฅผ recv ํ•˜๊ณ  ์†ก์‹ ์ž (from) ํ™•์ธ

If 0 returns : datagram of length 0 (???) If no interest in senders address

from : NULL, addrlen : NULL Recv ํ•  ๋•Œ ๋งˆ๋‹ค ์†ก์‹ ์ž๊ฐ€ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค .

Sendto: ๋ฉ”์‹œ์ง€๋ฅผ ์ˆ˜์‹ ์ž (to) ์—๊ฒŒ send Send ํ•  ๋•Œ ๋งˆ๋‹ค ์ˆ˜์‹ ์ž๊ฐ€ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค .

Page 29: Transport Protocols Overview

May Lost via UDP Socket Comm.May Lost via UDP Socket Comm. Lost datagram due to

lost in network socket receive buffer overflow

UDP has no flow control

Lost ๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด , UDP ๋ฅผ ํ†ตํ•œ ์†ก์ˆ˜์‹ ์‹œ message ๊ฒฝ๊ณ„๊ฐ€ ์œ ์ง€๋œ๋‹ค . ์†ก์‹ ํ•œ ๋ฉ”์‹œ์ง€๋Š” ํฌ๊ธฐ๊ฐ€ ์œ ์ง€๋œ ์ฑ„๋กœ ์ˆ˜์‹ ๋œ๋‹ค . ์˜ˆ์™ธ์ ์œผ๋กœ , ์ˆ˜์‹ ๋œ ๋ฉ”์ง€์ง€๊ฐ€ ์งค๋ฆด ์ˆ˜ ์žˆ๋‹ค .

(truncated) ์ˆ˜์‹ ๋œ ๋ฉ”์‹œ์ง€์— ๋น„ํŠธ์—๋Ÿฌ๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค .

Page 30: Transport Protocols Overview

Connected UDP SocketConnected UDP Socket Call connect only to communication with exactly one peer

Kernel just records IP address and port # of the peer Connected UDP socket

No need to specify the destination IP addr and port # for output operation write, send instead of sendto

No need to verify received response read, recv instead of recvfrom

Asynchronous errors are returned Connected UDP socket provides better performance

Unconnected UDP socket: make a temporary connection(1/3 overhead) May connect multiple times for a UDP socket by specifying a new IP

addr and port #

ํ•˜๋‚˜์˜ ์ง€์ •๋œ ์ƒ๋Œ€์™€ UDP ํ†ต์‹ ํ•  ๋•Œ๋Š”TCP ์ฒ˜๋Ÿผ connect() ํ•˜์—ฌ send(), recv()ํ•˜๋Š” ํŽธ์ด ์ข‹๋‹ค .

Page 31: Transport Protocols Overview

Miscellaneous FunctionsMiscellaneous Functions

Page 32: Transport Protocols Overview

Value-Result ArgumentsValue-Result Arguments

SA structure are always passed by reference

process to kernel: bind, connect, sendto

kernel to process: accept, recvfrom, getsockname,getpeername

struct sockaddrstruct sockaddr

Page 33: Transport Protocols Overview

Byte OrderingByte Ordering

Host Byte Order Network Byte Order

ํ”„๋กœํ† ์ฝœ์—์„œ ๊ทธ๋Œ€๋กœ header ์— ์‹ฃ์„ ์ˆ˜ ์žˆ๋„๋กNetwork address ์™€ port ๋Š” ํ•ญ์ƒ network byte order ๋กœ ์ €์žฅ๋˜์–ด์•ผ ํ•œ๋‹ค .๊ทธ๋Ÿฌ๋‚˜ , ์ปดํ“จํ„ฐ ์ข…๋ฅ˜์— ๋”ฐ๋ผ byte ์ €์žฅ ์ˆœ์„œ๊ฐ€ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค .

0000 0001 0000 0010

0000 0001 0000 0010

un.c[0]

un.c[0]

un.c[1]

un.c[1]

Page 34: Transport Protocols Overview

Byte Manipulation FunctionsByte Manipulation Functions

4.3BSD

ANSI C: a = b; style !!

Page 35: Transport Protocols Overview

IPv4 Address ConversionIPv4 Address Conversion Functions only for IPv4, not for IPv6 Dotted decimal(a string) 32-bit IP address

What about 255.255.255.255?

32-bit IP address Dotted decimal

Not reentrant, not thread-safe Function ๋‚ด๋ถ€์—์„œ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•  ๊ณต๊ฐ„์„ static memory ๋กœ ์žก์•„์„œ ,

function call ๋•Œ ๋งˆ๋‹ค ๊ฐ™์€ ์˜์—ญ์„ ์“ฐ๊ธฐ ๋•Œ๋ฌธ

Page 36: Transport Protocols Overview

IPv4/IPv6 Address ConversionIPv4/IPv6 Address Conversion Functions for IPv6: work with both IPv6 and IPv4