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

Function netname4

tools/netstat/route.c:581–615  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

579}
580
581static const char *
582netname4(in_addr_t in, in_addr_t mask)
583{
584 char *cp = 0;
585 static char line[MAXHOSTNAMELEN + sizeof("&0xffffffff")];
586 char nline[INET_ADDRSTRLEN];
587 struct netent *np = 0;
588 in_addr_t i;
589
590 if (in == INADDR_ANY && mask == 0) {
591 strlcpy(line, "default", sizeof(line));
592 return (line);
593 }
594
595 /* It is ok to supply host address. */
596 in &= mask;
597
598 i = ntohl(in);
599 if (!numeric_addr && i) {
600 np = getnetbyaddr(i >> NSHIFT(ntohl(mask)), AF_INET);
601 if (np != NULL) {
602 cp = np->n_name;
603 trimdomain(cp, strlen(cp));
604 }
605 }
606 if (cp != NULL)
607 strlcpy(line, cp, sizeof(line));
608 else {
609 inet_ntop(AF_INET, &in, nline, sizeof(nline));
610 strlcpy(line, nline, sizeof(line));
611 domask(line + strlen(line), sizeof(line) - strlen(line), ntohl(mask));
612 }
613
614 return (line);
615}
616
617#undef NSHIFT
618

Callers 1

netnameFunction · 0.85

Calls 4

trimdomainFunction · 0.85
inet_ntopFunction · 0.85
domaskFunction · 0.85
strlcpyFunction · 0.50

Tested by

no test coverage detected