summaryrefslogtreecommitdiffstats
path: root/if-bsd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-09-17 10:32:55 +0000
committerRoy Marples <roy@marples.name>2008-09-17 10:32:55 +0000
commitf52769ba71d9fac5acbe71a435e6018f2eacd571 (patch)
tree563f7540d02f80a77c5879341d7f635a8efefd20 /if-bsd.c
parent065125d478bfa3d0814c8a67fa0bad5fd442270b (diff)
downloaddhcpcd-f52769ba71d9fac5acbe71a435e6018f2eacd571.tar.xz
Move wireless detection from net.c into if-bsd.c and if-linux.c
Diffstat (limited to 'if-bsd.c')
-rw-r--r--if-bsd.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/if-bsd.c b/if-bsd.c
index 02f3814d..c4f65e66 100644
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -37,6 +37,7 @@
#include <net/if_types.h>
#include <net/route.h>
#include <netinet/in.h>
+#include <net80211/ieee80211_ioctl.h>
#include <errno.h>
#include <fnmatch.h>
@@ -62,6 +63,37 @@
#endif
int
+if_wireless(const char *ifname)
+{
+ int s, retval = -1;
+#if defined(SIOCG80211NWID)
+ struct ifreq ifr;
+ struct ieee80211_nwid nwid;
+#elif defined(IEEE80211_IOC_SSID)
+ struct ieee80211req ireq;
+#endif
+
+ if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+ return retval;
+#if defined(SIOCG80211NWID) /* NetBSD */
+ memset(&ifr, 0, sizeof(ifr));
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+ memset(&nwid, 0, sizeof(nwid));
+ ifr.ifr_data = (void *)&nwid;
+ if (ioctl(s, SIOCG80211NWID, &ifr) == 0)
+ retval = 0;
+#elif defined(IEEE80211_IOC_SSID) /* FreeBSD */
+ memset(&ireq, 0, sizeof(ireq));
+ strlcpy(ireq.i_name, ifname, sizeof(ireq.i_name));
+ ireq.i_type = IEEE80211_IOC_NUMSSIDS;
+ if (ioctl(s, SIOCG80211, &ireq) == 0)
+ retval = 0;
+#endif
+ close(s);
+ return retval;
+}
+
+int
if_address(const struct interface *iface, const struct in_addr *address,
const struct in_addr *netmask, const struct in_addr *broadcast,
int action)