MCPcopy Create free account
hub / github.com/F-Stack/f-stack / getaddrinfo

Function getaddrinfo

tools/compat/getaddrinfo.c:44–80  ·  view source on GitHub ↗

FIXME: to support IPv6 */ Just conver numeric hostname to int and not do anything else. */

Source from the content-addressed store, hash-verified

42/* FIXME: to support IPv6 */
43/* Just conver numeric hostname to int and not do anything else. */
44int
45getaddrinfo(const char *hostname, const char *servername,
46 const struct addrinfo *hints, struct addrinfo **res)
47{
48 if (hostname == NULL)
49 return EAI_NONAME;
50
51 *res = NULL;
52 struct addrinfo *ai;
53
54 ai = malloc(sizeof(struct addrinfo) + sizeof(struct sockaddr));
55 if (ai == NULL)
56 return EAI_MEMORY;
57
58 ai->ai_next = NULL;
59 ai->ai_canonname = NULL;
60 ai->ai_addr = (struct sockaddr *)(ai+1);
61
62 struct sockaddr_in *si = (struct sockaddr_in *)ai->ai_addr;
63 si->sin_len = ai->ai_addrlen = sizeof(struct sockaddr);
64 si->sin_family = ai->ai_family = AF_INET;
65 /* si->sin_port ? */
66
67 if (hints != NULL) {
68 si->sin_family = ai->ai_family = hints->ai_family;
69 ai->ai_socktype = hints->ai_socktype;
70 }
71
72 if (inet_pton(AF_INET, hostname, &si->sin_addr.s_addr) != 1) {
73 freeaddrinfo(ai);
74 return EAI_NONAME;
75 }
76
77 *res = ai;
78
79 return 0;
80}
81
82void
83freeaddrinfo(struct addrinfo *ai)

Callers 15

setFunction · 0.85
getFunction · 0.85
deleteFunction · 0.85
realhostname_saFunction · 0.85
settunnelFunction · 0.85
setpfsync_syncpeerFunction · 0.85
ifvxlan.cFile · 0.85
in6_getaddrFunction · 0.85
getaddrFunction · 0.85
tentry_fill_valueFunction · 0.85
compile_ruleFunction · 0.85
anetResolveFunction · 0.85

Calls 3

mallocFunction · 0.85
inet_ptonFunction · 0.85
freeaddrinfoFunction · 0.85

Tested by 1