⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 wifi 无线网络路由协议OLSR linux下C代码
💻 C
📖 第 1 页 / 共 2 页
字号:
 */#ifndef WIN32voidolsr_reconfigure(int signal __attribute__((unused))){  if(!fork())    {      /* New process */      sleep(3);      printf("Restarting %s\n", olsr_argv[0]);      execv(olsr_argv[0], olsr_argv);    }  olsr_shutdown(0);  printf("RECONFIGURING!\n");}#endif/** *Function called at shutdown. Signal handler * * @param signal the signal that triggered this call */#ifdef WIN32int __stdcallSignalHandler(unsigned long signal)#elsestatic voidolsr_shutdown(int signal)#endif{  struct interface *ifn;  OLSR_PRINTF(1, "Received signal %d - shutting down\n", (int)signal);#ifdef WIN32  OLSR_PRINTF(1, "Waiting for the scheduler to stop.\n");  olsr_win32_end_request = TRUE;  while (!olsr_win32_end_flag)    Sleep(100);  OLSR_PRINTF(1, "Scheduler stopped.\n");#endif  olsr_delete_all_kernel_routes();  OLSR_PRINTF(1, "Closing sockets...\n");  /* front-end IPC socket */  if(olsr_cnf->open_ipc)    shutdown_ipc();  /* OLSR sockets */  for (ifn = ifnet; ifn; ifn = ifn->int_next)     close(ifn->olsr_socket);  /* Closing plug-ins */  olsr_close_plugins();  /* Reset network settings */  restore_settings(olsr_cnf->ip_version);  /* ioctl socket */  close(olsr_cnf->ioctl_s);#if LINUX_POLICY_ROUTING  close(olsr_cnf->rtnl_s);#endif#if defined __FreeBSD__ || defined __MacOSX__ || defined __NetBSD__ || defined __OpenBSD__  /* routing socket */  close(olsr_cnf->rts);#endif  olsr_syslog(OLSR_LOG_INFO, "%s stopped", olsrd_version);  OLSR_PRINTF(1, "\n <<<< %s - terminating >>>>\n           http://www.olsr.org\n", olsrd_version);  exit(olsr_cnf->exit_value);}/** * Print the command line usage */static voidprint_usage(void){  fprintf(stderr,          "An error occured somwhere between your keyboard and your chair!\n"          "usage: olsrd [-f <configfile>] [ -i interface1 interface2 ... ]\n"          "  [-d <debug_level>] [-ipv6] [-multi <IPv6 multicast address>]\n"          "  [-lql <LQ level>] [-lqw <LQ winsize>]\n"          "  [-bcast <broadcastaddr>] [-ipc] [-dispin] [-dispout] [-delgw]\n"          "  [-hint <hello interval (secs)>] [-tcint <tc interval (secs)>]\n"          "  [-midint <mid interval (secs)>] [-hnaint <hna interval (secs)>]\n"          "  [-T <Polling Rate (secs)>] [-nofork] [-hemu <ip_address>]\n"          "  [-lql <LQ level>] [-lqw <LQ winsize>]\n");}/** * Sets the provided configuration on all unconfigured * interfaces * * @param ifs a linked list of interfaces to check and possible update * @param cnf the default configuration to set on unconfigured interfaces */intset_default_ifcnfs(struct olsr_if *ifs, struct if_config_options *cnf){  int changes = 0;  while(ifs)    {      if(ifs->cnf == NULL)	{	  ifs->cnf = olsr_malloc(sizeof(struct if_config_options), "Set default config");	  *ifs->cnf = *cnf;	  changes++;	}      ifs = ifs->next;    }  return changes;}#define NEXT_ARG argv++;argc--#define CHECK_ARGC if(!argc) { \      if((argc - 1) == 1){ \      fprintf(stderr, "Error parsing command line options!\n"); \      olsr_exit(__func__, EXIT_FAILURE); \      } else { \      argv--; \      fprintf(stderr, "You must provide a parameter when using the %s switch!\n", *argv); \      olsr_exit(__func__, EXIT_FAILURE); \     } \     }/** * Process command line arguments passed to olsrd * */static intolsr_process_arguments(int argc, char *argv[], 		       struct olsrd_config *cnf, 		       struct if_config_options *ifcnf){  while (argc > 1)    {      NEXT_ARG;#ifdef WIN32      /*       *Interface list       */      if (strcmp(*argv, "-int") == 0)        {          ListInterfaces();          exit(0);        }#endif      /*       *Configfilename       */      if(strcmp(*argv, "-f") == 0) 	{	  fprintf(stderr, "Configfilename must ALWAYS be first argument!\n\n");	  olsr_exit(__func__, EXIT_FAILURE);	}      /*       *Use IP version 6       */      if(strcmp(*argv, "-ipv6") == 0) 	{	  cnf->ip_version = AF_INET6;	  continue;	}      /*       *Broadcast address       */      if(strcmp(*argv, "-bcast") == 0) 	{	  struct in_addr in;	  NEXT_ARG;          CHECK_ARGC;	  if (inet_aton(*argv, &in) == 0)	    {	      printf("Invalid broadcast address! %s\nSkipping it!\n", *argv);	      continue;	    }	  memcpy(&ifcnf->ipv4_broadcast.v4, &in.s_addr, sizeof(olsr_u32_t));  	  continue;	}      /*       * Set LQ level       */      if (strcmp(*argv, "-lql") == 0) 	{	  int tmp_lq_level;	  NEXT_ARG;          CHECK_ARGC;	  	  /* Sanity checking is done later */	  sscanf(*argv, "%d", &tmp_lq_level);	  olsr_cnf->lq_level = tmp_lq_level;	  continue;	}      /*       * Set LQ winsize       */      if (strcmp(*argv, "-lqw") == 0) 	{	  int tmp_lq_wsize;	  NEXT_ARG;          CHECK_ARGC;	  	  sscanf(*argv, "%d", &tmp_lq_wsize);	  if(tmp_lq_wsize < MIN_LQ_WSIZE || tmp_lq_wsize > MAX_LQ_WSIZE)	    {	      printf("LQ winsize %d not allowed. Range [%d-%d]\n", 		     tmp_lq_wsize, MIN_LQ_WSIZE, MAX_LQ_WSIZE);	      olsr_exit(__func__, EXIT_FAILURE);	    }	  olsr_cnf->lq_wsize = tmp_lq_wsize;	  continue;	}            /*       * Enable additional debugging information to be logged.       */      if (strcmp(*argv, "-d") == 0) 	{	  NEXT_ARG;          CHECK_ARGC;	  sscanf(*argv,"%d", &cnf->debug_level);	  continue;	}		      /*       * Interfaces to be used by olsrd.       */      if (strcmp(*argv, "-i") == 0) 	{	  NEXT_ARG;          CHECK_ARGC;	  if(*argv[0] == '-')	    {	      fprintf(stderr, "You must provide an interface label!\n");	      olsr_exit(__func__, EXIT_FAILURE);	    }	  printf("Queuing if %s\n", *argv);	  queue_if(*argv, OLSR_FALSE);	  while((argc - 1) && (argv[1][0] != '-'))	    {	      NEXT_ARG;	      printf("Queuing if %s\n", *argv);	      queue_if(*argv, OLSR_FALSE);	    }	  continue;	}      /*       * Set the hello interval to be used by olsrd.       *        */      if (strcmp(*argv, "-hint") == 0) 	{	  NEXT_ARG;          CHECK_ARGC;	  sscanf(*argv,"%f", &ifcnf->hello_params.emission_interval);          ifcnf->hello_params.validity_time = ifcnf->hello_params.emission_interval * 3;	  continue;	}      /*       * Set the HNA interval to be used by olsrd.       *        */      if (strcmp(*argv, "-hnaint") == 0) 	{	  NEXT_ARG;          CHECK_ARGC;	  sscanf(*argv,"%f", &ifcnf->hna_params.emission_interval);          ifcnf->hna_params.validity_time = ifcnf->hna_params.emission_interval * 3;	  continue;	}      /*       * Set the MID interval to be used by olsrd.       *        */      if (strcmp(*argv, "-midint") == 0) 	{	  NEXT_ARG;          CHECK_ARGC;	  sscanf(*argv,"%f", &ifcnf->mid_params.emission_interval);          ifcnf->mid_params.validity_time = ifcnf->mid_params.emission_interval * 3;	  continue;	}      /*       * Set the tc interval to be used by olsrd.       *        */      if (strcmp(*argv, "-tcint") == 0) 	{	  NEXT_ARG;          CHECK_ARGC;	  sscanf(*argv,"%f", &ifcnf->tc_params.emission_interval);          ifcnf->tc_params.validity_time = ifcnf->tc_params.emission_interval * 3;	  continue;	}      /*       * Set the polling interval to be used by olsrd.       */      if (strcmp(*argv, "-T") == 0) 	{	  NEXT_ARG;          CHECK_ARGC;	  sscanf(*argv,"%f",&cnf->pollrate);	  continue;	}      /*       * Should we display the contents of packages beeing sent?       */      if (strcmp(*argv, "-dispin") == 0) 	{	  parser_set_disp_pack_in(OLSR_TRUE);	  continue;	}      /*       * Should we display the contents of incoming packages?       */      if (strcmp(*argv, "-dispout") == 0) 	{	  net_set_disp_pack_out(OLSR_TRUE);	  continue;	}      /*       * Should we set up and send on a IPC socket for the front-end?       */      if (strcmp(*argv, "-ipc") == 0) 	{	  cnf->ipc_connections = 1;	  cnf->open_ipc = OLSR_TRUE;	  continue;	}      /*       * IPv6 multicast addr       */      if (strcmp(*argv, "-multi") == 0) 	{	  struct in6_addr in6;	  NEXT_ARG;          CHECK_ARGC;	  if(inet_pton(AF_INET6, *argv, &in6) <= 0)	    {	      fprintf(stderr, "Failed converting IP address %s\n", *argv);	      exit(EXIT_FAILURE);	    }	  memcpy(&ifcnf->ipv6_multi_glbl, &in6, sizeof(struct in6_addr));	  continue;	}      /*       * Host emulation       */      if (strcmp(*argv, "-hemu") == 0) 	{	  struct in_addr in;	  struct olsr_if *ifa;      	  NEXT_ARG;          CHECK_ARGC;	  if(inet_pton(AF_INET, *argv, &in) <= 0)	    {	      fprintf(stderr, "Failed converting IP address %s\n", *argv);	      exit(EXIT_FAILURE);	    }	  /* Add hemu interface */	  ifa = queue_if("hcif01", OLSR_TRUE);	  if(!ifa)	    continue;	  ifa->cnf = get_default_if_config();	  ifa->host_emul = OLSR_TRUE;	  memcpy(&ifa->hemu_ip, &in, sizeof(union olsr_ip_addr));	  cnf->host_emul = OLSR_TRUE;	  continue;	}      /*       * Delete possible default GWs       */      if (strcmp(*argv, "-delgw") == 0) 	{	  olsr_cnf->del_gws = OLSR_TRUE;	  continue;	}      if (strcmp(*argv, "-nofork") == 0) 	{	  cnf->no_fork = OLSR_TRUE;	  continue;	}      return -1;    }  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -