Linux Application Development-socket

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.