[Olsr-dev] [PATCH] Implement a simpler way to detect wireless interfaces on *BSD.

Stefan Sperling (spam-protected)
Sun Jun 4 11:48:07 CEST 2017


On Sun, May 14, 2017 at 05:02:52PM +0200, Stefan Sperling wrote:
> The media type of an interface can be used to tell wireless interfaces
> apart. The SIOCGIFMEDIA ioctl works the same way across all BSDs,
> whereas the net80211 ioctls used previously differ.
> 
> Tested on OpenBSD only. I am confident it will work elsewhere.
> 
>  ---- Interface configuration ----
> 
> Checking ral0:
>         Wireless interface detected

Ping. Is anybody interested in such diffs?

I would eventually send more, but if they're just being ignored
I'm not sure if it's worth the effort.

It's probably just a matter of someone (Ferry?) finding some
spare time to look at them, isn't it?

Thanks :)

> ---
>  src/bsd/net.c | 45 ++++++---------------------------------------
>  1 file changed, 6 insertions(+), 39 deletions(-)
> 
> diff --git a/src/bsd/net.c b/src/bsd/net.c
> index d3b67fef..c8c910d2 100644
> --- a/src/bsd/net.c
> +++ b/src/bsd/net.c
> @@ -65,6 +65,7 @@
>  #include <string.h>
>  #include <unistd.h>
>  #include <net/if.h>
> +#include <net/if_media.h>
>  #include <sys/ioctl.h>
>  #include <fcntl.h>
>  #include <syslog.h>
> @@ -87,7 +88,6 @@
>  #ifdef __NetBSD__
>  #include <net/if_ether.h>
>  #include <netinet6/in6_var.h>   /* For struct in6_ifreq */
> -#include <net80211/ieee80211_ioctl.h>
>  #include <ifaddrs.h>
>  #endif /* __NetBSD__ */
>  
> @@ -101,8 +101,6 @@
>  #include <netinet6/in6_var.h>   /* For struct in6_ifreq */
>  #include <ifaddrs.h>
>  #include <sys/uio.h>
> -#include <net80211/ieee80211.h>
> -#include <net80211/ieee80211_ioctl.h>
>  #endif /* __OpenBSD__ */
>  
>  #if defined __FreeBSD__ || defined __FreeBSD_kernel__
> @@ -110,10 +108,6 @@
>  #include <net/ethernet.h>
>  #include <netinet/in_var.h>
>  #include <ifaddrs.h>
> -#ifndef FBSD_NO_80211
> -#include <net80211/ieee80211.h>
> -#include <net80211/ieee80211_ioctl.h>
> -#endif /* FBSD_NO_80211 */
>  #endif /* defined __FreeBSD__ || defined __FreeBSD_kernel__ */
>  
>  #ifdef __APPLE__
> @@ -748,39 +742,12 @@ olsr_select(int nfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, s
>  int
>  check_wireless_interface(char *ifname)
>  {
> -#if (defined __FreeBSD__ || defined __FreeBSD_kernel__ ) &&  !defined FBSD_NO_80211
> -
> -/* From FreeBSD ifconfig/ifieee80211.c ieee80211_status() */
> -  struct ieee80211req ireq;
> -  u_int8_t data[32];
> -
> -  memset(&ireq, 0, sizeof(ireq));
> -  strscpy(ireq.i_name, ifname, sizeof(ireq.i_name));
> -  ireq.i_data = &data;
> -  ireq.i_type = IEEE80211_IOC_SSID;
> -  ireq.i_val = -1;
> -  return (ioctl(olsr_cnf->ioctl_s, SIOCG80211, &ireq) >= 0) ? 1 : 0;
> -#elif defined __OpenBSD__
> -  struct ieee80211_nodereq nr;
> -  bzero(&nr, sizeof(nr));
> -  strscpy(nr.nr_ifname, ifname, sizeof(nr.nr_ifname));
> -  return (ioctl(olsr_cnf->ioctl_s, SIOCG80211FLAGS, &nr) >= 0) ? 1 : 0;
> -#elif defined __NetBSD__
> -  struct ifreq ireq;
> -  struct ieee80211_nwid data;
> +  struct ifmediareq ifmr;
>    int ret;
> -
> -  memset(&ireq, 0, sizeof(ireq));
> -  strscpy(ireq.ifr_name, ifname, sizeof(ireq.ifr_name));
> -  ireq.ifr_data = &data;
> -  ret = ioctl(olsr_cnf->ioctl_s, SIOCG80211NWID, &ireq);
> -  if(ret == 0)
> -	  return 1;
> -  return 0;
> -#else /* defined __NetBSD__ */
> -  ifname = NULL;                /* squelsh compiler warning */
> -  return 0;
> -#endif /* defined __NetBSD__ */
> +  bzero(&ifmr, sizeof(ifmr));
> +  strscpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
> +  ret = ioctl(olsr_cnf->ioctl_s, SIOCGIFMEDIA, (caddr_t)&ifmr);
> +  return (ret == 0 && IFM_TYPE(ifmr.ifm_current) == IFM_IEEE80211);
>  }
>  
>  #include <sys/sockio.h>
> -- 
> 2.12.2
> 
> 
> -- 
> Olsr-dev mailing list
> (spam-protected)
> https://lists.olsr.org/mailman/listinfo/olsr-dev



More information about the Olsr-dev mailing list