File: gethostbyaddr.c

package info (click to toggle)
dietlibc 0.34~cvs20160606-10
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 11,336 kB
  • sloc: ansic: 71,631; asm: 13,006; cpp: 1,860; makefile: 799; sh: 292; perl: 62
file content (20 lines) | stat: -rw-r--r-- 503 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <netdb.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main() {
  struct in_addr bar;
  struct hostent *foo;
  inet_aton("160.45.10.8",&bar);
  foo=gethostbyaddr(&bar,4,AF_INET);
  if (foo) {
    int i;
    for (i=0; foo->h_addr_list[i]; ++i)
      printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr_list[i]));
    for (i=0; foo->h_aliases[i]; ++i)
      printf("  also known as %s\n",foo->h_aliases[i]);
  }
  return 0;
}