Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ cat ex.c
- #include <arpa/inet.h>
- #include <netdb.h>
- #include <netinet/in.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/socket.h>
- int main(int argc, char *argv[]) {
- if (argc < 2) {
- printf("Use as %s hostname", argv[0]);
- return EXIT_FAILURE;
- }
- struct hostent *hp = gethostbyname(argv[1]);
- if (hp == NULL) {
- printf("gethostbyname() failed\n");
- } else {
- printf("%s = ", hp->h_name);
- int i = 0;
- while (hp->h_addr_list[i] != NULL) {
- printf("%s ", inet_ntoa(*(struct in_addr *)(hp->h_addr_list[i])));
- i++;
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement