Changeset View
Changeset View
Standalone View
Standalone View
sbin/ifconfig/ifmedia.c
Show First 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | media_status(int s) | ||||
} | } | ||||
free: | free: | ||||
free(ifmr); | free(ifmr); | ||||
} | } | ||||
struct ifmediareq * | struct ifmediareq * | ||||
ifmedia_getstate(void) | ifmedia_getstate(void) | ||||
{ | { | ||||
static struct ifmediareq *ifmr; | static struct ifmediareq *ifmr = NULL; | ||||
if (ifmr != NULL) | |||||
return (ifmr); | |||||
if (ifconfig_media_get_mediareq(lifh, name, &ifmr) == -1) | if (ifconfig_media_get_mediareq(lifh, name, &ifmr) == -1) | ||||
errc(1, ifconfig_err_errno(lifh), | errc(1, ifconfig_err_errno(lifh), | ||||
"%s: ifconfig_media_get_mediareq", name); | "%s: ifconfig_media_get_mediareq", name); | ||||
if (ifmr->ifm_count == 0) | if (ifmr->ifm_count == 0) | ||||
errx(1, "%s: no media types?", name); | errx(1, "%s: no media types?", name); | ||||
return (ifmr); | return (ifmr); | ||||
} | } | ||||
static void | static void | ||||
setifmediacallback(int s, void *arg) | setifmediacallback(int s, void *arg) | ||||
{ | { | ||||
struct ifmediareq *ifmr = (struct ifmediareq *)arg; | struct ifmediareq *ifmr = (struct ifmediareq *)arg; | ||||
static bool did_it = false; | static bool did_it = false; | ||||
if (!did_it) { | if (!did_it) { | ||||
ifr.ifr_media = ifmr->ifm_current; | ifr.ifr_media = ifmr->ifm_current; | ||||
if (ioctl(s, SIOCSIFMEDIA, (caddr_t)&ifr) < 0) | if (ioctl(s, SIOCSIFMEDIA, (caddr_t)&ifr) < 0) | ||||
err(1, "SIOCSIFMEDIA (media)"); | err(1, "SIOCSIFMEDIA (media)"); | ||||
free(ifmr); | free(ifmr); | ||||
donner: There is the free(3) call. | |||||
Done Inline ActionsThe callback is a one-shot (see the next line) so we only free this once. That confused me at first, too. freqlabs: The callback is a one-shot (see the next line) so we only free this once. That confused me at… | |||||
did_it = true; | did_it = true; | ||||
} | } | ||||
} | } | ||||
static void | static void | ||||
setmedia(const char *val, int d, int s, const struct afswtch *afp) | setmedia(const char *val, int d, int s, const struct afswtch *afp) | ||||
{ | { | ||||
struct ifmediareq *ifmr; | struct ifmediareq *ifmr; | ||||
int subtype; | int subtype; | ||||
ifmr = ifmedia_getstate(); | ifmr = ifmedia_getstate(); | ||||
Not Done Inline ActionsThis retrieves the singleton value. donner: This retrieves the singleton value. | |||||
/* | /* | ||||
* We are primarily concerned with the top-level type. | * We are primarily concerned with the top-level type. | ||||
* However, "current" may be only IFM_NONE, so we just look | * However, "current" may be only IFM_NONE, so we just look | ||||
* for the top-level type in the first "supported type" | * for the top-level type in the first "supported type" | ||||
* entry. | * entry. | ||||
* | * | ||||
* (I'm assuming that all supported media types for a given | * (I'm assuming that all supported media types for a given | ||||
* interface will be the same top-level type..) | * interface will be the same top-level type..) | ||||
*/ | */ | ||||
subtype = get_media_subtype(ifmr->ifm_ulist[0], val); | subtype = get_media_subtype(ifmr->ifm_ulist[0], val); | ||||
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); | strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); | ||||
ifr.ifr_media = (ifmr->ifm_current & IFM_IMASK) | | ifr.ifr_media = (ifmr->ifm_current & IFM_IMASK) | | ||||
IFM_TYPE(ifmr->ifm_ulist[0]) | subtype; | IFM_TYPE(ifmr->ifm_ulist[0]) | subtype; | ||||
ifmr->ifm_current = ifr.ifr_media; | ifmr->ifm_current = ifr.ifr_media; | ||||
callback_register(setifmediacallback, (void *)ifmr); | callback_register(setifmediacallback, (void *)ifmr); | ||||
Not Done Inline ActionsThis callback could free the "ifrm" pointer, which is returned from the singleton call above. donner: This callback could free the "ifrm" pointer, which is returned from the singleton call above. | |||||
} | } | ||||
static void | static void | ||||
setmediaopt(const char *val, int d, int s, const struct afswtch *afp) | setmediaopt(const char *val, int d, int s, const struct afswtch *afp) | ||||
{ | { | ||||
domediaopt(val, false, s); | domediaopt(val, false, s); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 270 Lines • Show Last 20 Lines |
There is the free(3) call.