本文整理汇总了C++中IFM_TYPE函数的典型用法代码示例。如果您正苦于以下问题:C++ IFM_TYPE函数的具体用法?C++ IFM_TYPE怎么用?C++ IFM_TYPE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IFM_TYPE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setmedia
static void
setmedia(const char *val, int d, int s, const struct afswtch *afp)
{
struct ifmediareq *ifmr;
int subtype;
ifmr = ifmedia_getstate(s);
/*
* We are primarily concerned with the top-level type.
* However, "current" may be only IFM_NONE, so we just look
* for the top-level type in the first "supported type"
* entry.
*
* (I'm assuming that all supported media types for a given
* interface will be the same top-level type..)
*/
subtype = get_media_subtype(IFM_TYPE(ifmr->ifm_ulist[0]), val);
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_media = (ifmr->ifm_current & ~(IFM_NMASK|IFM_TMASK)) |
IFM_TYPE(ifmr->ifm_ulist[0]) | subtype;
if ((ifr.ifr_media & IFM_TMASK) == 0) {
ifr.ifr_media &= ~(IFM_GMASK | IFM_OMASK);
}
ifmr->ifm_current = ifr.ifr_media;
callback_register(setifmediacallback, (void *)ifmr);
}
示例2: qe_ifmedia_upd
/*
* Set media options.
*/
int
qe_ifmedia_upd(struct ifnet *ifp)
{
struct qe_softc *sc = ifp->if_softc;
struct ifmedia *ifm = &sc->sc_ifmedia;
bus_space_tag_t t = sc->sc_bustag;
bus_space_handle_t mr = sc->sc_mr;
int newmedia = ifm->ifm_media;
uint8_t plscc, phycc;
#if defined(SUN4U) || defined(__GNUC__)
(void)&t;
#endif
if (IFM_TYPE(newmedia) != IFM_ETHER)
return (EINVAL);
plscc = bus_space_read_1(t, mr, QE_MRI_PLSCC) & ~QE_MR_PLSCC_PORTMASK;
phycc = bus_space_read_1(t, mr, QE_MRI_PHYCC) & ~QE_MR_PHYCC_ASEL;
if (IFM_SUBTYPE(newmedia) == IFM_AUTO)
phycc |= QE_MR_PHYCC_ASEL;
else if (IFM_SUBTYPE(newmedia) == IFM_10_T)
plscc |= QE_MR_PLSCC_TP;
else if (IFM_SUBTYPE(newmedia) == IFM_10_5)
plscc |= QE_MR_PLSCC_AUI;
bus_space_write_1(t, mr, QE_MRI_PLSCC, plscc);
bus_space_write_1(t, mr, QE_MRI_PHYCC, phycc);
return (0);
}
示例3: init_current_media
int
init_current_media(int s, char *ifname)
{
int media_current;
struct ifmediareq ifmr;
(void) memset(&ifmr, 0, sizeof(ifmr));
(void) strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
if (ioctl(s, SIOCGIFMEDIA, (caddr_t) & ifmr) < 0) {
/*
* If we get E2BIG, the kernel is telling us
* that there are more, so we can ignore it.
*/
if (errno != E2BIG)
return(-1);
}
media_current = ifmr.ifm_current;
/* Sanity. */
if (IFM_TYPE(media_current) == 0) {
printf("%% init_current_media: %s: no link type?\n", ifname);
return(-1);
}
return(media_current);
}
示例4: rtems_ifmedia2str
int
rtems_ifmedia2str (int media, char *buf, int bufsz)
{
const char *mdesc;
const char *dupdesc = 0;
/* only ethernet supported, so far */
if (IFM_ETHER != IFM_TYPE (media))
return -1;
if (!(mdesc = find_desc (IFM_SUBTYPE (media), shared_media_strings)))
mdesc = find_desc (IFM_SUBTYPE (media), ethern_media_strings);
if (!mdesc)
return -1;
if (IFM_NONE != IFM_SUBTYPE (media))
dupdesc = IFM_FDX & media ? " full-duplex" : " half-duplex";
return WHATPRINT (buf, bufsz,
"Ethernet [phy instance: %" PRId32 "]: (link %s, autoneg %s) -- media: %s%s",
(int32_t) IFM_INST (media),
IFM_LINK_OK & media ? "ok" : "down",
IFM_ANEG_DIS & media ? "off" : "on",
mdesc, dupdesc ? dupdesc : "");
}
示例5: tr_pcmcia_mediachange
static int
tr_pcmcia_mediachange(struct tr_softc *sc)
{
int setspeed = 0;
if (IFM_TYPE(sc->sc_media.ifm_media) != IFM_TOKEN)
return EINVAL;
switch (IFM_SUBTYPE(sc->sc_media.ifm_media)) {
case IFM_TOK_STP16:
case IFM_TOK_UTP16:
if ((sc->sc_init_status & RSP_16) == 0)
setspeed = 1;
break;
case IFM_TOK_STP4:
case IFM_TOK_UTP4:
if ((sc->sc_init_status & RSP_16) != 0)
setspeed = 1;
break;
}
if (setspeed != 0) {
tr_stop(sc);
if (sc->sc_enabled)
tr_pcmcia_disable(sc);
sc->sc_init_status ^= RSP_16; /* XXX 100 Mbit/s */
if (sc->sc_enabled)
tr_pcmcia_enable(sc);
}
/*
* XXX Handle Early Token Release !!!!
*/
return 0;
}
示例6: s_wireless_nic
static bool
s_wireless_nic (const char* name)
{
int sock = 0;
bool result = FALSE;
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
return FALSE;
#if defined (SIOCGIFMEDIA)
struct ifmediareq ifmr;
memset (&ifmr, 0, sizeof (struct ifmediareq));
strncpy(ifmr.ifm_name, name, sizeof (ifmr.ifm_name));
int res = ioctl (sock, SIOCGIFMEDIA, (caddr_t) &ifmr);
if (res != -1)
result = (IFM_TYPE (ifmr.ifm_current) == IFM_IEEE80211);
#elif defined (SIOCGIWNAME)
struct iwreq wrq;
memset (&wrq, 0, sizeof (struct iwreq));
strncpy (wrq.ifr_name, name, sizeof (wrq.ifr_name));
int res = ioctl (sock, SIOCGIWNAME, (caddr_t) &wrq);
if (res != -1)
result = TRUE;
#endif
close (sock);
return result;
}
示例7: set_port_media
static void
set_port_media(struct cfg *cfg, char *argv[])
{
etherswitch_port_t p;
int ifm_ulist[IFMEDIAREQ_NULISTENTRIES];
int subtype;
bzero(&p, sizeof(p));
p.es_port = cfg->unit;
p.es_ifmr.ifm_ulist = ifm_ulist;
p.es_ifmr.ifm_count = IFMEDIAREQ_NULISTENTRIES;
if (ioctl(cfg->fd, IOETHERSWITCHGETPORT, &p) != 0)
err(EX_OSERR, "ioctl(IOETHERSWITCHGETPORT)");
subtype = get_media_subtype(IFM_TYPE(ifm_ulist[0]), argv[1]);
p.es_ifr.ifr_media = (p.es_ifmr.ifm_current & IFM_IMASK) |
IFM_TYPE(ifm_ulist[0]) | subtype;
if (ioctl(cfg->fd, IOETHERSWITCHSETPORT, &p) != 0)
err(EX_OSERR, "ioctl(IOETHERSWITCHSETPORT)");
}
示例8:
static struct ifmedia_description *get_toptype_desc(int ifmw)
{
struct ifmedia_description *desc;
for (desc = ifm_type_descriptions; desc->ifmt_string != NULL; desc++)
if (IFM_TYPE(ifmw) == desc->ifmt_word)
break;
return desc;
}
示例9: memset
bool NetworkInterface::isWireless()
{
struct ifmediareq ifm;
memset(&ifm, 0, sizeof(struct ifmediareq));
strncpy(ifm.ifm_name, name.toLocal8Bit(), IFNAMSIZ);
int s = socket(AF_INET, SOCK_DGRAM, 0);
ioctl(s, SIOCGIFMEDIA, &ifm);
return IFM_TYPE(ifm.ifm_active) == IFM_IEEE80211;
}
示例10: get_media_type_string
const char *
get_media_type_string(uint64_t mword)
{
const struct ifmedia_description *desc;
for (desc = ifm_type_descriptions; desc->ifmt_string != NULL;
desc++) {
if (IFM_TYPE(mword) == desc->ifmt_word)
return (desc->ifmt_string);
}
return ("<unknown type>");
}
示例11: ixl_if_media_change
/*********************************************************************
*
* Media Ioctl callback
*
* This routine is called when the user changes speed/duplex using
* media/mediopt option with ifconfig.
*
**********************************************************************/
int
ixl_if_media_change(if_ctx_t ctx)
{
struct ifmedia *ifm = iflib_get_media(ctx);
INIT_DEBUGOUT("ixl_media_change: begin");
if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
return (EINVAL);
if_printf(iflib_get_ifp(ctx), "Media change is currently not supported.\n");
return (ENODEV);
}
示例12: intmediaopt
int
intmediaopt(char *ifname, int ifs, int argc, char **argv)
{
int set, media_current, mediaopt;
if (NO_ARG(argv[0])) {
set = 0;
argc--;
argv++;
} else
set = 1;
argv++;
argc--;
if ((set && (argc != 1)) || (!set && (argc > 1))) {
printf("%% mediaopt <option>\n");
printf("%% no mediaopt [option]\n");
return(0);
}
media_current = init_current_media(ifs, ifname);
if (media_current == -1) {
if (errno == EINVAL)
printf("%% This device does not support "
"media commands.\n");
else
printf("%% Failed to initialize media: %s\n",
strerror(errno));
return(0);
}
if (argc == 1)
mediaopt = get_media_options(IFM_TYPE(media_current), argv[0]);
else
mediaopt = IFM_OPTIONS(media_current);
if (mediaopt == -1)
return(0);
if (set)
media_current |= mediaopt;
else
media_current &= ~mediaopt;
process_media_commands(ifs, ifname, media_current);
return(0);
}
示例13: sln_media_upd
static int
sln_media_upd(struct ifnet *ifp)
{
struct sln_softc *sc = ifp->if_softc;
struct ifmedia *ifm = &sc->ifmedia;
if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
return EINVAL;
if (ifp->if_flags & IFF_UP)
sln_init(sc);
return 0;
}
示例14: media_supported
void
media_supported(int s, char *ifname, char *hdr_delim, char *body_delim)
{
u_int64_t *media_list;
int i, type, printed_type;
struct ifmediareq ifmr;
memset(&ifmr, 0, sizeof(ifmr));
strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
if (errno != ENOTTY)
printf("%% media_supported: 1/SIOCGIFMEDIA: %s\n",
strerror(errno));
return;
}
media_list = calloc(ifmr.ifm_count, sizeof(*media_list));
if (media_list == NULL) {
printf("%% media_status: calloc: %s\n", strerror(errno));
return;
}
ifmr.ifm_ulist = media_list;
if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
printf("%% media_supported: 2/SIOCGIFMEDIA: %s\n",
strerror(errno));
return;
}
for (type = IFM_NMIN; type <= IFM_NMAX; type += IFM_NMIN) {
for (i = 0, printed_type = 0; i < ifmr.ifm_count; i++) {
if (IFM_TYPE(media_list[i]) == type) {
if (printed_type == 0) {
printf("%sSupported media types on %s:\n",
hdr_delim, ifname);
printed_type = 1;
}
printf("%s", body_delim);
print_media_word(media_list[i], 0, 1);
printf("\n");
}
}
}
free(media_list);
return;
}
示例15: setmediamode
static void
setmediamode(const char *val, int d, int s, const struct afswtch *afp)
{
struct ifmediareq *ifmr;
int mode;
ifmr = ifmedia_getstate(s);
mode = get_media_mode(IFM_TYPE(ifmr->ifm_ulist[0]), val);
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_media = (ifmr->ifm_current & ~IFM_MMASK) | mode;
ifmr->ifm_current = ifr.ifr_media;
callback_register(setifmediacallback, (void *)ifmr);
}