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

Function ifmedia_getstate

tools/ifconfig/ifmedia.c:219–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217}
218
219struct ifmediareq *
220ifmedia_getstate(int s)
221{
222 static struct ifmediareq *ifmr = NULL;
223 int *mwords;
224 int xmedia = 1;
225
226 if (ifmr == NULL) {
227 ifmr = (struct ifmediareq *)malloc(sizeof(struct ifmediareq));
228 if (ifmr == NULL)
229 err(1, "malloc");
230
231 (void) memset(ifmr, 0, sizeof(struct ifmediareq));
232 (void) strlcpy(ifmr->ifm_name, name,
233 sizeof(ifmr->ifm_name));
234
235 ifmr->ifm_count = 0;
236 ifmr->ifm_ulist = NULL;
237
238 /*
239 * We must go through the motions of reading all
240 * supported media because we need to know both
241 * the current media type and the top-level type.
242 */
243
244 if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)ifmr) < 0) {
245 xmedia = 0;
246 }
247 if (xmedia == 0 && ioctl(s, SIOCGIFMEDIA, (caddr_t)ifmr) < 0) {
248 err(1, "SIOCGIFMEDIA");
249 }
250
251 if (ifmr->ifm_count == 0)
252 errx(1, "%s: no media types?", name);
253
254 mwords = (int *)malloc(ifmr->ifm_count * sizeof(int));
255 if (mwords == NULL)
256 err(1, "malloc");
257
258 ifmr->ifm_ulist = mwords;
259 if (xmedia) {
260 if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)ifmr) < 0)
261 err(1, "SIOCGIFXMEDIA");
262 } else {
263 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)ifmr) < 0)
264 err(1, "SIOCGIFMEDIA");
265 }
266 }
267
268 return ifmr;
269}
270
271static void
272setifmediacallback(int s, void *arg)

Callers 5

getchaninfoFunction · 0.85
setmediaFunction · 0.85
domediaoptFunction · 0.85
setmediainstFunction · 0.85
setmediamodeFunction · 0.85

Calls 4

mallocFunction · 0.85
memsetFunction · 0.85
strlcpyFunction · 0.50
ioctlFunction · 0.50

Tested by

no test coverage detected