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

📄 olsrd_conf.c

📁 wifi 无线网络路由协议OLSR linux下C代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * The olsr.org Optimized Link-State Routing daemon(olsrd) * Copyright (c) 2004, Andreas T鴑nesen(andreto@olsr.org) * All rights reserved. * * Redistribution and use in source and binary forms, with or without  * modification, are permitted provided that the following conditions  * are met: * * * Redistributions of source code must retain the above copyright  *   notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright  *   notice, this list of conditions and the following disclaimer in  *   the documentation and/or other materials provided with the  *   distribution. * * Neither the name of olsr.org, olsrd nor the names of its  *   contributors may be used to endorse or promote products derived  *   from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  * POSSIBILITY OF SUCH DAMAGE. * * Visit http://www.olsr.org for more information. * * If you find this software useful feel free to make a donation * to the project. For more information see the website or contact * the copyright holders. * * $Id: olsrd_conf.c,v 1.55 2007/09/13 16:08:13 bernd67 Exp $ */#include <stdio.h>#include <string.h>#include <errno.h>#include <stdlib.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include "olsrd_conf.h"extern FILE *yyin;extern int yyparse(void);static char copyright_string[] = "The olsr.org Optimized Link-State Routing daemon(olsrd) Copyright (c) 2004, Andreas T鴑nesen(andreto@olsr.org) All rights reserved.";#ifdef MAKEBIN/* Build as standalone binary */int main(int argc, char *argv[]){  struct olsrd_config *cnf;  if(argc == 1)    {      fprintf(stderr, "Usage: olsrd_cfgparser [filename] -print\n\n");      exit(EXIT_FAILURE);    }  if((cnf = olsrd_parse_cnf(argv[1])) != NULL)    {      if((argc > 2) && (!strcmp(argv[2], "-print")))	{	  olsrd_print_cnf(cnf);  	  olsrd_write_cnf(cnf, "./out.conf");	}      else        printf("Use -print to view parsed values\n");      printf("Configfile parsed OK\n");    }  else    {      printf("Failed parsing \"%s\"\n", argv[1]);    }  return 0;}#else/* Build as part of olsrd */#endifstruct olsrd_config *olsrd_parse_cnf(const char *filename){  struct olsr_if *in, *new_ifqueue, *in_tmp;  /* Stop the compiler from complaining */  (void)strlen(copyright_string);  cnf = malloc(sizeof(struct olsrd_config));  if (cnf == NULL)    {      fprintf(stderr, "Out of memory %s\n", __func__);      return NULL;    }  set_default_cnf(cnf);  printf("Parsing file: \"%s\"\n", filename);  yyin = fopen(filename, "r");    if (yyin == NULL)    {      fprintf(stderr, "Cannot open configuration file '%s': %s.\n",	      filename, strerror(errno));      free(cnf);      return NULL;    }  current_line = 1;  if (yyparse() != 0)    {      fclose(yyin);      olsrd_free_cnf(cnf);      return NULL;    }    fclose(yyin);  /* Reverse the queue (added by user request) */  in = cnf->interfaces;  new_ifqueue = NULL;  while(in)    {      in_tmp = in;       in = in->next;      in_tmp->next = new_ifqueue;      new_ifqueue = in_tmp;    }  cnf->interfaces = new_ifqueue;  in = cnf->interfaces;  while(in)    {      /* set various stuff */      in->configured = OLSR_FALSE;      in->interf = NULL;      in->host_emul = OLSR_FALSE;      in = in->next;    }  return cnf;}intolsrd_sanity_check_cnf(struct olsrd_config *cnf){  struct olsr_if           *in = cnf->interfaces;  struct if_config_options *io;  /* Debug level */  if(cnf->debug_level < MIN_DEBUGLVL ||     cnf->debug_level > MAX_DEBUGLVL)    {      fprintf(stderr, "Debuglevel %d is not allowed\n", cnf->debug_level);      return -1;    }  /* IP version */  if(cnf->ip_version != AF_INET &&     cnf->ip_version != AF_INET6)    {      fprintf(stderr, "Ipversion %d not allowed!\n", cnf->ip_version);      return -1;    }  /* TOS */  if(//cnf->tos < MIN_TOS ||     cnf->tos > MAX_TOS)    {      fprintf(stderr, "TOS %d is not allowed\n", cnf->tos);      return -1;    }  if(cnf->willingness_auto == OLSR_FALSE &&     (cnf->willingness > MAX_WILLINGNESS))    {      fprintf(stderr, "Willingness %d is not allowed\n", cnf->willingness);      return -1;    }  /* Hysteresis */  if(cnf->use_hysteresis == OLSR_TRUE)    {      if(cnf->hysteresis_param.scaling < MIN_HYST_PARAM ||	 cnf->hysteresis_param.scaling > MAX_HYST_PARAM)	{	  fprintf(stderr, "Hyst scaling %0.2f is not allowed\n", cnf->hysteresis_param.scaling);	  return -1;	}      if(cnf->hysteresis_param.thr_high <= cnf->hysteresis_param.thr_low)	{	  fprintf(stderr, "Hyst upper(%0.2f) thr must be bigger than lower(%0.2f) threshold!\n", cnf->hysteresis_param.thr_high, cnf->hysteresis_param.thr_low);	  return -1;	}      if(cnf->hysteresis_param.thr_high < MIN_HYST_PARAM ||	 cnf->hysteresis_param.thr_high > MAX_HYST_PARAM)	{	  fprintf(stderr, "Hyst upper thr %0.2f is not allowed\n", cnf->hysteresis_param.thr_high);	  return -1;	}      if(cnf->hysteresis_param.thr_low < MIN_HYST_PARAM ||	 cnf->hysteresis_param.thr_low > MAX_HYST_PARAM)	{	  fprintf(stderr, "Hyst lower thr %0.2f is not allowed\n", cnf->hysteresis_param.thr_low);	  return -1;	}    }  /* Pollrate */  if(cnf->pollrate < MIN_POLLRATE ||     cnf->pollrate > MAX_POLLRATE)    {      fprintf(stderr, "Pollrate %0.2f is not allowed\n", cnf->pollrate);      return -1;    }  /* NIC Changes Pollrate */  if(cnf->nic_chgs_pollrate < MIN_NICCHGPOLLRT ||     cnf->nic_chgs_pollrate > MAX_NICCHGPOLLRT)    {      fprintf(stderr, "NIC Changes Pollrate %0.2f is not allowed\n", cnf->nic_chgs_pollrate);      return -1;    }  /* TC redundancy */  if(//cnf->tc_redundancy < MIN_TC_REDUNDANCY ||     cnf->tc_redundancy > MAX_TC_REDUNDANCY)    {      fprintf(stderr, "TC redundancy %d is not allowed\n", cnf->tc_redundancy);      return -1;    }  /* MPR coverage */  if(cnf->mpr_coverage < MIN_MPR_COVERAGE ||     cnf->mpr_coverage > MAX_MPR_COVERAGE)    {      fprintf(stderr, "MPR coverage %d is not allowed\n", cnf->mpr_coverage);      return -1;    }  /* Link Q and hysteresis cannot be activated at the same time */  if(cnf->use_hysteresis == OLSR_TRUE && cnf->lq_level)    {      fprintf(stderr, "Hysteresis and LinkQuality cannot both be active! Deactivate one of them.\n");      return -1;    }  /* Link quality level */  if(cnf->lq_level > MAX_LQ_LEVEL)    {      fprintf(stderr, "LQ level %d is not allowed\n", cnf->lq_level);      return -1;    }  /* Link quality window size */  if(cnf->lq_level && (cnf->lq_wsize < MIN_LQ_WSIZE || cnf->lq_wsize > MAX_LQ_WSIZE))    {      fprintf(stderr, "LQ window size %d is not allowed\n", cnf->lq_wsize);      return -1;    }  if(in == NULL)    {      fprintf(stderr, "No interfaces configured!\n");      return -1;    }  /* Interfaces */  while(in)    {      io = in->cnf;      if(in->name == NULL || !strlen(in->name))	{	  fprintf(stderr, "Interface has no name!\n");	  return -1;	}      if(io == NULL)	{	  fprintf(stderr, "Interface %s has no configuration!\n", in->name);	  return -1;	}	      /* HELLO interval */      if (io->hello_params.validity_time < 0.0)      {        if (cnf->lq_level == 0)          io->hello_params.validity_time = NEIGHB_HOLD_TIME;        else          io->hello_params.validity_time = cnf->lq_wsize * io->hello_params.emission_interval;      }      if(io->hello_params.emission_interval < cnf->pollrate ||	 io->hello_params.emission_interval > io->hello_params.validity_time)	{	  fprintf(stderr, "Bad HELLO parameters! (em: %0.2f, vt: %0.2f)\n", io->hello_params.emission_interval, io->hello_params.validity_time);	  return -1;	}      /* TC interval */      if(io->tc_params.emission_interval < cnf->pollrate ||	 io->tc_params.emission_interval > io->tc_params.validity_time)	{	  fprintf(stderr, "Bad TC parameters! (em: %0.2f, vt: %0.2f)\n", io->tc_params.emission_interval, io->tc_params.validity_time);	  return -1;	}      /* MID interval */      if(io->mid_params.emission_interval < cnf->pollrate ||	 io->mid_params.emission_interval > io->mid_params.validity_time)	{	  fprintf(stderr, "Bad MID parameters! (em: %0.2f, vt: %0.2f)\n", io->mid_params.emission_interval, io->mid_params.validity_time);	  return -1;	}      /* HNA interval */      if(io->hna_params.emission_interval < cnf->pollrate ||	 io->hna_params.emission_interval > io->hna_params.validity_time)	{	  fprintf(stderr, "Bad HNA parameters! (em: %0.2f, vt: %0.2f)\n", io->hna_params.emission_interval, io->hna_params.validity_time);	  return -1;	}      in = in->next;    }  return 0;}voidolsrd_free_cnf(struct olsrd_config *cnf){

⌨️ 快捷键说明

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