Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************************************************
- ringneckparrot (c)
- License: http://creativecommons.org/licenses/by-nc-sa/3.0/
- Contact Me:
- Email: ringneckparrot@hotmail.com
- Facebook: http://www.facebook.com/ringneckparrot
- Twitter ID: pp4rr0t
- SecurityTube: http://www.securitytube.net/user/ringneckparrot
- ****************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netdb.h>
- #include <strings.h>
- #include <arpa/inet.h>
- #define ErrorValue -1
- main(int argc, char **argv)
- {
- struct addrinfo hints;
- struct addrinfo *res;
- struct addrinfo *p;
- int GetInfo;
- char *host;
- char ipstr[INET6_ADDRSTRLEN];
- if ( argc != 2 )
- {
- printf("usage: %s [host]\n",argv[0]);
- }
- else
- {
- bzero(&hints, sizeof hints);
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- host = argv[1];
- GetInfo = getaddrinfo(host, NULL, &hints, &res);
- if (GetInfo == ErrorValue)
- {
- fprintf(stderr, "Error: %s\n", gai_strerror(GetInfo));
- }
- printf("IP Addresses for the given host: %s\n\n",host);
- for( p = res; p != NULL; p = p->ai_next)
- {
- void *addr;
- char *ipversion;
- if( p->ai_family == AF_INET)
- {
- struct sockaddr_in *ipv4;
- ipv4 = (struct sockaddr_in *)p->ai_addr;
- addr = &(ipv4->sin_addr);
- ipversion = "IPv4";
- }
- else
- {
- struct sockaddr_in6 *ipv6;
- ipv6 = (struct sockaddr_in6 *)p->ai_addr;
- addr = &(ipv6->sin6_addr);
- ipversion = "IPv6";
- }
- inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
- printf("%s: %s\n", ipversion, ipstr);
- }
- freeaddrinfo(res);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement