]> git.decadent.org.uk Git - ap-utils.git/blobdiff - lib/common.c
Imported Upstream version 1.5
[ap-utils.git] / lib / common.c
index efcdb2b31a4e9ccb57e7849f8e70d1d410f86edc..a3df8a3a7472fc1e71c11854769f5ea0cea862a5 100644 (file)
@@ -2,6 +2,7 @@
  *      common.c from Access Point SNMP Utils for Linux
  *
  * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
+ * Copyright (c) 2005 Jan Rafaj <jr-aputils at cedric dot unob dot cz>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License Version 2 from
@@ -25,6 +26,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
+#include <sys/socket.h>
 #include "ap-utils.h"
 
 #define APIP _("Access Point IP-address: ")
@@ -35,6 +37,8 @@
 #define WANT_SYS_APLABEL _("Do you want to use AP's name as its label? ")
 #define APLABEL _("Access Point label: ")
 #define SAVESETTINGS _("Save connect-settings: ")
+#define POLL_I _("[P] Polling mode interval (tenths of second): ")
+#define POLL_HELP _("P - change polling mode interval; Q - quit to menu")
 
 char *ap_types[] = {
     "ATMEL410",
@@ -68,10 +72,11 @@ char *channels[] = {
 
 extern WINDOW *main_sub;
 extern char *community, *prog_title;
-short ap_type, ap_vendorext;
-extern int sockfd;
 extern struct in_addr ap_ip;
 
+short ap_type, ap_vendorext;
+int poll_delay = 10;
+
 void about()
 {
     int nrow = 14, ncol = 47, brow = (LINES - 5 - nrow) / 2, bcol =
@@ -140,7 +145,6 @@ void connect_options(unsigned long int ip, int type)
       {0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x01, 0x0A, 0x00}
     };
 
-    struct sockaddr_in client;
     extern int atmel410_filter; /* boolean; = 1 if we call from ap-gl utility */
     unsigned char message[256];
     unsigned char label[17];
@@ -149,22 +153,8 @@ void connect_options(unsigned long int ip, int type)
     char save_settings=1;
     varbind varbinds[1];
 
-    memset(&client, 0, sizeof client);
-    client.sin_family = AF_INET;
-    client.sin_port = INADDR_ANY;
-    client.sin_addr.s_addr = INADDR_ANY;
-
-    if (sockfd)
-       close(sockfd);
-
-    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
-       print_helperr(ERR_CREATING_SOCKET);
-       getch();
-       goto exit;
-    }
-
-    if (bind(sockfd, (struct sockaddr *) &client, SIZE) == -1) {
-       print_helperr(ERR_BINDING_SOCKET);
+    if (reopen_sockfd() == -1) {
+       print_helperr(ERR_SOCKET);
        getch();
        goto exit;
     }
@@ -320,6 +310,8 @@ get_all_again:
                    community, label, ap_type, ap_vendorext);
                write(fd, message, strlen(message));
                close(fd);
+               wbkgd(main_sub, A_NORMAL);
+               wrefresh(main_sub);
                print_help(DONE_WRITING_APCONF);
            } else
                print_helperr(ERR_WRITING_APCONF);
@@ -355,7 +347,7 @@ int get_mib_details()
     char AuthRadiusIP_ATMEL[] = {
        0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x03, 0x00
     };
-    /* ATMEL12350: GEMTEK and EZYNET MIBs define length 160, others 128 */
+    /* ATMEL12350: GEMTEK and EZYNET MIBs define length 160, others 92 or 128 */
     char sysDeviceInfo_ATMEL[] = {
        0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x01, 0x05, 0x00
     };
@@ -465,6 +457,8 @@ int get_mib_details()
 
 void exit_program()
 {
+    erase();
+    refresh();
     endwin();
     exit(0);
 }
@@ -478,6 +472,46 @@ void exit_shell()
     refresh();
 }
 
+/*
+ * Sets different-than-default (1 sec.) polling interval for polling-active
+ * modes, from interval <0.1;86400> seconds.
+ * poll_delay is natively in tenths of second.
+ */
+void polling_interval()
+{
+    unsigned char message[256];
+    int c = 0;
+
+    noecho();
+    print_help(POLL_HELP);
+
+    while (1) {
+       sprintf(message, _("%s%u"), POLL_I, poll_delay);
+       mvwaddstr(main_sub, 0, 0, message);
+       sprintf(message, _("(%0.1f seconds)"), (float) poll_delay / 10);
+       mvwaddstr(main_sub, 1, strlen(POLL_I), message);
+       wrefresh(main_sub);
+       c = getch();
+       switch (c) {
+           case 'P':
+           case 'p':
+               get_value(message, 0, strlen(POLL_I), 7, INT_STRING, 1, 864000,
+                   POLL_HELP);
+               poll_delay = atoi(message);
+               clear_main_new(0, 2);
+               break;
+           case 'Q':
+           case 'q':
+               goto quit;
+       }
+    }
+
+quit:
+    print_help("");
+    clear_main(0);
+    return;
+}
+
 /*
  * Expects regulatory domain code on input and returns index of a corresponding
  * regdom_types[] member, that describes the given regulatory domain properties.
@@ -492,4 +526,3 @@ int regdom_idx(char regdom)
 
     return i;
 }
-