device_info_query.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <getopt.h>
#include <unistd.h>
#include <signal.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <linux/if.h>
#include "util.h"
#include "dyn_mnlib.h"
#include "agentapi.h"
#include "fixed_fd_zero.h"
#include "device_info.h"
#include "dyn_ip.h"

Include dependency graph for device_info_query.c:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 117 of file device_info_query.c.

References device_info_query::device_index, ifname, IFNAMSIZ, optarg, prev(), and device_info_query::priority.

00118 {
00119         char *path = NULL;
00120         char *ifname = NULL;
00121         int c, s, r;
00122         struct device_info_query msg;
00123         struct idxmap *idx = NULL, *idxmap = NULL, *prev;
00124         struct sockaddr_un serv_addr;
00125 
00126         if (argc < 2) {
00127                 fprintf(stderr, usage);
00128                 exit(1);
00129         }
00130 
00131         while (1) {
00132                 int option_index = 0;
00133                 
00134                 c = getopt_long (argc, argv, "hd:p:", NULL, &option_index);
00135                 if (c == -1)
00136                         break;
00137                 
00138                 switch (c) {
00139                 case 'd':
00140                         ifname = malloc(IFNAMSIZ);
00141                         if (ifname == NULL) {
00142                                 fprintf(stderr, "malloc for device: %s\n",
00143                                         strerror(errno));
00144                                 exit(1);
00145                         }
00146                         memset(ifname, 0, IFNAMSIZ);
00147                         dynamics_strlcpy(ifname, optarg, IFNAMSIZ);
00148                         break;
00149                 case 'p':
00150                         path = malloc(MAXPATHLEN);
00151                         if (path == NULL) {
00152                                 fprintf(stderr, "malloc for path: %s\n",
00153                                         strerror(errno));
00154                                 exit(1);
00155                         }
00156                         memset(path, 0, MAXPATHLEN);
00157                         dynamics_strlcpy(path, optarg, MAXPATHLEN);
00158                         break;
00159                 case '?':
00160                 case 'h':
00161                         fprintf(stderr, usage);
00162                         exit(1);
00163                 default:
00164                         printf ("?? getopt returned character code "
00165                                 "0%o ??\n", c);
00166                 }
00167         }
00168 
00169         if (path == NULL)
00170                 path = default_path;
00171 
00172         if (ifname == NULL)
00173                 printf("Querying all interfaces\n");
00174 
00175         idxmap = dyn_ip_get_interface_map();
00176         idx = idxmap;
00177 
00178         s = open_socket();
00179         if (s < 0) {
00180                 fprintf(stderr, "socket open failed\n");
00181                 exit(1);
00182         }
00183 
00184         memset(&serv_addr, 0, sizeof(serv_addr));
00185         serv_addr.sun_family = AF_LOCAL;
00186         dynamics_strlcpy(serv_addr.sun_path, path,
00187                          sizeof(serv_addr.sun_path));
00188 
00189         while (idx != NULL) {
00190                 if (ifname != NULL && strncmp(idx->name, ifname, 
00191                                               sizeof(ifname))) {
00192                         idx = idx->next;
00193                         continue;
00194                 }
00195                 msg.device_index = idx->index;
00196                 msg.priority = -1;
00197                 r = send_query(s, serv_addr, path, &msg);
00198                 if (r == 0)
00199                         process_reply(s, &msg);
00200                 else {
00201                         fprintf(stderr, "send_query failed\n");
00202                         continue;
00203                 }
00204                 printf("interface %s:\n", idx->name);
00205                 if (msg.priority != -1)
00206                         printf("\tpriority %d\n", msg.priority);
00207                 idx = idx->next;
00208         }
00209 
00210         idx = idxmap;
00211         while (idx != NULL) {
00212                 prev = idx;
00213                 idx = idx->next;
00214                 free(prev);
00215         }
00216 
00217         close(s);
00218         return 0;
00219 }

Here is the call graph for this function:


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