Update contrib.
1 /** @file ../include/arpa/inet.h
5 /** @fn inet_addr(const char *cp)
8 Note: This description also covers the following functions -
9 inet_aton() inet_ntoa() inet_ntop() inet_pton()
12 struct in_addr or some other internal binary representation, in network byte order).
13 It returns 1 if the address was valid for the specified address family, or
14 0 if the address was not parseable in the specified address family, or -1
15 if some system error occurred.
16 This function is presently valid for AF_INET and AF_INET6.
19 struct in_addr or some other binary form, in network byte order) to presentation format
20 (suitable for external display purposes).
21 The size argument specifies the size, in bytes, of the buffer *dst It returns NULL if a system error occurs (in which case, errno will have been set), or it returns a pointer to the destination string.
22 This function is presently valid for AF_INET and AF_INET6.
25 The routines inet_addr and inet_aton interpret character strings representing
26 numbers expressed in the Internet standard ‘.’ notation.
29 The inet_pton function converts a presentation format address (that is, printable form
30 as held in a character string) to network format (usually a struct in_addr or some other internal binary representation, in network byte order).
31 It returns 1 if the address was valid for the specified address family, or
32 0 if the address was not parseable in the specified address family, or -1
33 if some system error occurred.
34 This function is presently valid for AF_INET and AF_INET6.
36 The inet_aton routine interprets the specified character string as an Internet address,
37 placing the address into the structure provided.
38 It returns 1 if the string was successfully interpreted,
39 or 0 if the string is invalid.
40 The inet_addr functions return numbers suitable for use
41 as Internet addresses.
43 The function inet_ntop converts an address *src from network format
44 (usually a struct in_addr or some other binary form, in network byte order) to presentation format
45 (suitable for external display purposes).
46 The size argument specifies the size, in bytes, of the buffer *dst It returns NULL if a system error occurs (in which case, errno will have been set), or it returns a pointer to the destination string.
47 This function is presently valid for AF_INET and AF_INET6.
49 The routine inet_ntoa takes an Internet address and returns an ASCII string representing the address in ' . '
52 All Internet addresses are returned in network
53 order (bytes ordered from left to right).
54 All network numbers and local address parts are
55 returned as machine byte order integer values.
59 The constant INADDR_NONE is returned by inet_addr for malformed requests.
67 #include <arpa/inet.h>
68 #include <netinet/in.h>
69 #define IPV6ADDRSIZE 48
72 unsigned int nbo_value;
73 char *ipaddrstring="1.2.3.4";
74 char *ipaddrholdr=NULL;
75 char *ipv6addrstring="8000::123:4567:89AB:CDEF";
76 struct in_addr ipstruct;
77 struct in6_addr ipv6struct;
78 char result[IPV6ADDRSIZE];
82 nbo_value=inet_addr(ipaddrstring);
85 printf("inet_addr failed0);
89 printf("inet_addr passed0);
91 ipstruct.s_addr=nbo_value;
92 ipaddrholdr=inet_ntoa(ipstruct);
95 printf("inet_ntoa failed0);
99 printf("ipaddr is %s0,ipaddrholdr);
101 err=inet_pton(AF_INET6,ipv6addrstring ,&ipv6struct;);
102 if(err ==0 || err==-1)
103 printf("inet_pton Failed0);
105 printf("inet_pton passed0);
107 error=inet_ntop(AF_INET6,&ipv6struct.s6;_addr,result,size);
110 printf("inet_ntop failed");
114 printf("inet_ntop passed");
116 err=inet_aton(ipaddrstring,&ipstruct;);
119 printf("invalid address ");
123 printf("inet_aton passed ");
136 The inet_ntop and inet_pton functions conform to -xns5.2. Note that inet_pton does not accept 1-, 2-, or 3-part dotted addresses; all four parts
137 must be specified and are interpreted only as decimal values.
138 This is a narrower input set than that accepted by inet_aton. These
139 functions appeared in BSD 4.2.
143 The value INADDR_NONE (0xffffffff) is a valid broadcast address, but inet_addr cannot return that value without indicating failure.
144 The newer inet_aton function does not share this problem.
145 The problem of host byte ordering versus network byte ordering is
147 The string returned by inet_ntoa resides in a static memory area. Inet_addr should return a struct in_addr.
152 @externallyDefinedApi
155 /** @fn inet_ntoa(struct in_addr in)
158 Refer to inet_addr() for the documentation
165 @externallyDefinedApi
168 /** @fn inet_ntop( int af , const void * src, char * dst, socklen_t size)
174 Refer to inet_addr() for the documentation
182 @externallyDefinedApi
185 /** @fn inet_pton(int af, const char * src, void * dst)
190 Refer to inet_addr() for the documentation
198 @externallyDefinedApi
201 /** @fn inet_aton(const char *cp, struct in_addr *pin)
205 Refer to inet_addr() for the documentation
213 @externallyDefinedApi
216 /** @fn htonl(uint32_t hl)
219 Note: This description also covers the following functions -
220 htons() ntohl() ntohs()
222 These routines convert 16 and 32 bit quantities between network
223 byte order and host byte order.
224 On machines which have a byte order which is the same as the network
225 order, routines are defined as null macros.
227 These routines are most often used in conjunction with Internet
228 addresses and ports as returned by gethostbyname
237 On the VAX bytes are handled backwards from most everyone else in
243 @externallyDefinedApi
246 /** @fn htons(uint16_t hs)
249 Refer to htonl() for the documentation
257 @externallyDefinedApi
262 These are also declared as functions.
265 @externallyDefinedApi
270 These are also declared as functions.
273 @externallyDefinedApi
278 These are also declared as functions.
281 @externallyDefinedApi
287 These are also declared as functions.
290 @externallyDefinedApi
296 These are also declared as functions.
299 @externallyDefinedApi
305 These are also declared as functions.
308 @externallyDefinedApi