Skip to content

Instantly share code, notes, and snippets.

@basman
Created September 17, 2010 06:52
Show Gist options
  • Select an option

  • Save basman/583837 to your computer and use it in GitHub Desktop.

Select an option

Save basman/583837 to your computer and use it in GitHub Desktop.
/*
** This puts different kinds of IP addresses in one place.
** Here we can put IPv4 and IPv6 addresses.
*/
typedef union sockaddr_union {
struct sockaddr sa;
struct sockaddr_in in;
#if defined(USE_IPv6)
struct sockaddr_in6 in6;
#endif
} SOCKADDR_UNION;
/*
Notes:
- sizeof sockaddr_union will reflect the size of the biggest member of the union (so the actual size of this union heavily depends on USE_IPv6)
- Linux tolerates wrong size specs in connect() and bind() calls:
connect(AF_INET, ..., sizeof(struct sockaddr_in6))
But Solaris does not (runtime error: invalid argument).
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment