Monday, 14 January 2013

Socket Structures


Socket Structures

● struct sockaddr: Holds socket address information
for many types of sockets


struct sockaddr {
unsigned short sa_family; //address family AF_xxx
unsigned short sa_data[14]; //14 bytes of protocol addr
}


● struct sockaddr_in: A parallel structure that makes
it easy to reference elements of the socket address


struct sockaddr_in {
short int sin_family; // set to AF_INET
unsigned short int sin_port; // Port number
struct in_addr sin_addr; // Internet address
unsigned char sin_zero[8]; //set to all zeros
}

● sin_port and sin_addr must be in Network Byte
Order



No comments:

Post a Comment