device_info.c File Reference

#include <stdio.h>
#include <stdarg.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.c:

Go to the source code of this file.

Data Structures

struct  device_info_config

Defines

#define PID_FILE   "/var/run/device_info.pid"
#define MAXLINE   100

Functions

void DEBUG (char *format,...)
int main (int argc, char *argv[])


Define Documentation

#define MAXLINE   100

Definition at line 48 of file device_info.c.

#define PID_FILE   "/var/run/device_info.pid"

Definition at line 47 of file device_info.c.

Referenced by main().


Function Documentation

void DEBUG ( char *  format,
  ... 
)

Definition at line 67 of file device_info.c.

Referenced by add_fa_host_route(), add_fa_spi(), at_home(), check_expired_agent_advs(), check_interfaces(), clean_agentadv(), clean_up(), close_for_home(), close_tunneling(), connected(), copy_str(), create_registration_socket(), degrade_current_fa_priority(), disconnect(), dyn_wireless_check_simulator(), dyn_wireless_create_socket(), dyn_wireless_get_ap_address(), dyn_wireless_get_channel(), dyn_wireless_get_name(), dyn_wireless_get_range(), dyn_wireless_get_simulator(), dyn_wireless_his_get(), dyn_wireless_his_set(), dyn_wireless_iwspy_get(), dyn_wireless_iwspy_set(), dyn_wireless_set_channel(), dyn_wireless_set_simulator(), find_agent(), get_fa_spi(), get_free_slot(), handle_api(), handle_icmp(), handle_registration(), handler_call_all(), handler_register(), handler_unregister(), handler_unregister_all(), init_pcap_for_advs(), init_tunneling(), main(), mn_handlers_init(), mn_init(), mn_parse_command_line(), mn_remove_dynamic_home_addr(), monitor_api_get_ch(), monitor_api_mon_conf(), monitor_api_set_ch(), monitor_get_dev(), monitor_poll_ap_addresses(), passive_find(), print_entries(), rec_add(), rec_add_long(), rec_add_qual(), rec_clean(), rec_clean_up(), rec_dump(), remove_fa_host_routes(), remove_fa_spi(), reply_waiting_api(), request_tunnel(), restart_tunneling(), send_gratuitous_arp(), send_registration(), start_tunneling(), stop_tunneling(), and update_fa_decaps_routes().

00068 {
00069         va_list ap;
00070 
00071         if (!debug)
00072                 return;
00073 
00074         va_start(ap, format);
00075         vfprintf(stdout, format, ap);
00076         fflush(stdout);
00077         va_end(ap);
00078 }

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

Definition at line 292 of file device_info.c.

References DEBUG(), optarg, and PID_FILE.

00293 {
00294         int s, foreground = 0, c, n;
00295 
00296         socket_path = default_socket_path;
00297         config_file_path = default_config_file_path;
00298         while (1) {
00299                 int option_index = 0;
00300                 static struct option long_options[] = {
00301                         {"fg", no_argument, NULL, 'f'},
00302                         {"debug", no_argument, NULL, 'd'},
00303                         {0, 0, 0, 0}
00304                 };
00305                 
00306                 c = getopt_long (argc, argv, "fdc:s:",
00307                                  long_options, &option_index);
00308                 if (c == -1)
00309                         break;
00310                 
00311                 switch (c) {
00312                 case 'f':
00313                         switch (option_index) {
00314                         case 0:
00315                                 fprintf(stderr,"Option: %s\n",
00316                                       long_options[option_index].name);
00317                                 foreground = 1;
00318                         }
00319                         break;
00320                 case 'c':
00321                         config_file_path = malloc(MAXPATHLEN);
00322                         if (config_file_path == NULL) {
00323                                 fprintf(stderr, "malloc for config: %s\n",
00324                                         strerror(errno));
00325                                 exit(1);
00326                         }
00327                         dynamics_strlcpy(config_file_path, optarg, MAXPATHLEN);
00328                         break;
00329                 case 's':
00330                         socket_path = malloc(MAXPATHLEN);
00331                         if (socket_path == NULL) {
00332                                 fprintf(stderr, "malloc for path: %s\n",
00333                                         strerror(errno));
00334                                 exit(1);
00335                         }
00336                         dynamics_strlcpy(socket_path, optarg, MAXPATHLEN);
00337                         break;
00338                 case 'd':
00339                         debug = 1;
00340                         break;
00341                 case '?':
00342                         fprintf(stderr, "device_info -c <configuration file> "
00343                                 "[-s <API socket>] [--fg]\n");
00344                         exit(1);
00345                 default:
00346                         fprintf(stderr, "?? getopt returned character code "
00347                                 "0%o ??\n", c);
00348                 }
00349         }
00350 
00351         parse_config(0);
00352         if (config == NULL) {
00353                 fprintf(stderr, "Configuration file parsing failed\n");
00354                 exit(1);
00355         }
00356 
00357         s = open_socket(socket_path);
00358         if (s < 0) {
00359                 fprintf(stderr, "Open socket failed\n");
00360                 exit(1);
00361         }
00362 
00363         DEBUG("Initializing mn admin socket path\n");
00364         c = dynamics_mn_init(NULL);
00365         if (c == API_FAILED || c == API_ERROR) {
00366                 fprintf(stderr, "MN admin socket path initialization "
00367                         "failed\n");
00368                 exit(1);
00369         }
00370         DEBUG("Registering device info socket path\n");
00371 
00372         if (dynamics_mn_register_dev_info_socket(socket_path, 3) 
00373             != API_SUCCESS) {
00374                 fprintf(stderr, "API device info socket initialization "
00375                         "failed\n");
00376                 exit(1);
00377         }
00378         DEBUG("\tregistered\n");
00379 
00380         if (!foreground && dynamics_fork_daemon() < 0) {
00381                 fprintf(stderr, "fork failed\n");
00382                 exit(1);
00383         }
00384         dynamics_write_pid_file(PID_FILE);
00385 
00386         signal(SIGHUP, parse_config);
00387         signal(SIGTERM, clean_up);
00388         signal(SIGINT, clean_up);
00389 
00390         for (;;) {
00391                 FD_ZERO(&set);
00392                 FD_SET(s, &set);
00393 
00394                 n = select(FD_SETSIZE, &set, NULL, NULL, NULL);
00395                 if (n < 0 && errno != EINTR)
00396                         fprintf(stderr, "select: %s\n",
00397                                 strerror(errno));
00398           
00399                 if (n == 1 && FD_ISSET(s, &set))
00400                         handle_request(s);
00401         }
00402 
00403         return 0;
00404 }

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