Linux application Development-socket
a Socket
Sockets are network programming interfaces that are independent of specific protocols
In the OSI model, mainly between the session layer and the Transport layer
Characteristics
1 is a programming interface
2 is a special kind of file descriptor
3 is not limited to TCP and IP
4 connection-oriented and no-connection two ways
Two socket types
Common
Sock_stream: In order, reliable, data integrity, byte-stream based, using TCP transmission, using the most
Sock_dgram: No connection, fixed length, unreliable, UDP-based transmission
Not used
Sock_seqpacket,sock_raw,sock_rdm
Three byte order
Concept: Byte order refers to the order in which multibyte data is stored in computer memory or bytes transmitted over a network
Category: Host sequence and network order
Common byte-order:
Little endian low byte stored at start address
BIg endian high byte stored at start address
BYTE-Order Conversion
Different host byte sequence, in order to unify, introduced the network byte order (big-endian mode)
Network, host
U_long Ntohl (U_long hostlong)
U_short htons (u_short short)
Host to Network long
Host to network short
Host Network
U_long Ntohl (U_long hostlong)
U_short Ntohs (u_short short)
Network to host Long
Network to host Short
Four IP address translation
1 Inet_aton
2 inet_addr
3 Inet_ntoa
Five Get DNS
Get IP address based on domain name gethostbyname
See the Man Handbook for Linux systems for details.
Children's Day Cases
Aton
Ntoa
gethostbyname
Linux Application Development-socket