Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

59. Sockets: Internet Domains > The inet_pton() and inet_ntop() Functions

The inet_pton() and inet_ntop() Functions

The inet_pton() and inet_ntop() functions allow conversion of both IPv4 and IPv6 addresses between binary form and dotted-decimal or hex-string notation.

#include <arpa/inet.h>

int inet_pton(int domain, const char *src_str, void *addrptr);

Note

Returns 1 on successful conversion, 0 if src_str is not in presentation format, or -1 on error

const char *inet_ntop(int domain, const void *addrptr,
 char *dst_str, size_t len);

Note

Returns pointer to dst_str on success, or NULL on error

The p in the names of these functions stands for “presentation,” and the n stands for “network.” The presentation form is a human-readable string, such as the following:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint