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

Function intpr

tools/netstat/if.c:271–501  ·  view source on GitHub ↗

* Print a description of the network interfaces. */

Source from the content-addressed store, hash-verified

269 * Print a description of the network interfaces.
270 */
271void
272intpr(void (*pfunc)(char *), int af)
273{
274 struct ifaddrs *ifap, *ifa;
275 struct ifmaddrs *ifmap, *ifma;
276 u_int ifn_len_max = 5, ifn_len;
277 u_int has_ipv6 = 0, net_len = 13, addr_len = 17;
278
279 if (interval)
280 return sidewaysintpr();
281
282 if (getifaddrs(&ifap) != 0)
283 err(EX_OSERR, "getifaddrs");
284 if (aflag && getifmaddrs(&ifmap) != 0)
285 err(EX_OSERR, "getifmaddrs");
286
287 if (Wflag) {
288 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
289 if (interface != NULL &&
290 strcmp(ifa->ifa_name, interface) != 0)
291 continue;
292 if (af != AF_UNSPEC && ifa->ifa_addr->sa_family != af)
293 continue;
294 ifn_len = strlen(ifa->ifa_name);
295 if ((ifa->ifa_flags & IFF_UP) == 0)
296 ++ifn_len;
297 ifn_len_max = MAX(ifn_len_max, ifn_len);
298 if (ifa->ifa_addr->sa_family == AF_INET6)
299 has_ipv6 = 1;
300 }
301 if (has_ipv6) {
302 net_len = 24;
303 addr_len = 39;
304 } else
305 net_len = 18;
306 }
307
308 xo_open_list("interface");
309 if (!pfunc) {
310 xo_emit("{T:/%-*.*s}", ifn_len_max, ifn_len_max, "Name");
311 xo_emit(" {T:/%5.5s} {T:/%-*.*s} {T:/%-*.*s} {T:/%8.8s} "
312 "{T:/%5.5s} {T:/%5.5s}",
313 "Mtu", net_len, net_len, "Network", addr_len, addr_len,
314 "Address", "Ipkts", "Ierrs", "Idrop");
315 if (bflag)
316 xo_emit(" {T:/%10.10s}","Ibytes");
317 xo_emit(" {T:/%8.8s} {T:/%5.5s}", "Opkts", "Oerrs");
318 if (bflag)
319 xo_emit(" {T:/%10.10s}","Obytes");
320 xo_emit(" {T:/%5s}", "Coll");
321 if (dflag)
322 xo_emit(" {T:/%5.5s}", "Drop");
323 xo_emit("\n");
324 }
325
326 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
327 bool network = false, link = false;
328 char *name, *xname, buf[IFNAMSIZ+1];

Callers 2

main.cFile · 0.85
printprotoFunction · 0.85

Calls 15

sidewaysintprFunction · 0.85
getifaddrsFunction · 0.85
getifmaddrsFunction · 0.85
strcmpFunction · 0.85
xo_open_listFunction · 0.85
xo_emitFunction · 0.85
xo_open_instanceFunction · 0.85
show_statFunction · 0.85
snprintfFunction · 0.85
xo_close_instanceFunction · 0.85
next_ifmaFunction · 0.85
xo_close_listFunction · 0.85

Tested by

no test coverage detected