histogram.c

Go to the documentation of this file.
00001 /* $Id: histogram.c,v 1.3 2000/04/06 07:26:52 jm Exp $
00002  * Dynamics signal quality history management module
00003  *
00004  * Dynamic hierarchial IP tunnel
00005  * Copyright (C) 1998-2000, Dynamics group
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License version 2 as
00009  * published by the Free Software Foundation. See README and COPYING for
00010  * more details.
00011  */
00012 
00013 #include <stdlib.h>
00014 #include <signal.h>
00015 #include <getopt.h>
00016 #include <unistd.h>
00017 #include <string.h>
00018 #include <asm/types.h>
00019 #include <sys/types.h>
00020 #include <sys/socket.h>
00021 #include <sys/ioctl.h>
00022 #include <sys/time.h>
00023 #include "owntypes.h"
00024 #include <linux/filter.h>
00025 #include <linux/wireless.h>
00026 #include "debug.h"
00027 #include "dyn_wireless.h"
00028 #include "agentadv.h"
00029 
00030 #define USAGE "histogram -d <device> {-s|-g}"
00031 #define DEBUG_FLAG '6'
00032 #define SETHIS 1
00033 #define GETHIS 2
00034 
00035 #ifndef IFNAMSIZ
00036 #define IFNAMSIZ 16
00037 #endif
00038 
00039 extern int opt_debug;
00040 int sock;
00041 char ifname[IFNAMSIZ];
00042 
00043 static struct option const long_options[] =
00044 {
00045         {"device", required_argument, NULL, 'd'},
00046         {"get-history", 0, NULL, 'g'},
00047         {"set-history", 0, NULL, 's'},
00048         {0, 0, 0, 0}
00049 };
00050 
00051 
00052 void clean_up(int dummy)
00053 {
00054         close(sock);
00055 }
00056 
00057 
00058 static int init_sockets(void)
00059 {
00060         __u32 filter = 0;
00061 
00062         filter = ICMP_FILTER_MN;
00063         sock = dyn_wireless_create_socket();
00064 
00065         if (sock < 0)
00066                 return 1;
00067         return 0;
00068 }
00069 
00070 
00071 int main(int argc, char **argv)
00072 {
00073         int ret = -1, c, oindex, command = -1, i, count = -1;
00074 #define RANGE_VALUES 16
00075         long history[RANGE_VALUES];
00076         char range[16];
00077         
00078         memset(history, 0, sizeof(history));
00079         memset(range, 0, sizeof(range));
00080         opt_debug = 1;
00081           
00082         /* parse arguments */
00083         while ((c = getopt_long(argc, argv, "d:sgc:", long_options, 
00084                                 &oindex)) != EOF) {
00085                 switch (c) {
00086                 case 's': /* set history */
00087                         DEBUG(DEBUG_FLAG, "option s (Set)\n");
00088                         if (command == GETHIS) {
00089                                 printf("Only one command at the time!\n");
00090                                 exit(1);
00091                         }
00092                         command = SETHIS;
00093                         break;
00094                 case 'g': /* get history */
00095                         DEBUG(DEBUG_FLAG, "option g (Get)\n");
00096                         if (command == SETHIS) {
00097                                 printf("Only one command at the time!\n");
00098                                 exit(1);
00099                         }
00100                         command = GETHIS;
00101                         break; 
00102                 case 'd': /* device */
00103                         DEBUG(DEBUG_FLAG, "option d (Device) with value"
00104                               " '%s'\n", optarg);
00105                         ret = dyn_wireless_get_ifname(optarg, ifname);
00106                         break;
00107                 default:
00108                         printf(USAGE);
00109                         return 1;
00110                 }
00111         }
00112 
00113         count = argc - optind;
00114         for (i = 0; optind < argc; optind++, i++) {
00115                 DEBUG(DEBUG_FLAG, "%d\n", (char)atoi(argv[optind]));
00116                 if (i >= 16) {
00117                         fprintf(stderr, "Only 16 first numbers are "
00118                                 "accepted for the range parameters\n");
00119                         exit(1);
00120                 }
00121                 range[i] = (char)atoi(argv[optind]);
00122         }
00123 
00124         /* interface given? */
00125         if (ret < 0) {
00126                 fprintf(stderr, "No device argument!\n");
00127                 printf(USAGE);
00128                 return 1;
00129         } 
00130 
00131         /* open sockets */
00132         if (init_sockets()) {
00133                 fprintf(stderr, "Open socket(s) failed\n");
00134                 return 3;
00135         }
00136 
00137         if (command == GETHIS) {
00138                 ret = dyn_wireless_his_get(sock, ifname, (char *)history);
00139                 for (i = 0; i < RANGE_VALUES; i++)
00140                         printf("%ld\n", history[i]);
00141         }
00142 
00143         if (command == SETHIS) {
00144                 DEBUG(DEBUG_FLAG, "==\n%d intervals [0..92]\n", count);
00145                 if (count < 0) {
00146                         fprintf(stderr, "You have to give ranges.\n");
00147                         clean_up(1);
00148                 }
00149                 ret = dyn_wireless_his_set(sock, ifname, range, sizeof(range));
00150         }
00151 
00152         if (ret != 0) {
00153                 printf("return value != 0\n");
00154         }
00155 
00156         clean_up(0);
00157         return 0;
00158 }

Generated on Tue Jan 15 08:50:43 2008 for Virtual foreign agent generator version 0.1 by  doxygen 1.5.1