sl@0: /** @file ../include/arpa/inet.h sl@0: @internalComponent sl@0: */ sl@0: sl@0: /** @fn inet_addr(const char *cp) sl@0: @param cp sl@0: sl@0: Note: This description also covers the following functions - sl@0: inet_aton() inet_ntoa() inet_ntop() inet_pton() sl@0: sl@0: @code sl@0: struct in_addr or some other internal binary representation, in network byte order). sl@0: It returns 1 if the address was valid for the specified address family, or sl@0: 0 if the address was not parseable in the specified address family, or -1 sl@0: if some system error occurred. sl@0: This function is presently valid for AF_INET and AF_INET6. sl@0: @endcode sl@0: @code sl@0: struct in_addr or some other binary form, in network byte order) to presentation format sl@0: (suitable for external display purposes). sl@0: 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. sl@0: This function is presently valid for AF_INET and AF_INET6. sl@0: @endcode sl@0: @code sl@0: The routines inet_addr and inet_aton interpret character strings representing sl@0: numbers expressed in the Internet standard ‘.’ notation. sl@0: @endcode sl@0: sl@0: The inet_pton function converts a presentation format address (that is, printable form sl@0: as held in a character string) to network format (usually a struct in_addr or some other internal binary representation, in network byte order). sl@0: It returns 1 if the address was valid for the specified address family, or sl@0: 0 if the address was not parseable in the specified address family, or -1 sl@0: if some system error occurred. sl@0: This function is presently valid for AF_INET and AF_INET6. sl@0: sl@0: The inet_aton routine interprets the specified character string as an Internet address, sl@0: placing the address into the structure provided. sl@0: It returns 1 if the string was successfully interpreted, sl@0: or 0 if the string is invalid. sl@0: The inet_addr functions return numbers suitable for use sl@0: as Internet addresses. sl@0: sl@0: The function inet_ntop converts an address *src from network format sl@0: (usually a struct in_addr or some other binary form, in network byte order) to presentation format sl@0: (suitable for external display purposes). sl@0: 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. sl@0: This function is presently valid for AF_INET and AF_INET6. sl@0: sl@0: The routine inet_ntoa takes an Internet address and returns an ASCII string representing the address in ' . ' sl@0: notation. sl@0: sl@0: All Internet addresses are returned in network sl@0: order (bytes ordered from left to right). sl@0: All network numbers and local address parts are sl@0: returned as machine byte order integer values. sl@0: sl@0: Diagnostics: sl@0: sl@0: The constant INADDR_NONE is returned by inet_addr for malformed requests. sl@0: sl@0: @see gethostbyname() sl@0: sl@0: sl@0: Examples: sl@0: @code sl@0: #include sl@0: #include sl@0: #include sl@0: #define IPV6ADDRSIZE 48 sl@0: int main() sl@0: { sl@0: unsigned int nbo_value; sl@0: char *ipaddrstring="1.2.3.4"; sl@0: char *ipaddrholdr=NULL; sl@0: char *ipv6addrstring="8000::123:4567:89AB:CDEF"; sl@0: struct in_addr ipstruct; sl@0: struct in6_addr ipv6struct; sl@0: char result[IPV6ADDRSIZE]; sl@0: int err; sl@0: int size; sl@0: const char* error; sl@0: nbo_value=inet_addr(ipaddrstring); sl@0: if(nbo_value == -1) sl@0: { sl@0: printf("inet_addr failed0); sl@0: } sl@0: else sl@0: { sl@0: printf("inet_addr passed0); sl@0: } sl@0: ipstruct.s_addr=nbo_value; sl@0: ipaddrholdr=inet_ntoa(ipstruct); sl@0: if(ipaddrholdr==NULL) sl@0: { sl@0: printf("inet_ntoa failed0); sl@0: } sl@0: else sl@0: { sl@0: printf("ipaddr is %s0,ipaddrholdr); sl@0: } sl@0: err=inet_pton(AF_INET6,ipv6addrstring ,&ipv6struct;); sl@0: if(err ==0 || err==-1) sl@0: printf("inet_pton Failed0); sl@0: else sl@0: printf("inet_pton passed0); sl@0: size=sizeof(result); sl@0: error=inet_ntop(AF_INET6,&ipv6struct.s6;_addr,result,size); sl@0: if(error==NULL) sl@0: { sl@0: printf("inet_ntop failed"); sl@0: } sl@0: else sl@0: { sl@0: printf("inet_ntop passed"); sl@0: } sl@0: err=inet_aton(ipaddrstring,&ipstruct;); sl@0: if(err==0) sl@0: { sl@0: printf("invalid address "); sl@0: } sl@0: else sl@0: { sl@0: printf("inet_aton passed "); sl@0: } sl@0: sl@0: return 0; sl@0: } sl@0: Output: sl@0: inet_addr passed sl@0: ipaddr is 1.2.3.4 sl@0: inet_pton passed sl@0: inet_ntop passed sl@0: inet_aton passed sl@0: sl@0: @endcode sl@0: 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 sl@0: must be specified and are interpreted only as decimal values. sl@0: This is a narrower input set than that accepted by inet_aton. These sl@0: functions appeared in BSD 4.2. sl@0: sl@0: Bugs: sl@0: sl@0: The value INADDR_NONE (0xffffffff) is a valid broadcast address, but inet_addr cannot return that value without indicating failure. sl@0: The newer inet_aton function does not share this problem. sl@0: The problem of host byte ordering versus network byte ordering is sl@0: confusing. sl@0: The string returned by inet_ntoa resides in a static memory area. Inet_addr should return a struct in_addr. sl@0: sl@0: sl@0: sl@0: @publishedAll sl@0: @externallyDefinedApi sl@0: */ sl@0: sl@0: /** @fn inet_ntoa(struct in_addr in) sl@0: @param in sl@0: sl@0: Refer to inet_addr() for the documentation sl@0: @see gethostbyname() sl@0: sl@0: sl@0: sl@0: sl@0: @publishedAll sl@0: @externallyDefinedApi sl@0: */ sl@0: sl@0: /** @fn inet_ntop( int af , const void * src, char * dst, socklen_t size) sl@0: @param af sl@0: @param src sl@0: @param dst sl@0: @param size sl@0: sl@0: Refer to inet_addr() for the documentation sl@0: sl@0: @see gethostbyname() sl@0: sl@0: sl@0: sl@0: sl@0: @publishedAll sl@0: @externallyDefinedApi sl@0: */ sl@0: sl@0: /** @fn inet_pton(int af, const char * src, void * dst) sl@0: @param af sl@0: @param src sl@0: @param dst sl@0: sl@0: Refer to inet_addr() for the documentation sl@0: sl@0: @see gethostbyname() sl@0: sl@0: sl@0: sl@0: sl@0: @publishedAll sl@0: @externallyDefinedApi sl@0: */ sl@0: sl@0: /** @fn inet_aton(const char *cp, struct in_addr *pin) sl@0: @param cp sl@0: @param pin sl@0: sl@0: Refer to inet_addr() for the documentation sl@0: sl@0: @see gethostbyname() sl@0: sl@0: sl@0: sl@0: sl@0: @publishedAll sl@0: @externallyDefinedApi sl@0: */ sl@0: sl@0: /** @fn htonl(uint32_t hl) sl@0: @param hl sl@0: sl@0: Note: This description also covers the following functions - sl@0: htons() ntohl() ntohs() sl@0: sl@0: These routines convert 16 and 32 bit quantities between network sl@0: byte order and host byte order. sl@0: On machines which have a byte order which is the same as the network sl@0: order, routines are defined as null macros. sl@0: sl@0: These routines are most often used in conjunction with Internet sl@0: addresses and ports as returned by gethostbyname sl@0: and getservent . sl@0: sl@0: @see gethostbyaddr() sl@0: @see getservent() sl@0: sl@0: sl@0: Bugs: sl@0: sl@0: On the VAX bytes are handled backwards from most everyone else in sl@0: the world. sl@0: sl@0: sl@0: sl@0: @publishedAll sl@0: @externallyDefinedApi sl@0: */ sl@0: sl@0: /** @fn htons(uint16_t hs) sl@0: @param hs sl@0: sl@0: Refer to htonl() for the documentation sl@0: @see gethostbyaddr() sl@0: @see getservent() sl@0: sl@0: sl@0: sl@0: sl@0: @publishedAll sl@0: @externallyDefinedApi sl@0: */ sl@0: sl@0: /** @def ntohl sl@0: sl@0: These are also declared as functions. sl@0: sl@0: @publishedAll sl@0: @externallyDefinedApi sl@0: */ sl@0: sl@0: /** @def ntohs sl@0: sl@0: These are also declared as functions. sl@0: sl@0: @publishedAll sl@0: @externallyDefinedApi sl@0: */ sl@0: sl@0: /** @def inet_addr sl@0: sl@0: These are also declared as functions. sl@0: sl@0: @publishedAll sl@0: @externallyDefinedApi sl@0: */ sl@0: sl@0: sl@0: /** @def inet_ntoa sl@0: sl@0: These are also declared as functions. sl@0: sl@0: @publishedAll sl@0: @externallyDefinedApi sl@0: */ sl@0: sl@0: sl@0: /** @def inet_pton sl@0: sl@0: These are also declared as functions. sl@0: sl@0: @publishedAll sl@0: @externallyDefinedApi sl@0: */ sl@0: sl@0: sl@0: /** @def inet_ntop sl@0: sl@0: These are also declared as functions. sl@0: sl@0: @publishedAll sl@0: @externallyDefinedApi sl@0: */ sl@0: sl@0: