Transcript SocketIntro
Sockets Introduction
Chap 1, 3
Client-Server Model
BSD Networking History
Protocols and API
Simple Daytime Client
26 bytes can be returned,
but always need to code
in read loop !! Why?
Simple Daytime Client – over IPv6
Only runs on IPv6,
but not runs on IPv4
New application should be
written in a manner of
protocol independence
Error Handling: Wrapper Functions –
in files wrap….c
Standard Error Functions – lib/error.c
Standard Error Functions – lib/error.c
Considerations in NP
Protocol Independence
TCP/IP Protocol Suite
Other Protocol Family
API
Socket
IPv4
IPv6
BSD Socket
Winsock, Winsock 2
XTI: X/Open Transport Interface
Version of Networking Software
Portability
OS
UNIX: BSD, SVR, POSIX, X/Open
MS Windows
32bit and 64bit Architecture: ILP32 model, LP64 model
Socket Address Structures
IPv4/IPv6 Socket Address Structure
IPv4
SA structure itself are
used only on a given
host, not used for
communication
always set to 0
IPv6
POSIX datatypes
Generic Socket Address Structures
Generic SA structure: SA structure의 pointer를 casting할 때 사용
sockaddr_storage structure: large enough to hold any socket
address type
Protocol independent하게 메모리를 잡을 때 사용
Value-Result Arguments
SA structure are always
passed by reference
process to kernel: bind,
connect, sendto
kernel to process:
accept, recvfrom,
getsockname,getpeer
name
Byte Ordering
Host Byte Order Network Byte Order
Byte Manipulation
4.3BSD
ANSI C
IPv4 Address Conversion
Functions only for IPv4, not for IPv6
Dotted decimal 32-bit IP address
What about 255.255.255.255?
32-bit IP address Dotted decimal
Not reentrant nor thread-safe
IPv4/IPv6 Address Conversion
Functions for IPv6: work with both IPv6 and IPv4
Still, protocol dependent !!
Protocol independent version of inet_ntop
Useful UNP Library Functions(1)
Useful UNP Library Functions(2)