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

Function in_status

tools/ifconfig/af_inet.c:62–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60extern char *f_inet, *f_addr;
61
62static void
63in_status(int s __unused, const struct ifaddrs *ifa)
64{
65 struct sockaddr_in *sin, null_sin;
66#ifndef FSTACK
67 int error, n_flags;
68#endif
69
70 memset(&null_sin, 0, sizeof(null_sin));
71
72 sin = (struct sockaddr_in *)ifa->ifa_addr;
73 if (sin == NULL)
74 return;
75
76#ifndef FSTACK
77 if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0)
78 n_flags = 0;
79 else if (f_addr != NULL && strcmp(f_addr, "host") == 0)
80 n_flags = NI_NOFQDN;
81 else
82 n_flags = NI_NUMERICHOST;
83
84 error = getnameinfo((struct sockaddr *)sin, sin->sin_len, addr_buf,
85 sizeof(addr_buf), NULL, 0, n_flags);
86
87 if (error)
88#endif
89 inet_ntop(AF_INET, &sin->sin_addr, addr_buf, sizeof(addr_buf));
90
91 printf("\tinet %s", addr_buf);
92
93 if (ifa->ifa_flags & IFF_POINTOPOINT) {
94 sin = (struct sockaddr_in *)ifa->ifa_dstaddr;
95 if (sin == NULL)
96 sin = &null_sin;
97 printf(" --> %s", inet_ntoa(sin->sin_addr));
98 }
99
100 sin = (struct sockaddr_in *)ifa->ifa_netmask;
101 if (sin == NULL)
102 sin = &null_sin;
103 if (f_inet != NULL && strcmp(f_inet, "cidr") == 0) {
104 int cidr = 32;
105 unsigned long smask;
106
107 smask = ntohl(sin->sin_addr.s_addr);
108 while ((smask & 1) == 0) {
109 smask = smask >> 1;
110 cidr--;
111 if (cidr == 0)
112 break;
113 }
114 printf("/%d", cidr);
115 } else if (f_inet != NULL && strcmp(f_inet, "dotted") == 0)
116 printf(" netmask %s", inet_ntoa(sin->sin_addr));
117 else
118 printf(" netmask 0x%lx", (unsigned long)ntohl(sin->sin_addr.s_addr));
119

Callers

nothing calls this directly

Calls 6

memsetFunction · 0.85
strcmpFunction · 0.85
inet_ntopFunction · 0.85
print_vhidFunction · 0.85
putcharFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected