summaryrefslogtreecommitdiffstats
path: root/if-linux.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2009-01-01 20:51:04 +0000
committerRoy Marples <roy@marples.name>2009-01-01 20:51:04 +0000
commitc53cf4ef4b332cd1ff0cb1b0dc23fc193aebb892 (patch)
treebc4b3e699a9a40ecf7eb74249ca0c89f2ccb7f61 /if-linux.c
parent91a44b91b06f127a98ae7f64e377e59d47eba329 (diff)
downloaddhcpcd-c53cf4ef4b332cd1ff0cb1b0dc23fc193aebb892.tar.xz
You can now add a configure block per ssid if the interface is wireless.
Diffstat (limited to 'if-linux.c')
-rw-r--r--if-linux.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/if-linux.c b/if-linux.c
index c9cba9ef..937b4ad0 100644
--- a/if-linux.c
+++ b/if-linux.c
@@ -1,6 +1,6 @@
/*
* dhcpcd - DHCP client daemon
- * Copyright 2006-2008 Roy Marples <roy@marples.name>
+ * Copyright 2006-2009 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
@@ -36,6 +36,7 @@
#include <arpa/inet.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
+#include <linux/wireless.h>
#include <netinet/ether.h>
#include <netpacket/packet.h>
@@ -73,17 +74,22 @@ static void (*nl_add)(const char *);
static void (*nl_remove)(const char *);
int
-if_wireless(const char *ifname)
+getifssid(const char *ifname, char *ssid)
{
- int s, retval = -1;
- struct ifreq ifr;
+ int s, retval;
+ struct iwreq iwr;
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
- return retval;
- memset(&ifr, 0, sizeof(ifr));
- strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
- if (ioctl(s, SIOCGIWNAME, &ifr) == 0)
- retval = 0;
+ return -1;
+ memset(&iwr, 0, sizeof(iwr));
+ strlcpy(iwr.ifr_name, ifname, sizeof(iwr.ifr_name));
+ iwr.u.essid.pointer = ssid;
+ iwr.u.essid.length = IF_SSIDSIZE - 1;
+
+ if (ioctl(s, SIOCGIWESSID, &iwr) == 0)
+ retval = iwr.u.essid.length;
+ else
+ retval = -1;
close(s);
return retval;
}