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

Function netname

tools/route/route.c:718–828  ·  view source on GitHub ↗

* Return the name of the network whose address is given. * The address is assumed to be that of a net, not a host. */

Source from the content-addressed store, hash-verified

716 * The address is assumed to be that of a net, not a host.
717 */
718static const char *
719netname(struct sockaddr *sa)
720{
721 struct sockaddr_dl *sdl;
722 int n;
723#ifdef INET
724#ifndef FSTACK
725 struct netent *np = NULL;
726 const char *cp = NULL;
727 u_long i;
728#else
729 const char *cp = NULL;
730#endif
731#endif
732
733 switch (sa->sa_family) {
734#ifdef INET
735 case AF_INET:
736 {
737 struct in_addr in;
738
739 in = ((struct sockaddr_in *)(void *)sa)->sin_addr;
740#ifndef FSTACK
741 i = in.s_addr = ntohl(in.s_addr);
742#else
743 in.s_addr = ntohl(in.s_addr);
744#endif
745 if (in.s_addr == 0)
746 cp = "default";
747#ifndef FSTACK
748 else if (!nflag) {
749 np = getnetbyaddr(i, AF_INET);
750 if (np != NULL)
751 cp = np->n_name;
752 }
753#endif
754
755#define C(x) (unsigned)((x) & 0xff)
756 if (cp != NULL)
757 strncpy(net_line, cp, sizeof(net_line));
758 else if ((in.s_addr & 0xffffff) == 0)
759 (void)sprintf(net_line, "%u", C(in.s_addr >> 24));
760 else if ((in.s_addr & 0xffff) == 0)
761 (void)sprintf(net_line, "%u.%u", C(in.s_addr >> 24),
762 C(in.s_addr >> 16));
763 else if ((in.s_addr & 0xff) == 0)
764 (void)sprintf(net_line, "%u.%u.%u", C(in.s_addr >> 24),
765 C(in.s_addr >> 16), C(in.s_addr >> 8));
766 else
767 (void)sprintf(net_line, "%u.%u.%u.%u", C(in.s_addr >> 24),
768 C(in.s_addr >> 16), C(in.s_addr >> 8),
769 C(in.s_addr));
770#undef C
771 break;
772 }
773#endif
774#ifdef INET6
775 case AF_INET6:

Callers 1

flushroutes_fibFunction · 0.70

Calls 7

strncpyFunction · 0.85
sprintfFunction · 0.85
memsetFunction · 0.85
inet_ntopFunction · 0.85
snprintfFunction · 0.85
link_ntoaFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected