summaryrefslogtreecommitdiffstats
path: root/if-bsd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2014-09-10 02:02:21 +0000
committerRoy Marples <roy@marples.name>2014-09-10 02:02:21 +0000
commit0477b8a434c052542aaed0c593f1b50b55dddefe (patch)
tree35095aa58ab4afe036289e897b346d1b682831fb /if-bsd.c
parent67ed6c5fdc76fa237307750d84251de7857f7e99 (diff)
downloaddhcpcd-0477b8a434c052542aaed0c593f1b50b55dddefe.tar.xz
Fix compile and warnings on BSD.
Diffstat (limited to 'if-bsd.c')
-rw-r--r--if-bsd.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/if-bsd.c b/if-bsd.c
index baf7c355..d951ca2a 100644
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -137,8 +137,8 @@ if_openlinksocket(void)
#endif
}
-int
-if_getssid(struct interface *ifp)
+static int
+if_getssid1(const char *ifname, char *ssid)
{
int s, retval = -1;
#if defined(SIOCG80211NWID)
@@ -154,18 +154,19 @@ if_getssid(struct interface *ifp)
#if defined(SIOCG80211NWID) /* NetBSD */
memset(&ifr, 0, sizeof(ifr));
- strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
+ 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) {
- if (nwid.i_len > sizeof(ifp->ssid)) {
+ if (ssid == NULL)
+ retval = nwid.i_len;
+ else if (nwid.i_len > IF_SSIDSIZE) {
errno = ENOBUFS;
retval = -1;
} else {
retval = nwid.i_len;
- memcpy(ifp->ssid, nwid.i_nwid, nwid.i_len);
+ memcpy(ssid, nwid.i_nwid, nwid.i_len);
ssid[nwid.i_len] = '\0';
- ifp->ssid_len = nwid.i_len;
}
}
#elif defined(IEEE80211_IOC_SSID) /* FreeBSD */
@@ -176,14 +177,15 @@ if_getssid(struct interface *ifp)
memset(nwid, 0, sizeof(nwid));
ireq.i_data = &nwid;
if (ioctl(s, SIOCG80211, &ireq) == 0) {
- if (ireq.i_len > sizeof(ifp->ssid)) {
+ if (ssid == NULL)
+ retval = ireq.i_len;
+ else if (ireq.i_len > IF_SSIDSIZE) {
errno = ENOBUFS;
retval = -1;
} else {
retval = ireq.i_len;
- memcpy(ifp->ssid, nwid, ireq.i_len);
- ifp->ssid[ireq.i_len] = '\0';
- ifp->ssid_len = ireq.i_len;
+ memcpy(ssid, nwid, ireq.i_len);
+ ssid[ireq.i_len] = '\0';
}
}
#endif
@@ -192,6 +194,17 @@ if_getssid(struct interface *ifp)
return retval;
}
+int
+if_getssid(struct interface *ifp)
+{
+ int r;
+
+ r = if_getssid1(ifp->name, ifp->ssid);
+ if (r != -1)
+ ifp->ssid_len = (unsigned int)r;
+ return r;
+}
+
/*
* FreeBSD allows for Virtual Access Points
* We need to check if the interface is a Virtual Interface Master
@@ -216,7 +229,7 @@ if_vimaster(const char *ifname)
if (ifmr.ifm_status & IFM_AVALID &&
IFM_TYPE(ifmr.ifm_active) == IFM_IEEE80211)
{
- if (if_getssid(ifname, NULL) == -1)
+ if (if_getssid1(ifname, NULL) == -1)
return 1;
}
return 0;