Sunday, December 12, 2010

Linux operating system Socket programming address structure introduction

Linux network communications programs, we must deal with a structure, this construct is the socketaddress.

For example, bind, connect, and so on the function you want to use socketaddress structure. Understanding of the socketaddress is we have to understand, in fact, Linux is specific to different socketdomain defines a generic address structure structsockaddr, its specific defined as: {unsignedshortintsa_family; charsa_data [14];} Structsockaddr where socket for call sa_family () function parameter domain parameter, sa_data to 14 characters in length. In response to a different domain, the socket address structure and corresponding General had different definitions, such as General AF_INETdomain, socketaddress is defined as follows: structsockaddr_in {structin_addrsin_addr uint16_tsin_port unsignedshortintsin_family;;; unsignedcharsin_zero [8];//not used} structin_addr {uint32_ts_addr;} When the domain is different from the socket AF_INET, specific address definition is different, but the size of the entire address structure, the capacity is in line with common address structure.

No comments:

Post a Comment