Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/i/inet_ntop.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/i/inet_ntop.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/i/inet_ntop.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/i/inet_ntop.html on line 8
Convert a numeric network address to a string
#include <sys/socket.h>
#include <arpa/inet.h>
const char * inet_ntop( int af,
const void * src,
char * dst,
socklen_t size );
- af
- The src address's network family; one of:
- AF_INET
- IPv4 addresses
- AF_INET6
- IPv6 addresses
- src
- The numeric network address that you want to convert to a string.
- dst
- The text string that represents the translated network address.
You can use the following constants to allocate buffers of the correct
size (they're defined in <netinet/in.h>):
- INET_ADDRSTRLEN — storage for an IPv4 address
- INET6_ADDRSTRLEN — storage for an IPv6 address
- size
- The size of the buffer pointed to by dst.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The inet_ntop() function converts a numeric network address
pointed to by src into a text string in the buffer pointed to by dst.
A pointer to the buffer containing the text version of the address,
or NULL if an error occurs
(errno is set).
- EAFNOSUPPORT
- The value of the af argument isn't a supported network family.
- ENOSPC
- The dst buffer isn't large enough (according to
size) to store the translated address.
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <errno.h>
#define INADDR "10.1.0.29"
#define IN6ADDR "DEAD:BEEF:7654:3210:FEDC:3210:7654:BA98"
int
main()
{
struct in_addr inaddr;
struct in6_addr in6addr;
char buf[INET_ADDRSTRLEN], buf6[INET6_ADDRSTRLEN];
int rval;
if ( (rval = inet_pton(AF_INET, INADDR, &inaddr)) == 0) {
printf("Invalid address: %s\n", INADDR);
exit(EXIT_FAILURE);
} else if (rval == -1) {
perror("inet_pton");
exit(EXIT_FAILURE);
}
if (inet_ntop(AF_INET, &inaddr, buf, sizeof(buf)) != NULL)
printf("inet addr: %s\n", buf);
else {
perror("inet_ntop");
exit(EXIT_FAILURE);
}
if ( (rval = inet_pton(AF_INET6, IN6ADDR, &in6addr)) == 0) {
printf("Invalid address: %s\n", IN6ADDR);
exit(EXIT_FAILURE);
} else if (rval == -1) {
perror("inet_pton");
exit(EXIT_FAILURE);
}
if (inet_ntop(AF_INET6, &in6addr, buf6, sizeof(buf6)) != NULL)
printf("inet6 addr: %s\n", buf6);
else {
perror("inet_ntop");
exit(EXIT_FAILURE);
}
return(EXIT_SUCCESS);
}
POSIX 1003.1
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
Yes |
Thread |
Yes |
inet_pton()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/i/inet_ntop.html on line 232
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/i/inet_ntop.html on line 232