aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_netinfo.c
diff options
context:
space:
mode:
authormichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2008-12-31 06:28:56 +0000
committermichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2008-12-31 06:28:56 +0000
commit9798fe8cbee8d9b26fdbd5167f2b46be574ec140 (patch)
tree769c8adc529b160959b4544ad93987209195cd81 /plugin_netinfo.c
parent509ea3a22fa798ad2f4b506bda5d6bd2eaa6e400 (diff)
downloadlcd4linux-9798fe8cbee8d9b26fdbd5167f2b46be574ec140.tar.gz
ported r838 from volker_dev
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@926 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to 'plugin_netinfo.c')
-rw-r--r--plugin_netinfo.c52
1 files changed, 34 insertions, 18 deletions
diff --git a/plugin_netinfo.c b/plugin_netinfo.c
index 371c9eb..c2af6fd 100644
--- a/plugin_netinfo.c
+++ b/plugin_netinfo.c
@@ -66,10 +66,10 @@ static int open_net(void)
if (socknr == -3)
return -1;
if (socknr == -2) {
- socknr = socket(PF_INET, SOCK_STREAM, 0);
+ socknr = socket(PF_INET, SOCK_DGRAM, 0);
}
if (socknr == -1) {
- error("%s: socket(PF_INET, SOCK_STREAM, 0) failed: %s", "plugin_netinfo", strerror(errno));
+ error("%s: socket(PF_INET, SOCK_DGRAM, 0) failed: %s", "plugin_netinfo", strerror(errno));
error(" deactivate plugin netinfo");
socknr = -3;
return -1;
@@ -81,33 +81,49 @@ static int open_net(void)
static void my_exists(RESULT * result, RESULT * arg1)
{
- static int errcount = 0;
- struct ifreq ifreq;
- double value = 1.0; // netdev exists
+ char buf[10240];
+ struct ifconf ifcnf;
+ struct ifreq *ifreq;
+ int len;
+ double value = 0.0; // netdev doesn't exists
+ char devname[80];
if (socknr < 0) {
/* no open socket */
- value = 0.0;
SetResult(&result, R_NUMBER, &value);
return;
}
- strncpy(ifreq.ifr_name, R2S(arg1), sizeof(ifreq.ifr_name));
- if (ioctl(socknr, SIOCGIFFLAGS, &ifreq) < 0) {
- if (errno == ENODEV) {
- /* device does not exists */
- value = 0.0;
- } else {
- errcount++;
- if (1 == errcount % 1000) {
- error("%s: ioctl(FLAGS %s) failed: %s", "plugin_netinfo", ifreq.ifr_name, strerror(errno));
- error(" (skip next 1000 errors)");
- }
+ ifcnf.ifc_len = sizeof(buf);
+ ifcnf.ifc_buf = buf;
+ if (ioctl(socknr, SIOCGIFCONF, &ifcnf) < 0) {
+ /* error getting list of devices */
+ error("%s: ioctl(IFCONF) for %s failed: %s", "plugin_netinfo", R2S(arg1), strerror(errno));
+ SetResult(&result, R_NUMBER, &value);
+ return;
+ }
+ if (0 == ifcnf.ifc_len) {
+ /* no interfaces found */
+ SetResult(&result, R_NUMBER, &value);
+ return;
+ }
+
+ ifreq = (struct ifreq *) buf;
+ len = sizeof(struct ifreq);
+ strncpy(devname, R2S(arg1), sizeof(devname));
+
+ while (ifreq && *((char *) ifreq) && ((char *) ifreq) < buf + ifcnf.ifc_len) {
+ if (*((char *) ifreq) && strncmp(ifreq->ifr_name, devname, sizeof(devname)) == 0) {
+ /* found */
+ value = 1.0;
+ SetResult(&result, R_NUMBER, &value);
return;
}
+
+ (*(char **) &ifreq) += len;
}
- /* device exists */
+ /* device doesn't exists */
SetResult(&result, R_NUMBER, &value);
}