MCPcopy Create free account
hub / github.com/acl-dev/acl / resolve_addr

Function resolve_addr

lib_acl/samples/resolve/main.cpp:48–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46#endif
47
48static ACL_DNS_DB *resolve_addr(const char *name)
49{
50 ACL_DNS_DB *res;
51 struct hostent *h_addrp = NULL;
52 struct in_addr addr;
53 ACL_HOSTNAME *h_host;
54 char **pptr;
55 int n;
56
57 memset(&addr, 0, sizeof(addr));
58 addr.s_addr = inet_addr(name);
59
60 printf("%s: gethostbyaddr addr: %s\n", __FUNCTION__, name);
61
62 h_addrp = gethostbyaddr((char*) &addr, sizeof(addr), AF_INET);
63 if (!h_addrp) {
64 printf("%s: gethostbyaddr error=%s\n",
65 __FUNCTION__, hstrerror(h_errno));
66 return NULL;
67 }
68
69 printf("h_name: %s\n", h_addrp->h_name);
70
71 res = acl_netdb_new(name);
72
73 for (pptr = h_addrp->h_addr_list; *pptr != NULL; pptr++) {
74 h_host = (ACL_HOSTNAME*) acl_mycalloc(1, sizeof(ACL_HOSTNAME));
75
76 memset(&h_host->saddr, 0, sizeof(h_host->saddr));
77 if ((int) sizeof(h_host->saddr.in.sin_addr) > h_addrp->h_length)
78 n = h_addrp->h_length;
79 else
80 n = (int) sizeof(h_host->saddr.in.sin_addr);
81
82 memcpy(&h_host->saddr.in.sin_addr, *pptr, n);
83 acl_inet_ntoa(h_host->saddr.in.sin_addr,
84 h_host->ip, sizeof(h_host->ip));
85
86 (void) acl_array_append(res->h_db, h_host);
87
88 res->size++;
89 }
90
91 return res;
92}
93
94static void show(ACL_DNS_DB *res)
95{

Callers 1

testFunction · 0.70

Calls 4

acl_netdb_newFunction · 0.85
memcpyFunction · 0.85
acl_inet_ntoaFunction · 0.85
acl_array_appendFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…