Changeset View
Changeset View
Standalone View
Standalone View
sbin/ifconfig/ifmedia.c
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | |||||
#include <net/if_types.h> | #include <net/if_types.h> | ||||
#include <net/if_media.h> | #include <net/if_media.h> | ||||
#include <net/route.h> | #include <net/route.h> | ||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <stdbool.h> | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include "ifconfig.h" | #include "ifconfig.h" | ||||
static void domediaopt(const char *, int, int); | static void domediaopt(const char *, int, int); | ||||
Show All 14 Lines | #define IFM_OPMODE(x) \ | ||||
IFM_IEEE80211_IBSS | IFM_IEEE80211_WDS | IFM_IEEE80211_MONITOR | \ | IFM_IEEE80211_IBSS | IFM_IEEE80211_WDS | IFM_IEEE80211_MONITOR | \ | ||||
IFM_IEEE80211_MBSS)) | IFM_IEEE80211_MBSS)) | ||||
#define IFM_IEEE80211_STA 0 | #define IFM_IEEE80211_STA 0 | ||||
static void | static void | ||||
media_status(int s) | media_status(int s) | ||||
{ | { | ||||
struct ifmediareq ifmr; | struct ifmediareq ifmr; | ||||
struct ifdownreason ifdr; | |||||
int *media_list, i; | int *media_list, i; | ||||
int xmedia = 1; | bool no_carrier, xmedia; | ||||
(void) memset(&ifmr, 0, sizeof(ifmr)); | (void) memset(&ifmr, 0, sizeof(ifmr)); | ||||
(void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); | (void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); | ||||
xmedia = true; | |||||
/* | /* | ||||
* Check if interface supports extended media types. | * Check if interface supports extended media types. | ||||
*/ | */ | ||||
if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0) | if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0) | ||||
xmedia = 0; | xmedia = false; | ||||
if (xmedia == 0 && ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) { | if (!xmedia && ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) { | ||||
/* | /* | ||||
* Interface doesn't support SIOC{G,S}IFMEDIA. | * Interface doesn't support SIOC{G,S}IFMEDIA. | ||||
*/ | */ | ||||
return; | return; | ||||
} | } | ||||
if (ifmr.ifm_count == 0) { | if (ifmr.ifm_count == 0) { | ||||
warnx("%s: no media types?", name); | warnx("%s: no media types?", name); | ||||
Show All 20 Lines | if (ifmr.ifm_active != ifmr.ifm_current) { | ||||
putchar('('); | putchar('('); | ||||
print_media_word(ifmr.ifm_active, 0); | print_media_word(ifmr.ifm_active, 0); | ||||
putchar(')'); | putchar(')'); | ||||
} | } | ||||
putchar('\n'); | putchar('\n'); | ||||
if (ifmr.ifm_status & IFM_AVALID) { | if (ifmr.ifm_status & IFM_AVALID) { | ||||
no_carrier = false; | |||||
printf("\tstatus: "); | printf("\tstatus: "); | ||||
switch (IFM_TYPE(ifmr.ifm_active)) { | switch (IFM_TYPE(ifmr.ifm_active)) { | ||||
case IFM_ETHER: | case IFM_ETHER: | ||||
case IFM_ATM: | case IFM_ATM: | ||||
if (ifmr.ifm_status & IFM_ACTIVE) | if (ifmr.ifm_status & IFM_ACTIVE) | ||||
printf("active"); | printf("active"); | ||||
else | else | ||||
printf("no carrier"); | no_carrier = true; | ||||
break; | break; | ||||
case IFM_IEEE80211: | case IFM_IEEE80211: | ||||
if (ifmr.ifm_status & IFM_ACTIVE) { | if (ifmr.ifm_status & IFM_ACTIVE) { | ||||
/* NB: only sta mode associates */ | /* NB: only sta mode associates */ | ||||
if (IFM_OPMODE(ifmr.ifm_active) == IFM_IEEE80211_STA) | if (IFM_OPMODE(ifmr.ifm_active) == IFM_IEEE80211_STA) | ||||
printf("associated"); | printf("associated"); | ||||
else | else | ||||
printf("running"); | printf("running"); | ||||
} else | } else | ||||
no_carrier = true; | |||||
break; | |||||
} | |||||
if (no_carrier) { | |||||
printf("no carrier"); | printf("no carrier"); | ||||
memset(&ifdr, 0, sizeof(ifdr)); | |||||
strlcpy(ifdr.ifdr_name, name, sizeof(ifdr.ifdr_name)); | |||||
if (ioctl(s, SIOCGIFDOWNREASON, (caddr_t)&ifdr) == 0) { | |||||
switch (ifdr.ifdr_reason) { | |||||
case IFDR_REASON_MSG: | |||||
printf(" (%s)", ifdr.ifdr_msg); | |||||
hselasky: Should there be some filter or forced zero at on ifdr_msg ?
ifdr_msg[sizeof(ifdr_msg) - 1] = 0… | |||||
kibAuthorUnsubmitted Done Inline ActionsKernel must zero-terminate the string. Why would utility not trust the kernel ? kib: Kernel must zero-terminate the string. Why would utility not trust the kernel ? | |||||
hselaskyUnsubmitted Not Done Inline ActionsOK, but what about non-printable characters? Is the kernel responsible to filter this? I don't trust hardware/firmware to provide correct strings :-) hselasky: OK, but what about non-printable characters? Is the kernel responsible to filter this? I don't… | |||||
kibAuthorUnsubmitted Done Inline ActionsI am not sure, and I think it is premature to do anything about it until there is a driver that does emit something non-printable. Even then, I think this is a problem of the driver, and not kernel/ifconfig. kib: I am not sure, and I think it is premature to do anything about it until there is a driver that… | |||||
break; | break; | ||||
case IFDR_REASON_VENDOR: | |||||
printf(" (vendor code %d)", | |||||
ifdr.ifdr_vendor); | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
} | |||||
} | } | ||||
putchar('\n'); | putchar('\n'); | ||||
} | } | ||||
if (ifmr.ifm_count > 0 && supmedia) { | if (ifmr.ifm_count > 0 && supmedia) { | ||||
printf("\tsupported media:\n"); | printf("\tsupported media:\n"); | ||||
for (i = 0; i < ifmr.ifm_count; i++) { | for (i = 0; i < ifmr.ifm_count; i++) { | ||||
printf("\t\t"); | printf("\t\t"); | ||||
▲ Show 20 Lines • Show All 605 Lines • Show Last 20 Lines |
Should there be some filter or forced zero at on ifdr_msg ?
ifdr_msg[sizeof(ifdr_msg) - 1] = 0 ??