[isf-wifidog] mac-address patch cry for help
Saul Albert
saul at twenteenthcentury.com
Lun 23 Mai 18:26:17 EDT 2005
Dear ilesansfil peeps
well after a long and frustrating battle, we are (at the moment) giving
up on nocatsplash and returning to wifidog, and the attempt we made to
patch it to do mac-address reporting.
I made a very silly attempt which failed completely, but Schuyler did
have a go too. Here's a patch which represents his best attempt.
If one of you who knows wifidog intimately could have a look at it - and
(wishes) see what you can do. Maybe this isn't too far off, and just
needs a nudge in the right direction.
voila patchfile:
thanks :)
Saul.
--
-- http://chinabone.lth.bclub.org.uk/~saul/
-------------- next part --------------
diff -Naur wifidog-1.1.1/src/conf.c wifidog-1.1.1-autoid/src/conf.c
--- wifidog-1.1.1/src/conf.c 2005-03-08 03:51:41.000000000 +0000
+++ wifidog-1.1.1-autoid/src/conf.c 2005-05-18 17:39:31.000000000 +0100
@@ -707,7 +707,8 @@
void
config_validate(void)
{
- config_notnull(config.gw_id, "GatewayID");
+ // this isn't necessary if we can take the gateway ID from the internal MAC address
+ // config_notnull(config.gw_id, "GatewayID");
config_notnull(config.gw_interface, "GatewayInterface");
config_notnull(config.auth_servers, "AuthServer");
diff -Naur wifidog-1.1.1/src/conf.h wifidog-1.1.1-autoid/src/conf.h
--- wifidog-1.1.1/src/conf.h 2004-11-22 21:45:57.000000000 +0000
+++ wifidog-1.1.1-autoid/src/conf.h 2005-05-18 20:22:10.000000000 +0100
@@ -29,11 +29,10 @@
/*@{*/
/** Defaults configuration values */
#define DEFAULT_CONFIGFILE "/etc/wifidog.conf"
#define DEFAULT_DAEMON 1
#define DEFAULT_DEBUGLEVEL LOG_INFO
#define DEFAULT_HTTPDMAXCONN 10
-#define DEFAULT_GATEWAYID "default"
+#define DEFAULT_GATEWAYID NULL
#define DEFAULT_GATEWAYPORT 2060
#define DEFAULT_HTTPDNAME "WiFiDog"
#define DEFAULT_CLIENTTIMEOUT 5
diff -Naur wifidog-1.1.1/src/gateway.c wifidog-1.1.1-autoid/src/gateway.c
--- wifidog-1.1.1/src/gateway.c 2005-03-12 22:16:38.000000000 +0000
+++ wifidog-1.1.1-autoid/src/gateway.c 2005-05-18 17:33:11.000000000 +0100
@@ -198,6 +198,16 @@
debug(LOG_DEBUG, "%s = %s", config->gw_interface, config->gw_address);
}
+ /* If we don't have the Gateway ID, construct it from the internal MAC address. Can't fail. */
+ if (!config->gw_id) {
+ debug(LOG_DEBUG, "Finding MAC address of %s", config->gw_interface);
+ if ((config->gw_id = get_iface_mac(config->gw_interface)) == NULL) {
+ debug(LOG_ERR, "Could not get MAC address information of %s, exiting...", config->gw_interface);
+ exit(1);
+ }
+ debug(LOG_DEBUG, "%s = %s", config->gw_interface, config->gw_id);
+ }
+
/* Initializes the web server */
debug(LOG_NOTICE, "Creating web server on %s:%d",
config->gw_address, config->gw_port);
diff -Naur wifidog-1.1.1/src/util.c wifidog-1.1.1-autoid/src/util.c
--- wifidog-1.1.1/src/util.c 2005-03-12 02:02:01.000000000 +0000
+++ wifidog-1.1.1-autoid/src/util.c 2005-05-18 17:42:07.000000000 +0100
@@ -172,6 +172,43 @@
#endif
}
+char *get_iface_mac (char *ifname) {
+#ifdef __linux__
+ int r, s;
+ struct ifreq ifr;
+ char *hwaddr, mac[13];
+
+ strcpy( ifr.ifr_name, ifname );
+
+ s = socket( PF_INET, SOCK_DGRAM, 0 );
+ if (s == -1) {
+ debug(LOG_ERR, "get_iface_mac socket: %s", strerror(errno));
+ return NULL;
+ }
+
+ r = ioctl( s, SIOCGIFHWADDR, &ifr );
+ if (r == -1) {
+ debug(LOG_ERR, "get_iface_mac ioctl(SIOCGIFHWADDR): %s", strerror(errno));
+ close(s);
+ return NULL;
+ }
+
+ hwaddr = ifr.ifr_hwaddr.sa_data;
+ snprintf( mac, 13, "%02X%02X%02X%02X%02X%02X",
+ hwaddr[0] & 0xFF,
+ hwaddr[1] & 0xFF,
+ hwaddr[2] & 0xFF,
+ hwaddr[3] & 0xFF,
+ hwaddr[4] & 0xFF,
+ hwaddr[5] & 0xFF);
+
+ close(s);
+ return safe_strdup(mac);
+#else
+ return NULL;
+#endif
+}
+
void mark_online() {
int before;
int after;
diff -Naur wifidog-1.1.1/src/util.h wifidog-1.1.1-autoid/src/util.h
--- wifidog-1.1.1/src/util.h 2005-03-12 02:02:02.000000000 +0000
+++ wifidog-1.1.1-autoid/src/util.h 2005-05-18 17:38:33.000000000 +0100
@@ -37,6 +37,10 @@
/* @brief Get IP address of an interface */
char *get_iface_ip(char *ifname);
+/* @brief Get MAC address of an interface */
+char *get_iface_mac(char *ifname);
+
+
/* @brief Sets hint that an online action (dns/connect/etc using WAN) succeeded */
void mark_online();
/* @brief Sets hint that an online action (dns/connect/etc using WAN) failed */
Plus d'informations sur la liste de diffusion WiFiDog