Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

sockaddr_in address structure of the AF_INET address family

&pagelevel(5)&pagelevel

With the AF_INET address family, a name comprises an Internet address and a port number. You use the sockaddr_in address structure for the AF_INET address family.

The sockaddr_in structure is declared as follows in the <netinet/in.h> header file:

struct sockaddr_in {
    sa_family_t      sin_family;      /* address family */
    in_port_t        sin_port;        /* 16-bit port number */
    struct in_addr   sin_addr;        /* 32-bit Internet address */;
    unsigned char    sin_zero[8];
};
struct in_addr {
    in_addr_t s_addr;
};

You can supply a variable server of type struct sockaddr_in with a name, using the following statements:

struct sockaddr_in server;
...
server.sin_family = AF_INET;
server.sin_port = htons(8888);
server.sin_addr.s_addr = htonl(INADDR_ANY);

A pointer to the variable server can now be passed as the current parameter, e.g. with a bind() call, to bind the name to a socket:

bind (..., (struct sockaddr *)&server, ...);  /* bind() call with type conversion */