TAILIEUCHUNG - Internetworking with TCP/IP- P48

Internetworking with TCP/IP- P48: TCP/IP has accommodated change well. The basic technology has survived nearly two decades of exponential growth and the associated increases in traffic. The protocols have worked over new high-speed network technologies, and the design has handled applications that could not be imagined in the original design. Of course, the entire protocol suite has not remained static. New protocols have been deployed, and new techniques have been developed to adapt existing protocols to new network technologies | Sec. Network Byte Order Conversion Routines 429 All four conversion routines are functions that take a value as an argument and return a new value with the bytes rearranged. For example to convert a short 2-byte integer from network byte order to the local host byte order a programmer calls ntohs network to host short . The format is localshort ntohs netshort Argument netshort is a 2-byte 16-bit integer in network standard byte order and the result localshort is in local host byte order. The C programming language calls 4 byte 32 bit integers longs. Function ntohl network to host long converts 4-byte longs from network standard byte order to local host byte order. Programs invoke ntohl as a function supplying a long integer in network byte order as an argument locallong ntohl netlong Two analogous functions allow the programmer to convert from local host byte order to network byte order. Function htons converts a 2-byte short integer in the host s local byte order to a 2-byte integer in network standard byte order. Programs invoke htons as a function netshort htons localshort The final conversion routine htonl converts long integers to network standard byte order. Like the others htonl is a function netlong htonl locallong It should be obvious that the conversion routines preserve the following mathematical relationships netshort htons ntohs netshort and localshort ntohs htons localshort Similar relationships hold for the long integer conversion routines. IP Address Manipulation Routines Because many programs translate between 32-bit IP addresses and the corresponding dotted decimal notation the socket library includes utility routines that perform the translation. Procedures inet_addr and inet_network both translate from dotted decimal 430 The Socket Interface Chap. 22 format to a 32-bit IP address in network byte order. Inet_addr forms a 32-bit host IP address inet_network forms the network address with zeroes for the host part. They have the form .

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.