MCPcopy Index your code
hub / github.com/F-Stack/f-stack / getaddr

Function getaddr

tools/arp/arp.c:300–325  ·  view source on GitHub ↗

* Given a hostname, fills up a (static) struct sockaddr_in with * the address of the host and returns a pointer to the * structure. */

Source from the content-addressed store, hash-verified

298 * structure.
299 */
300static struct sockaddr_in *
301getaddr(char *host)
302{
303#ifndef FSTACK
304 struct hostent *hp;
305#endif
306 static struct sockaddr_in reply;
307
308 bzero(&reply, sizeof(reply));
309 reply.sin_len = sizeof(reply);
310 reply.sin_family = AF_INET;
311 reply.sin_addr.s_addr = inet_addr(host);
312 if (reply.sin_addr.s_addr == INADDR_NONE) {
313#ifndef FSTACK
314 if (!(hp = gethostbyname(host))) {
315 xo_warnx("%s: %s", host, hstrerror(h_errno));
316 return (NULL);
317 }
318 bcopy((char *)hp->h_addr, (char *)&reply.sin_addr,
319 sizeof reply.sin_addr);
320#else
321 warnx("reply.sin_addr.s_addr == INADDR_NONE");
322#endif
323 }
324 return (&reply);
325}
326
327/*
328 * Returns true if the type is a valid one for ARP.

Callers 3

setFunction · 0.70
getFunction · 0.70
deleteFunction · 0.70

Calls 2

bzeroFunction · 0.85
xo_warnxFunction · 0.85

Tested by

no test coverage detected