]> git.decadent.org.uk Git - ap-utils.git/blobdiff - src/ap-rrd.c
Imported Upstream version 1.5
[ap-utils.git] / src / ap-rrd.c
index 33b5463b507fe350f654f4bf8e058c11b9135923..9b15269636f813042028a7c96bca300e843956e4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *      ap-mrtg.c from Access Point SNMP Utils for Linux
+ *      ap-rrd.c from Access Point SNMP Utils for Linux
  *
  * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
  *
 #endif
 #include "ap-utils.h"
 
-#define ERR_STR_V "\n\n-\n\n"
-#define ERR_STR_N "999999999\n999999999\n-\n\n"
+#define ERR_STR _("Error getting data from AP %s\n")
 
 short ap_type = ATMEL410;
 char *community = NULL;
-int sockfd;
 struct in_addr ap_ip;
 
 void usage()
@@ -114,9 +112,7 @@ int main(int argc, char **argv)
     struct wirelessStatistics_s *WirelessStat = NULL;
     varbind varbinds[2];
     int i, reset_flag=0;
-    char message[12], bssid_flag,  stat_type = 0, *ERR_STR =
-       ERR_STR_N, *bssid = NULL, *name = NULL, *rrd_file = NULL, cmd[1024];
-    struct sockaddr_in client;
+    char message[12], bssid_flag,  stat_type = 0, *bssid = NULL, *name = NULL, *rrd_file = NULL, cmd[1024];
 
 #ifdef HAVE_GETTEXT
     setlocale(LC_ALL, "");
@@ -124,11 +120,6 @@ int main(int argc, char **argv)
     textdomain("ap-utils");
 #endif
 
-    memset(&client, 0, sizeof client);
-    client.sin_family = AF_INET;
-    client.sin_port = INADDR_ANY;
-    client.sin_addr.s_addr = INADDR_ANY;
-
     if (argc < 4) {
        usage();
        exit(0);
@@ -202,16 +193,6 @@ int main(int argc, char **argv)
        goto quit;
     }
 
-
-    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
-       perror(_("Create socket error"));
-       return 1;
-    }
-    if (bind(sockfd, (struct sockaddr *) &client, SIZE) == -1) {
-       perror(_("Bind socket error"));
-       return 1;
-    }
-
     switch (stat_type) {
 
     case 'e':
@@ -228,7 +209,7 @@ int main(int argc, char **argv)
        varbinds[1].type = NULL_VALUE;
 
        if (snmp(varbinds, 2, GET) <= 0) {
-           printf(ERR_STR);
+           printf(ERR_STR, inet_ntoa(ap_ip));
            return 1;
        }
 
@@ -240,7 +221,7 @@ int main(int argc, char **argv)
                                                       len_val);
            memcpy(EthRxStat, varbinds[0].value, varbinds[0].len_val);
        } else {
-           printf(ERR_STR);
+           printf(ERR_STR, inet_ntoa(ap_ip));
            return 1;
        }
 
@@ -252,7 +233,7 @@ int main(int argc, char **argv)
                                                       len_val);
            memcpy(EthTxStat, varbinds[1].value, varbinds[1].len_val);
        } else {
-           printf(ERR_STR);
+           printf(ERR_STR, inet_ntoa(ap_ip));
            return 1;
        }
        sprintf(cmd, "rrdtool update %s N:%u:%u", rrd_file, swap4(EthRxStat->TotalBytesRx), swap4(EthTxStat->TotalBytesTx));
@@ -270,7 +251,7 @@ int main(int argc, char **argv)
        varbinds[0].type = NULL_VALUE;
 
        if (snmp(varbinds, 1, GET) <= 0) {
-           printf(ERR_STR);
+           printf(ERR_STR, inet_ntoa(ap_ip));
            return 1;
        }
 
@@ -281,7 +262,7 @@ int main(int argc, char **argv)
                (struct wirelessStatistics_s *) malloc(varbinds[0].len_val);
            memcpy(WirelessStat, varbinds[0].value, varbinds[0].len_val);
        } else {
-           printf(ERR_STR);
+           printf(ERR_STR, inet_ntoa(ap_ip));
            return 1;
        }
        sprintf(cmd, "rrdtool update %s N:%u:%u", rrd_file,
@@ -302,7 +283,7 @@ int main(int argc, char **argv)
        varbinds[0].type = NULL_VALUE;
 
        if (snmp(varbinds, 1, GET) <= 0) {
-           printf(ERR_STR);
+           printf(ERR_STR, inet_ntoa(ap_ip));
            return 1;
        }
 
@@ -318,18 +299,18 @@ int main(int argc, char **argv)
        varbinds[0].type = NULL_VALUE;
 
        if (snmp(varbinds, 1, GET) <= 0) {
-           printf(ERR_STR);
+           printf(ERR_STR, inet_ntoa(ap_ip));
            return 1;
        }
 
        if (*(varbinds[0].value) != 3) {
-           printf(ERR_STR);
+           printf(ERR_STR, inet_ntoa(ap_ip));
            return 1;
        }
 
        if (reset_flag) {
                if (SysReset()) {
-                   printf(ERR_STR);
+                   printf(ERR_STR, inet_ntoa(ap_ip));
                    return 1;
                }
                sleep(10);
@@ -341,7 +322,7 @@ int main(int argc, char **argv)
        varbinds[0].len_val = 0;
 
        if (snmp(varbinds, 1, GET) <= 0) {
-           printf(ERR_STR);
+           printf(ERR_STR, inet_ntoa(ap_ip));
            return 1;
        }
        bssid_flag = 1;
@@ -366,7 +347,7 @@ int main(int argc, char **argv)
            break;
        }
        if (bssid_flag)
-           printf(ERR_STR);
+           printf(ERR_STR, inet_ntoa(ap_ip));
        break;
     default:
        usage();
@@ -396,8 +377,6 @@ int main(int argc, char **argv)
         printf("-\n");
     }
 */
-    close(sockfd);
-
     
   quit:
     if (community)
@@ -410,4 +389,3 @@ int main(int argc, char **argv)
        free(name);
     return 0;
 }
-