Skip to content
Search

C:sockaddr in

lastmod 2021-09-11created 2017-01-133 edits

In the Internet address family, the SOCKADDR_IN structure is used to specify a local or remote endpoint address to which to connect a socket.

#if defined(__OS_WINDOWS__)
#include <winsock2.h>
#else
#include <netinet/in.h>
#endif

struct sockaddr_in {
    short            sin_family;   // e.g. AF_INET
    unsigned short   sin_port;     // e.g. htons(3490)
    struct in_addr   sin_addr;     // see struct in_addr, below
    char             sin_zero[8];  // zero this if you want to
};

struct in_addr {
    unsigned long s_addr;  // load with inet_aton()
};

Parameters

  • sin_family: Address family (must be AF_INET)
  • sin_port: IP port
  • sin_addr: IP address.
  • sin_zero: Padding to make the structure the same size as SOCKADDR

See also

Favorite site

author Zer0 sitemap