View
250
Download
0
Category
Preview:
Citation preview
Understand IPv4 AddressingUnderstand IPv4 Addressing
IPv4: originally Classfull AddressingIPv4: originally Classfull Addressing Special address
Host ID = 0: network address Network ID = 0, host ID = 0
i.e 0.0.0.0 means this network 127.x.y.z : “looped back” Host ID = all 1s : broadcasting NAT address
10/8 172.16/12 192.168/12
Broadcast address 255.255.255.255
Limited broadcast router 밖에는 나가지 못함
190.50.255.255 Network-directed broadcast 그 네트워크까지 가서 네트워크 내에
broadcast 190.50.1.255/24
Subnet-directed broadcast 190.50.1.0/24 subnet 내에 broadcast
IPv4 address 는 host 의 address 가 아니라 interface 의 address 이다 .
SubnetSubnet
Network address IP address && mask Network ID
223.1.1.1
223.1.1.2
223.1.1.3
223.1.1.4 223.1.2.9
223.1.2.2
223.1.2.1
223.1.3.2223.1.3.1
223.1.3.27
network consisting of 3 subnets
subnet
223.1.1.0/24223.1.2.0/24
223.1.3.0/24
223.1.0.0/16
CIDR (Classless Inter-Domain Routing) Subnetting + suppernetting
Tip: Develop and Use Application Tip: Develop and Use Application “Skeletons”“Skeletons”
Simple TCP Client and ServerSimple TCP Client and ServerClient: simplec.c Server: simples.c
Making UNIX/Windows CompatibleMaking UNIX/Windows CompatibleUNIX: bsd/skel.h Windows: win/skel.h
wincompat.c:
Window 에서 socket을 생성전에 call 해야
TCP Server SkeletonTCP Server Skeleton
tcpserver.skel:
“mclab.hufs.ac.kr”
or “203.254.68.114”or “” -- server
“http” or
“80”
TCP Server Skeleton - Cont’dTCP Server Skeleton - Cont’d
Usage: % myserver [local_addr | local_name] {local_port | service}Example: %myserver 15000 %myserver localhost http
TCP Client SkeletonTCP Client Skeletontcpclient.skel:
Usage: % myclient {peer_addr | peer_name} {peer_port | service}Example: % myclient 203.253.70.5 15000 % myclient www.hufs.ac.kr http
UDP Server & Client SkeletonUDP Server & Client Skeletonudpserver.skel: udpclient.skel:
Build Your Own Library and Use It !Build Your Own Library and Use It !etcp.h
TCP Client & Server Starting FunctionsTCP Client & Server Starting Functions
Host name or IP addr
or “” (my addr for server)
“http” or
“80”
UDP Client & Server Starting UDP Client & Server Starting FunctionsFunctions
Remember thatRemember thatTCP is a Stream ProtocolTCP is a Stream Protocol
TCP is a Stream ProtocolTCP is a Stream Protocol No message boundary, just a byte stream
TCP application 에서 하나의 message 를 send() 했다고 해서 recevier application 에서 그 message 를 한 덩어리로 recv() 되는 것이 아니다 .
Message 를 send() 했어도 TCP segment 에 언제 , 어떻게 실릴지 모른다 . (buffering 되기 때문 )
Recv() 하면 몇 byte 읽힐지 모른다 . If you want to read exactly n bytes ?? If you want to make a record ???
Use end-of-record mark. e.g) new line Handle variable records (using fixed header)
#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
메시지를 읽을 user buffer 의 크기즉 , 최대로 읽을 수 있는 크기
Socket send buffer에 저장할 메시지 길이
Use End-of-record mark: read a lineUse End-of-record mark: read a linelib/readline.c:
Read n bytes and Read a variable-length Read n bytes and Read a variable-length recordrecord
Record Length
Other Header Data
VariableData
lib/readn.c:
lib/readvrec:
#include “etcp.h”int readn (SOCKET s, char *buf, size_t len); Returns: # of bytes read, -1 on failure
int readvrec (SOCKET s, char *buf, size_t len); Returns: # of bytes read , -1 on failure
len
cnt
bp
Header size
Network byte order
Example: Client/Server using variable Example: Client/Server using variable recordsrecords
vrc.c: vrs.c:
Recommended