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

Function getdefif

tools/ndp/ndp.c:1403–1429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1401}
1402
1403static void
1404getdefif()
1405{
1406 struct in6_ndifreq ndifreq;
1407 char ifname[IFNAMSIZ+8];
1408 int sock;
1409
1410 if ((sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
1411 err(1, "socket");
1412
1413 memset(&ndifreq, 0, sizeof(ndifreq));
1414 strlcpy(ndifreq.ifname, "lo0", sizeof(ndifreq.ifname)); /* dummy */
1415
1416 if (ioctl(sock, SIOCGDEFIFACE_IN6, (caddr_t)&ndifreq) < 0)
1417 err(1, "ioctl(SIOCGDEFIFACE_IN6)");
1418
1419 if (ndifreq.ifindex == 0)
1420 printf("No default interface.\n");
1421 else {
1422 if ((if_indextoname(ndifreq.ifindex, ifname)) == NULL)
1423 err(1, "failed to resolve ifname for index %lu",
1424 ndifreq.ifindex);
1425 printf("ND default interface = %s\n", ifname);
1426 }
1427
1428 close(sock);
1429}
1430#endif /* SIOCSDEFIFACE_IN6 */
1431
1432static char *

Callers 1

mainFunction · 0.85

Calls 7

memsetFunction · 0.85
if_indextonameFunction · 0.85
socketClass · 0.50
strlcpyFunction · 0.50
ioctlFunction · 0.50
printfFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected