Difference between revisions of "Socket functions"

From Ilianko
(Created page with "Category:sockets == Byte Order Conversion== *htons() host to network short *htonl() host to network long *ntohs() network to host short *ntohl() network to host long")
 
Line 7: Line 7:
 
*ntohs() network to host short
 
*ntohs() network to host short
 
*ntohl() network to host long
 
*ntohl() network to host long
 +
 +
== IP address conversion==
 +
 +
 +
<code><pre>
 +
struct sockaddr_in sa; // IPv4
 +
struct sockaddr_in6 sa6; // IPv6
 +
 +
inet_pton(AF_INET, "192.0.2.1", &(sa.sin_addr)); // IPv4
 +
inet_pton(AF_INET6, "2001:db8:63b3:1::3490", &(sa6.sin6_addr)); // IPv6
 +
</pre></code>

Revision as of 14:38, 12 April 2013


Byte Order Conversion

  • htons() host to network short
  • htonl() host to network long
  • ntohs() network to host short
  • ntohl() network to host long

IP address conversion

struct sockaddr_in sa; // IPv4
struct sockaddr_in6 sa6; // IPv6

inet_pton(AF_INET, "192.0.2.1", &(sa.sin_addr)); // IPv4
inet_pton(AF_INET6, "2001:db8:63b3:1::3490", &(sa6.sin6_addr)); // IPv6