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

Function pcblist_sysctl

tools/netstat/unix.c:77–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75 { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" };
76
77static int
78pcblist_sysctl(int type, char **bufp)
79{
80 char *buf;
81 size_t len;
82 char mibvar[sizeof "net.local.seqpacket.pcblist"];
83
84 snprintf(mibvar, sizeof(mibvar), "net.local.%s.pcblist", socktype[type]);
85
86 len = 0;
87 if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) {
88 if (errno != ENOENT)
89 xo_warn("sysctl: %s", mibvar);
90 return (-1);
91 }
92 if ((buf = malloc(len)) == NULL) {
93 xo_warnx("malloc %lu bytes", (u_long)len);
94 return (-2);
95 }
96 if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) {
97 xo_warn("sysctl: %s", mibvar);
98 free(buf);
99 return (-2);
100 }
101 *bufp = buf;
102 return (0);
103}
104
105#ifndef FSTACK
106static int

Callers 1

unixprFunction · 0.70

Calls 6

snprintfFunction · 0.85
sysctlbynameFunction · 0.85
xo_warnFunction · 0.85
mallocFunction · 0.85
xo_warnxFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected