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

Function media_status

tools/ifconfig/ifmedia.c:110–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108#define IFM_IEEE80211_STA 0
109
110static void
111media_status(int s)
112{
113 struct ifmediareq ifmr;
114 struct ifdownreason ifdr;
115 int *media_list, i;
116 bool no_carrier, xmedia;
117
118 (void) memset(&ifmr, 0, sizeof(ifmr));
119 (void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
120 xmedia = true;
121
122 /*
123 * Check if interface supports extended media types.
124 */
125 if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0)
126 xmedia = false;
127 if (!xmedia && ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
128 /*
129 * Interface doesn't support SIOC{G,S}IFMEDIA.
130 */
131 return;
132 }
133
134 if (ifmr.ifm_count == 0) {
135 warnx("%s: no media types?", name);
136 return;
137 }
138
139 media_list = (int *)malloc(ifmr.ifm_count * sizeof(int));
140 if (media_list == NULL)
141 err(1, "malloc");
142 ifmr.ifm_ulist = media_list;
143
144 if (xmedia) {
145 if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0)
146 err(1, "SIOCGIFXMEDIA");
147 } else {
148 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0)
149 err(1, "SIOCGIFMEDIA");
150 }
151
152 printf("\tmedia: ");
153 print_media_word(ifmr.ifm_current, 1);
154 if (ifmr.ifm_active != ifmr.ifm_current) {
155 putchar(' ');
156 putchar('(');
157 print_media_word(ifmr.ifm_active, 0);
158 putchar(')');
159 }
160
161 putchar('\n');
162
163 if (ifmr.ifm_status & IFM_AVALID) {
164 no_carrier = false;
165 printf("\tstatus: ");
166 switch (IFM_TYPE(ifmr.ifm_active)) {
167 case IFM_ETHER:

Callers

nothing calls this directly

Calls 9

memsetFunction · 0.85
mallocFunction · 0.85
print_media_wordFunction · 0.85
putcharFunction · 0.85
strlcpyFunction · 0.50
ioctlFunction · 0.50
printfFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected