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

Function pcblist_sysctl

tools/netstat/inet.c:98–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96#endif /* INET6 */
97
98static int
99pcblist_sysctl(int proto, const char *name, char **bufp)
100{
101 const char *mibvar;
102 char *buf;
103 size_t len;
104
105 switch (proto) {
106 case IPPROTO_TCP:
107 mibvar = "net.inet.tcp.pcblist";
108 break;
109 case IPPROTO_UDP:
110 mibvar = "net.inet.udp.pcblist";
111 break;
112 case IPPROTO_DIVERT:
113 mibvar = "net.inet.divert.pcblist";
114 break;
115 default:
116 mibvar = "net.inet.raw.pcblist";
117 break;
118 }
119 if (strncmp(name, "sdp", 3) == 0)
120 mibvar = "net.inet.sdp.pcblist";
121 len = 0;
122 if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) {
123 if (errno != ENOENT)
124 xo_warn("sysctl: %s", mibvar);
125 return (0);
126 }
127 if ((buf = malloc(len)) == NULL) {
128 xo_warnx("malloc %lu bytes", (u_long)len);
129 return (0);
130 }
131 if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) {
132 xo_warn("sysctl: %s", mibvar);
133 free(buf);
134 return (0);
135 }
136 *bufp = buf;
137 return (1);
138}
139
140#ifndef FSTACK
141/*

Callers 1

protoprFunction · 0.70

Calls 6

strncmpFunction · 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