From 0eb707fdcf1b87e71bb3a9eaa8472d0b05799a3d Mon Sep 17 00:00:00 2001 From: Terry Dawson VK2KTJ Date: Wed, 12 Sep 2001 13:18:43 +0000 Subject: updated libtool, uniformly indented source, corrected small ax25mond Makefile bug --- ax25ipd/Makefile.in | 25 +- ax25ipd/ax25ipd.c | 190 ++++++------ ax25ipd/ax25ipd.h | 3 + ax25ipd/config.c | 325 +++++++++++--------- ax25ipd/crc.c | 141 ++++----- ax25ipd/io.c | 850 ++++++++++++++++++++++++++++++++-------------------- ax25ipd/kiss.c | 92 +++--- ax25ipd/process.c | 192 ++++++------ ax25ipd/routing.c | 164 +++++----- 9 files changed, 1129 insertions(+), 853 deletions(-) (limited to 'ax25ipd') diff --git a/ax25ipd/Makefile.in b/ax25ipd/Makefile.in index 513d44d..d2c6d30 100644 --- a/ax25ipd/Makefile.in +++ b/ax25ipd/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am +# Makefile.in generated automatically by automake 1.4-p4 from Makefile.am # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation @@ -64,15 +64,17 @@ AWK = @AWK@ AX25_LIB = @AX25_LIB@ CC = @CC@ DLLTOOL = @DLLTOOL@ -LD = @LD@ +ECHO = @ECHO@ +EXEEXT = @EXEEXT@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ NCURSES_LIB = @NCURSES_LIB@ -NM = @NM@ OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ RANLIB = @RANLIB@ +STRIP = @STRIP@ VERSION = @VERSION@ sbin_PROGRAMS = ax25ipd @@ -101,6 +103,7 @@ INCLUDES = -DAX25_SYSCONFDIR=\""$(AX25_SYSCONFDIR)"\" -DAX25_LOCALSTATEDIR=\ mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = ../config.h CONFIG_CLEAN_FILES = +sbin_PROGRAMS = ax25ipd$(EXEEXT) PROGRAMS = $(sbin_PROGRAMS) @@ -108,8 +111,8 @@ DEFS = @DEFS@ -I. -I$(srcdir) -I.. CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ -ax25ipd_OBJECTS = config.o crc.o io.o kiss.o ax25ipd.o process.o \ -routing.o +ax25ipd_OBJECTS = config.$(OBJEXT) crc.$(OBJEXT) io.$(OBJEXT) \ +kiss.$(OBJEXT) ax25ipd.$(OBJEXT) process.$(OBJEXT) routing.$(OBJEXT) ax25ipd_DEPENDENCIES = ax25ipd_LDFLAGS = COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -135,7 +138,7 @@ OBJECTS = $(ax25ipd_OBJECTS) all: all-redirect .SUFFIXES: -.SUFFIXES: .S .c .lo .o .s +.SUFFIXES: .S .c .lo .o .obj .s $(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps ax25ipd/Makefile @@ -172,6 +175,11 @@ uninstall-sbinPROGRAMS: .c.o: $(COMPILE) -c $< +# FIXME: We should only use cygpath when building on Windows, +# and only if it is available. +.c.obj: + $(COMPILE) -c `cygpath -w $<` + .s.o: $(COMPILE) -c $< @@ -180,6 +188,7 @@ uninstall-sbinPROGRAMS: mostlyclean-compile: -rm -f *.o core *.core + -rm -f *.$(OBJEXT) clean-compile: @@ -207,8 +216,8 @@ distclean-libtool: maintainer-clean-libtool: -ax25ipd: $(ax25ipd_OBJECTS) $(ax25ipd_DEPENDENCIES) - @rm -f ax25ipd +ax25ipd$(EXEEXT): $(ax25ipd_OBJECTS) $(ax25ipd_DEPENDENCIES) + @rm -f ax25ipd$(EXEEXT) $(LINK) $(ax25ipd_LDFLAGS) $(ax25ipd_OBJECTS) $(ax25ipd_LDADD) $(LIBS) install-man5: diff --git a/ax25ipd/ax25ipd.c b/ax25ipd/ax25ipd.c index e73f36b..45e59fa 100644 --- a/ax25ipd/ax25ipd.c +++ b/ax25ipd/ax25ipd.c @@ -33,16 +33,16 @@ int opt_help = 0; char opt_configfile[1024]; struct option options[] = { - "version", 0, &opt_version, 1, - "loglevel", 1, &opt_loglevel, 1, - "help", 0, &opt_help, 1, - "configfile", 1, NULL, 0, - 0,0,0,0 }; - -int -main(int argc, char **argv) + "version", 0, &opt_version, 1, + "loglevel", 1, &opt_loglevel, 1, + "help", 0, &opt_help, 1, + "configfile", 1, NULL, 0, + 0, 0, 0, 0 +}; + +int main(int argc, char **argv) { - if(setjmp(restart_env)==0) { + if (setjmp(restart_env) == 0) { signal(SIGHUP, hupper); } @@ -51,58 +51,65 @@ main(int argc, char **argv) signal(SIGINT, int_handler); signal(SIGTERM, term_handler); - while(1) { - int option_index = 0; - int c; - - c = getopt_long(argc, argv, "c:hl:v", options, &option_index); - if (c == -1) - break; - - switch (c) { - case 0: - break; - switch(option_index) { - case 0: case 2: - break; - case 1: - opt_loglevel = atoi(optarg); - break; - case 3: - strncpy(opt_configfile, optarg, 1023); - break; - - } - break; - case 'c' : - strncpy(opt_configfile, optarg, 1023); - break; - case 'v': - opt_version = 1; - break; - case 'l': - opt_loglevel = atoi(optarg); - break; - } - } - - if (optind < argc) { printf ("config %s\n", argv[optind++]); } - - if (opt_version == 1) { - greet_world(); - exit(0); - } - if (opt_help == 1) { - greet_world(); - printf ("Usage:\n"); - printf ("%s [flags]\n",argv[0]); - printf ("\nFlags:\n"); - printf (" --version, -v Print version of program\n"); - printf (" --help, -h This help screen\n"); - printf (" --loglevel NUM, -l NUM Set logging level to NUM\n"); - printf (" --configfile FILE, -c FILE Set confgiuration file to FILE\n"); - exit(0); - } + while (1) { + int option_index = 0; + int c; + + c = getopt_long(argc, argv, "c:hl:v", options, + &option_index); + if (c == -1) + break; + + switch (c) { + case 0: + break; + switch (option_index) { + case 0: + case 2: + break; + case 1: + opt_loglevel = atoi(optarg); + break; + case 3: + strncpy(opt_configfile, optarg, 1023); + break; + + } + break; + case 'c': + strncpy(opt_configfile, optarg, 1023); + break; + case 'v': + opt_version = 1; + break; + case 'l': + opt_loglevel = atoi(optarg); + break; + } + } + + if (optind < argc) { + printf("config %s\n", argv[optind++]); + } + + if (opt_version == 1) { + greet_world(); + exit(0); + } + if (opt_help == 1) { + greet_world(); + printf("Usage:\n"); + printf("%s [flags]\n", argv[0]); + printf("\nFlags:\n"); + printf + (" --version, -v Print version of program\n"); + printf(" --help, -h This help screen\n"); + printf + (" --loglevel NUM, -l NUM Set logging level to NUM\n"); + printf + (" --configfile FILE, -c FILE Set confgiuration file to FILE\n"); + exit(0); + } /* Initialize all routines */ config_init(); @@ -131,21 +138,21 @@ main(int argc, char **argv) /* and let the games begin */ io_start(); - return(0); + return (0); } -void -greet_world() +void greet_world() { printf("\nax25ipd %s / %s\n", VERS2, VERSION); - printf("Copyright 1991, Michael Westerhof, Sun Microsystems, Inc.\n"); - printf("This software may be freely used, distributed, or modified, providing\nthis header is not removed\n\n"); + printf + ("Copyright 1991, Michael Westerhof, Sun Microsystems, Inc.\n"); + printf + ("This software may be freely used, distributed, or modified, providing\nthis header is not removed\n\n"); fflush(stdout); } -void -do_stats() +void do_stats() { int save_loglevel; @@ -162,24 +169,24 @@ do_stats() dump_params(); printf("\nInput stats:\n"); - printf("KISS input packets: %d\n",stats.kiss_in); - printf(" too big: %d\n",stats.kiss_toobig); - printf(" bad type: %d\n",stats.kiss_badtype); - printf(" too short: %d\n",stats.kiss_tooshort); - printf(" not for me: %d\n",stats.kiss_not_for_me); - printf(" I am destination: %d\n",stats.kiss_i_am_dest); - printf(" no route found: %d\n",stats.kiss_no_ip_addr); - printf("UDP input packets: %d\n",stats.udp_in); - printf("IP input packets: %d\n",stats.ip_in); - printf(" failed CRC test: %d\n",stats.ip_failed_crc); - printf(" too short: %d\n",stats.ip_tooshort); - printf(" not for me: %d\n",stats.ip_not_for_me); - printf(" I am destination: %d\n",stats.ip_i_am_dest); + printf("KISS input packets: %d\n", stats.kiss_in); + printf(" too big: %d\n", stats.kiss_toobig); + printf(" bad type: %d\n", stats.kiss_badtype); + printf(" too short: %d\n", stats.kiss_tooshort); + printf(" not for me: %d\n", stats.kiss_not_for_me); + printf(" I am destination: %d\n", stats.kiss_i_am_dest); + printf(" no route found: %d\n", stats.kiss_no_ip_addr); + printf("UDP input packets: %d\n", stats.udp_in); + printf("IP input packets: %d\n", stats.ip_in); + printf(" failed CRC test: %d\n", stats.ip_failed_crc); + printf(" too short: %d\n", stats.ip_tooshort); + printf(" not for me: %d\n", stats.ip_not_for_me); + printf(" I am destination: %d\n", stats.ip_i_am_dest); printf("\nOutput stats:\n"); - printf("KISS output packets: %d\n",stats.kiss_out); - printf(" beacons: %d\n",stats.kiss_beacon_outs); - printf("UDP output packets: %d\n",stats.udp_out); - printf("IP output packets: %d\n",stats.ip_out); + printf("KISS output packets: %d\n", stats.kiss_out); + printf(" beacons: %d\n", stats.kiss_beacon_outs); + printf("UDP output packets: %d\n", stats.udp_out); + printf("IP output packets: %d\n", stats.ip_out); printf("\n"); fflush(stdout); @@ -188,33 +195,28 @@ do_stats() loglevel = save_loglevel; } -void -hupper(int i) +void hupper(int i) { printf("\nSIGHUP!\n"); longjmp(restart_env, 1); } -void -usr1_handler(int i) +void usr1_handler(int i) { printf("\nSIGUSR1!\n"); do_stats(); } -void -int_handler(int i) +void int_handler(int i) { printf("\nSIGINT!\n"); do_stats(); exit(1); } -void -term_handler(int i) +void term_handler(int i) { printf("\nSIGTERM!\n"); do_stats(); exit(1); } - diff --git a/ax25ipd/ax25ipd.h b/ax25ipd/ax25ipd.h index eeaf183..76a25b6 100644 --- a/ax25ipd/ax25ipd.h +++ b/ax25ipd/ax25ipd.h @@ -20,6 +20,9 @@ * added route flags, it's a little ugly, but is extensible fairly easily. * provided a mechanism for handling broadcast traffic * Terry Dawson, VK2KTJ, July 1997. + * + * Minor bug fixes. + * Terry Dawson, VK2KTJ, September 2001. */ /* Define the current version number diff --git a/ax25ipd/config.c b/ax25ipd/config.c index 243b82c..b80d113 100644 --- a/ax25ipd/config.c +++ b/ax25ipd/config.c @@ -23,21 +23,24 @@ #include "ax25ipd.h" /* Initialize the config table */ -void -config_init() +void config_init() { int i; *ttydevice = '\0'; - for(i=0;i<7;i++)mycallsign[i]='\0'; - for(i=0;i<7;i++)myalias[i]='\0'; - for(i=0;i<7;i++)mycallsign2[i]='\0'; - for(i=0;i<7;i++)myalias2[i]='\0'; + for (i = 0; i < 7; i++) + mycallsign[i] = '\0'; + for (i = 0; i < 7; i++) + myalias[i] = '\0'; + for (i = 0; i < 7; i++) + mycallsign2[i] = '\0'; + for (i = 0; i < 7; i++) + myalias2[i] = '\0'; digi = 1; ttyspeed = 9600; loglevel = 0; bc_interval = 0; - bc_text[0]='\0'; + bc_text[0] = '\0'; bc_every = 0; my_udp = htons(0); udp_mode = 0; @@ -65,8 +68,7 @@ config_init() /* Open and read the config file */ -void -config_read(f) +void config_read(f) char *f; { FILE *cf; @@ -74,252 +76,287 @@ char *f; int errflag, e, lineno; char *fname; - if (f) fname = f; - else fname = CONF_AX25IPD_FILE; + if (f) + fname = f; + else + fname = CONF_AX25IPD_FILE; - if((cf = fopen(fname,"r"))==NULL) { - fprintf(stderr,"Config file %s not found or could not be opened\n",fname); + if ((cf = fopen(fname, "r")) == NULL) { + fprintf(stderr, + "Config file %s not found or could not be opened\n", + fname); exit(1); } errflag = 0; lineno = 0; - while(fgets(buf, 255, cf)!=NULL) { + while (fgets(buf, 255, cf) != NULL) { strcpy(cbuf, buf); lineno++; - if((e = parse_line(buf)) < 0) { - fprintf(stderr,"Config error at line %d: ",lineno); - if(e==-1)fprintf(stderr,"Missing argument\n"); - else if(e==-2)fprintf(stderr,"Bad callsign format\n"); - else if(e==-3)fprintf(stderr,"Bad option - on/off\n"); - else if(e==-4)fprintf(stderr,"Bad option - tnc/digi\n"); - else if(e==-5)fprintf(stderr,"Host not known\n"); - else if(e==-6)fprintf(stderr,"Unknown command\n"); - else if(e==-7)fprintf(stderr,"Text string too long\n"); - else if(e==-8)fprintf(stderr,"Bad option - every/after\n"); - else if(e==-9)fprintf(stderr,"Bad option - ip/udp\n"); - else fprintf(stderr,"Unknown error\n"); - fprintf(stderr,"%s",cbuf); + if ((e = parse_line(buf)) < 0) { + fprintf(stderr, "Config error at line %d: ", + lineno); + if (e == -1) + fprintf(stderr, "Missing argument\n"); + else if (e == -2) + fprintf(stderr, "Bad callsign format\n"); + else if (e == -3) + fprintf(stderr, "Bad option - on/off\n"); + else if (e == -4) + fprintf(stderr, "Bad option - tnc/digi\n"); + else if (e == -5) + fprintf(stderr, "Host not known\n"); + else if (e == -6) + fprintf(stderr, "Unknown command\n"); + else if (e == -7) + fprintf(stderr, "Text string too long\n"); + else if (e == -8) + fprintf(stderr, + "Bad option - every/after\n"); + else if (e == -9) + fprintf(stderr, "Bad option - ip/udp\n"); + else + fprintf(stderr, "Unknown error\n"); + fprintf(stderr, "%s", cbuf); errflag++; } } - if(errflag)exit(1); + if (errflag) + exit(1); - if(strlen(ttydevice)==0) { - fprintf(stderr,"No device specified in config file\n"); + if (strlen(ttydevice) == 0) { + fprintf(stderr, "No device specified in config file\n"); exit(1); } - if((udp_mode == 0) && (ip_mode == 0)) { - fprintf(stderr,"Must specify ip and/or udp sockets\n"); + if ((udp_mode == 0) && (ip_mode == 0)) { + fprintf(stderr, "Must specify ip and/or udp sockets\n"); exit(1); } - if(digi) { - if(mycallsign[0]=='\0') { - fprintf(stderr,"No mycall line in config file\n"); + if (digi) { + if (mycallsign[0] == '\0') { + fprintf(stderr, "No mycall line in config file\n"); exit(1); } } - if((digi) && (dual_port)) { - if(mycallsign2[0]=='\0') { - fprintf(stderr,"No mycall2 line in config file\n"); + if ((digi) && (dual_port)) { + if (mycallsign2[0] == '\0') { + fprintf(stderr, + "No mycall2 line in config file\n"); exit(1); } } } /* Process each line from the config file. The return value is encoded. */ -int -parse_line(buf) +int parse_line(buf) char *buf; { char *p, *q; unsigned char tcall[7], tip[4]; struct hostent *he; - int i,j, uport; + int i, j, uport; unsigned int flags; p = strtok(buf, " \t\n\r"); - if(p==NULL)return 0; - if(*p=='#')return 0; + if (p == NULL) + return 0; + if (*p == '#') + return 0; - if(strcmp(p,"mycall")==0) { + if (strcmp(p, "mycall") == 0) { q = strtok(NULL, " \t\n\r"); - if(q==NULL)return -1; - if(a_to_call(q, mycallsign)!=0)return -2; + if (q == NULL) + return -1; + if (a_to_call(q, mycallsign) != 0) + return -2; return 0; - } else if(strcmp(p,"mycall2")==0) { + } else if (strcmp(p, "mycall2") == 0) { q = strtok(NULL, " \t\n\r"); - if(q==NULL)return -1; - if(a_to_call(q, mycallsign2)!=0)return -2; + if (q == NULL) + return -1; + if (a_to_call(q, mycallsign2) != 0) + return -2; return 0; - } else if(strcmp(p,"myalias")==0) { + } else if (strcmp(p, "myalias") == 0) { q = strtok(NULL, " \t\n\r"); - if(q==NULL)return -1; - if(a_to_call(q, myalias)!=0)return -2; + if (q == NULL) + return -1; + if (a_to_call(q, myalias) != 0) + return -2; dual_port = 1; - if(mycallsign2[0]=='\0') { - dual_port = 0; + if (mycallsign2[0] == '\0') { + dual_port = 0; } return 0; - } else if(strcmp(p,"myalias2")==0) { + } else if (strcmp(p, "myalias2") == 0) { q = strtok(NULL, " \t\n\r"); - if(q==NULL)return -1; - if(a_to_call(q, myalias2)!=0)return -2; + if (q == NULL) + return -1; + if (a_to_call(q, myalias2) != 0) + return -2; return 0; - } else if(strcmp(p,"device")==0) { + } else if (strcmp(p, "device") == 0) { q = strtok(NULL, " \t\n\r"); - if(q==NULL)return -1; + if (q == NULL) + return -1; strcpy(ttydevice, q); return 0; - } else if(strcmp(p,"mode")==0) { + } else if (strcmp(p, "mode") == 0) { q = strtok(NULL, " \t\n\r"); - if(q==NULL)return -1; - if(strcmp(q,"digi")==0) digi = 1; - else if(strcmp(q,"tnc")==0) digi = 0; - else return -4; + if (q == NULL) + return -1; + if (strcmp(q, "digi") == 0) + digi = 1; + else if (strcmp(q, "tnc") == 0) + digi = 0; + else + return -4; return 0; - } else if(strcmp(p,"speed")==0) { + } else if (strcmp(p, "speed") == 0) { q = strtok(NULL, " \t\n\r"); - if(q==NULL)return -1; + if (q == NULL) + return -1; ttyspeed = atoi(q); return 0; - } else if(strcmp(p,"socket")==0) { + } else if (strcmp(p, "socket") == 0) { q = strtok(NULL, " \t\n\r"); - if (q==NULL) + if (q == NULL) return -1; - if (strcmp(q,"ip")==0) { + if (strcmp(q, "ip") == 0) { ip_mode = 1; - } - else if(strcmp(q,"udp")==0) { + } else if (strcmp(q, "udp") == 0) { udp_mode = 1; my_udp = htons(DEFAULT_UDP_PORT); q = strtok(NULL, " \t\n\r"); - if (q!=NULL) { + if (q != NULL) { i = atoi(q); - if (i>0) + if (i > 0) my_udp = htons(i); } - } - else + } else return -9; return 0; - } else if(strcmp(p,"beacon")==0) { + } else if (strcmp(p, "beacon") == 0) { q = strtok(NULL, " \t\n\r"); - if (q==NULL) + if (q == NULL) return -1; - if (strcmp(q,"every")==0) + if (strcmp(q, "every") == 0) bc_every = 1; - else if (strcmp(q,"after")==0) + else if (strcmp(q, "after") == 0) bc_every = 0; else return -8; q = strtok(NULL, " \t\n\r"); - if (q==NULL) + if (q == NULL) return -1; bc_interval = atoi(q); return 0; /* This next one is a hack!!!!!! watch out!!!! */ - } else if(strcmp(p,"btext")==0) { + } else if (strcmp(p, "btext") == 0) { q = p + strlen(p) + 1; - if(strlen(q) < 2) return -1; /* line ends with a \n */ - if(strlen(q) > sizeof bc_text)return -7; - q[strlen(q)-1]='\0'; + if (strlen(q) < 2) + return -1; /* line ends with a \n */ + if (strlen(q) > sizeof bc_text) + return -7; + q[strlen(q) - 1] = '\0'; strcpy(bc_text, q); return 0; - } else if(strcmp(p,"loglevel")==0) { + } else if (strcmp(p, "loglevel") == 0) { q = strtok(NULL, " \t\n\r"); - if(q==NULL)return -1; + if (q == NULL) + return -1; loglevel = atoi(q); return 0; - } else if(strcmp(p,"route")==0) { + } else if (strcmp(p, "route") == 0) { uport = 0; flags = 0; q = strtok(NULL, " \t\n\r"); - if(q==NULL) + if (q == NULL) return -1; - if(a_to_call(q, tcall)!=0) + if (a_to_call(q, tcall) != 0) return -2; q = strtok(NULL, " \t\n\r"); - if(q==NULL) + if (q == NULL) return -1; he = gethostbyname(q); - if(he!=NULL) { + if (he != NULL) { memcpy(tip, he->h_addr_list[0], 4); - } else { /* maybe user specified a numeric addr? */ + } else { /* maybe user specified a numeric addr? */ j = inet_addr(q); - if(j==-1) - return -5; /* if -1, bad deal! */ - memcpy(tip, (char *)&j, 4); + if (j == -1) + return -5; /* if -1, bad deal! */ + memcpy(tip, (char *) &j, 4); } - while((q = strtok(NULL, " \t\n\r"))!=NULL) { - if(strcmp(q,"udp")==0) { + while ((q = strtok(NULL, " \t\n\r")) != NULL) { + if (strcmp(q, "udp") == 0) { uport = DEFAULT_UDP_PORT; q = strtok(NULL, " \t\n\r"); - if(q!=NULL) { + if (q != NULL) { i = atoi(q); - if(i>0) + if (i > 0) uport = i; } } else { /* Test for broadcast flag */ - if (strchr(q,'b')) { - flags|=AXRT_BCAST; + if (strchr(q, 'b')) { + flags |= AXRT_BCAST; } /* Test for Default flag */ - if (strchr(q,'d')) { - flags|=AXRT_DEFAULT; + if (strchr(q, 'd')) { + flags |= AXRT_DEFAULT; } } } route_add(tip, tcall, uport, flags); return 0; - } else if(strcmp(p,"broadcast")==0) { + } else if (strcmp(p, "broadcast") == 0) { - while ((q = strtok(NULL, " \t\n\r"))!=NULL) { - if (a_to_call(q, tcall)!=0) + while ((q = strtok(NULL, " \t\n\r")) != NULL) { + if (a_to_call(q, tcall) != 0) return -2; bcast_add(tcall); } return 0; - } else if(strcmp(p,"param")==0) { + } else if (strcmp(p, "param") == 0) { q = strtok(NULL, " \t\n\r"); - if(q==NULL)return -1; + if (q == NULL) + return -1; i = atoi(q); q = strtok(NULL, " \t\n\r"); - if(q==NULL)return -1; + if (q == NULL) + return -1; j = atoi(q); - param_add(i,j); + param_add(i, j); return 0; } return -999; } /* Convert ascii callsign to internal format */ -int -a_to_call(text, tcall) +int a_to_call(text, tcall) char *text; unsigned char *tcall; { @@ -327,32 +364,35 @@ unsigned char *tcall; int ssid; unsigned char c; - if(strlen(text)==0)return -1; + if (strlen(text) == 0) + return -1; ssid = 0; - for(i=0;i<6;i++) { - tcall[i]=(' '<<1); + for (i = 0; i < 6; i++) { + tcall[i] = (' ' << 1); } tcall[6] = '\0'; - for(i=0;i15)return -1; - tcall[6] = (ssid<<1); + if (c == '-') { + ssid = atoi(&text[i + 1]); + if (ssid > 15) + return -1; + tcall[6] = (ssid << 1); return 0; } - if(islower(c))c = toupper(c); - if(i>5)return -1; - tcall[i]=(c<<1); + if (islower(c)) + c = toupper(c); + if (i > 5) + return -1; + tcall[i] = (c << 1); } return 0; } /* Convert internal callsign to printable format */ -char * -call_to_a(tcall) +char *call_to_a(tcall) unsigned char *tcall; { int i; @@ -360,17 +400,18 @@ unsigned char *tcall; char *tptr; static char t[10]; - for(i=0,tptr=t;i<6;i++) { - if(tcall[i]==(' '<<1))break; - *tptr = tcall[i]>>1; + for (i = 0, tptr = t; i < 6; i++) { + if (tcall[i] == (' ' << 1)) + break; + *tptr = tcall[i] >> 1; tptr++; } - ssid = (tcall[6]>>1)&0x0f; - if(ssid>0) { + ssid = (tcall[6] >> 1) & 0x0f; + if (ssid > 0) { *tptr = '-'; tptr++; - if(ssid>9) { + if (ssid > 9) { *tptr = '1'; tptr++; ssid -= 10; @@ -384,21 +425,25 @@ unsigned char *tcall; } /* print the configuration data out */ -void -dump_config() +void dump_config() { LOGL1("\nCurrent configuration:\n"); - if(ip_mode) LOGL1(" socket ip\n"); - if(udp_mode)LOGL1(" socket udp on port %d\n", ntohs(my_udp)); + if (ip_mode) + LOGL1(" socket ip\n"); + if (udp_mode) + LOGL1(" socket udp on port %d\n", ntohs(my_udp)); LOGL1(" mode %s\n", digi ? "digi" : "tnc"); LOGL1(" device %s\n", ttydevice); LOGL1(" speed %d\n", ttyspeed); - if(digi)LOGL1(" mycall %s\n", call_to_a(mycallsign)); - if(digi && myalias[0])LOGL1(" myalias %s\n", call_to_a(myalias)); - if(bc_interval>0) { - LOGL1(" beacon %s %d\n", bc_every ? "every" : "after", bc_interval); + if (digi) + LOGL1(" mycall %s\n", call_to_a(mycallsign)); + if (digi && myalias[0]) + LOGL1(" myalias %s\n", call_to_a(myalias)); + if (bc_interval > 0) { + LOGL1(" beacon %s %d\n", bc_every ? "every" : "after", + bc_interval); LOGL1(" btext %s\n", bc_text); } LOGL1(" loglevel %d\n", loglevel); - (void)fflush(stdout); + (void) fflush(stdout); } diff --git a/ax25ipd/crc.c b/ax25ipd/crc.c index ff07195..f6fc565 100644 --- a/ax25ipd/crc.c +++ b/ax25ipd/crc.c @@ -30,57 +30,57 @@ typedef unsigned short u16; * FCS lookup table as calculated by the table generator in section 2. */ static u16 fcstab[256] = { - 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, - 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, - 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, - 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, - 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, - 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, - 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, - 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, - 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, - 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, - 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, - 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, - 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, - 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, - 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, - 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, - 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, - 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, - 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, - 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, - 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, - 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, - 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, - 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, - 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, - 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, - 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, - 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, - 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, - 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, - 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, - 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 + 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, + 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, + 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, + 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, + 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, + 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, + 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, + 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, + 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, + 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, + 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, + 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, + 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, + 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, + 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, + 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, + 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, + 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, + 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, + 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, + 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, + 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, + 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, + 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, + 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, + 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, + 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, + 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, + 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, + 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, + 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, + 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 }; -#define PPPINITFCS 0xffff /* Initial FCS value */ -#define PPPGOODFCS 0xf0b8 /* Good final FCS value */ +#define PPPINITFCS 0xffff /* Initial FCS value */ +#define PPPGOODFCS 0xf0b8 /* Good final FCS value */ /* * Calculate a new fcs given the current fcs and the new data. */ u16 pppfcs(fcs, cp, len) - register u16 fcs; - register unsigned char *cp; - register int len; +register u16 fcs; +register unsigned char *cp; +register int len; { /* ASSERT(sizeof (u16) == 2); */ /* ASSERT(((u16) -1) > 0); */ - while (len--) - fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff]; + while (len--) + fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff]; - return (fcs); + return (fcs); } /* @@ -94,8 +94,7 @@ u16 pppfcs(fcs, cp, len) */ /* Return the computed CRC */ -unsigned short int -compute_crc(buf, l) +unsigned short int compute_crc(buf, l) unsigned char *buf; int l; { @@ -108,8 +107,7 @@ int l; } /* Return true if the CRC is correct */ -int -ok_crc(buf, l) +int ok_crc(buf, l) unsigned char *buf; int l; { @@ -127,45 +125,52 @@ int l; */ #ifdef TEST -void -main() +void main() { unsigned char buf[258]; int l, i; unsigned short int f; l = 256; - for(i=0;i>8); + buf[l] = (f & 0xff); + buf[l + 1] = (f >> 8); printf("crc should be good... "); - i = ok_crc(buf, l+2); - if(i)printf("CRC declared OK\n"); - else printf("CRC declared bad\n"); - - buf[l+1]=(f&0xff); - buf[l]=(f>>8); + i = ok_crc(buf, l + 2); + if (i) + printf("CRC declared OK\n"); + else + printf("CRC declared bad\n"); + + buf[l + 1] = (f & 0xff); + buf[l] = (f >> 8); printf("reversed the CRC byte order... CRC should be bad..."); - i = ok_crc(buf, l+2); - if(i)printf("CRC declared OK\n"); - else printf("CRC declared bad\n"); + i = ok_crc(buf, l + 2); + if (i) + printf("CRC declared OK\n"); + else + printf("CRC declared bad\n"); printf("changed the frame length... CRC should be bad..."); - i = ok_crc(buf, l+1); - if(i)printf("CRC declared OK\n"); - else printf("CRC declared bad\n"); + i = ok_crc(buf, l + 1); + if (i) + printf("CRC declared OK\n"); + else + printf("CRC declared bad\n"); - buf[0]-=1; + buf[0] -= 1; printf("corrupted the data... CRC should be bad..."); - i = ok_crc(buf, l+2); - if(i)printf("CRC declared OK\n"); - else printf("CRC declared bad\n"); + i = ok_crc(buf, l + 2); + if (i) + printf("CRC declared OK\n"); + else + printf("CRC declared bad\n"); } #endif diff --git a/ax25ipd/io.c b/ax25ipd/io.c index 88a4923..6371e5e 100644 --- a/ax25ipd/io.c +++ b/ax25ipd/io.c @@ -46,12 +46,12 @@ struct termios nterm; #ifdef USE_TERMIO #include -struct termio nterm; +struct termio nterm; #endif #ifdef USE_SGTTY #include -struct sgttyb nterm; +struct sgttyb nterm; #endif int ttyfd = -1; @@ -88,8 +88,7 @@ time_t last_bc_time; * Initialize the io variables */ -void -io_init() +void io_init() { /* @@ -97,23 +96,22 @@ io_init() * will be able to support a re-initialization if sent a SIGHUP. */ - if(ttyfd>=0){ + if (ttyfd >= 0) { close(ttyfd); ttyfd = -1; } - if(sock>=0){ + if (sock >= 0) { close(sock); sock = -1; } - if(udpsock>=0){ + if (udpsock >= 0) { close(udpsock); udpsock = -1; } - #ifdef USE_ICMP - if(icmpsock>=0){ + if (icmpsock >= 0) { close(icmpsock); icmpsock = -1; } @@ -124,13 +122,13 @@ io_init() * address structure. Since both to and from are static, they are * already clear. */ - bzero( (char *)&to, sizeof(struct sockaddr) ); + bzero((char *) &to, sizeof(struct sockaddr)); to.sin_family = AF_INET; - bzero( (char *)&from, sizeof(struct sockaddr) ); + bzero((char *) &from, sizeof(struct sockaddr)); from.sin_family = AF_INET; - bzero( (char *)&udpbind, sizeof(struct sockaddr) ); + bzero((char *) &udpbind, sizeof(struct sockaddr)); udpbind.sin_family = AF_INET; } @@ -142,9 +140,9 @@ void io_open() { int baudrate; - if(ip_mode){ + if (ip_mode) { sock = socket(AF_INET, SOCK_RAW, IPPROTO_AX25); - if (sock<0) { + if (sock < 0) { perror("opening raw socket"); exit(1); } @@ -152,10 +150,9 @@ void io_open() perror("setting non-blocking I/O on raw socket"); exit(1); } - #ifdef USE_ICMP icmpsock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); - if (icmpsock<0) { + if (icmpsock < 0) { perror("opening raw ICMP socket"); exit(1); } @@ -166,9 +163,9 @@ void io_open() #endif } - if(udp_mode){ + if (udp_mode) { udpsock = socket(AF_INET, SOCK_DGRAM, 0); - if (udpsock<0) { + if (udpsock < 0) { perror("opening udp socket"); exit(1); } @@ -182,14 +179,16 @@ void io_open() */ udpbind.sin_addr.s_addr = INADDR_ANY; udpbind.sin_port = my_udp; - if(bind(udpsock,(struct sockaddr *)&udpbind,sizeof udpbind)<0){ + if (bind + (udpsock, (struct sockaddr *) &udpbind, + sizeof udpbind) < 0) { perror("binding udp socket"); exit(1); } } ttyfd = open(ttydevice, O_RDWR, 0); - if (ttyfd<0) { + if (ttyfd < 0) { perror("opening tty device"); exit(1); } @@ -197,257 +196,416 @@ void io_open() perror("setting non-blocking I/O on tty device"); exit(1); } - #ifdef USE_TERMIOS - if(ioctl(ttyfd, TCGETS, &nterm)<0){ + if (ioctl(ttyfd, TCGETS, &nterm) < 0) { #endif #ifdef USE_TERMIO - if(ioctl(ttyfd, TCGETA, &nterm)<0){ + if (ioctl(ttyfd, TCGETA, &nterm) < 0) { #endif #ifdef USE_SGTTY - if(ioctl(ttyfd, TIOCGETP, &nterm)<0){ + if (ioctl(ttyfd, TIOCGETP, &nterm) < 0) { #endif - perror("fetching tty device parameters"); - exit(1); - } + perror("fetching tty device parameters"); + exit(1); + } - if(ttyspeed==50)baudrate=B50; - else if(ttyspeed==50)baudrate=B50; - else if(ttyspeed==75)baudrate=B75; - else if(ttyspeed==110)baudrate=B110; - else if(ttyspeed==134)baudrate=B134; - else if(ttyspeed==150)baudrate=B150; - else if(ttyspeed==200)baudrate=B200; - else if(ttyspeed==300)baudrate=B300; - else if(ttyspeed==600)baudrate=B600; - else if(ttyspeed==1200)baudrate=B1200; - else if(ttyspeed==1800)baudrate=B1800; - else if(ttyspeed==2400)baudrate=B2400; - else if(ttyspeed==4800)baudrate=B4800; - else if(ttyspeed==9600)baudrate=B9600; + if (ttyspeed == 50) + baudrate = B50; + else if (ttyspeed == 50) + baudrate = B50; + else if (ttyspeed == 75) + baudrate = B75; + else if (ttyspeed == 110) + baudrate = B110; + else if (ttyspeed == 134) + baudrate = B134; + else if (ttyspeed == 150) + baudrate = B150; + else if (ttyspeed == 200) + baudrate = B200; + else if (ttyspeed == 300) + baudrate = B300; + else if (ttyspeed == 600) + baudrate = B600; + else if (ttyspeed == 1200) + baudrate = B1200; + else if (ttyspeed == 1800) + baudrate = B1800; + else if (ttyspeed == 2400) + baudrate = B2400; + else if (ttyspeed == 4800) + baudrate = B4800; + else if (ttyspeed == 9600) + baudrate = B9600; #ifdef B19200 - else if(ttyspeed==19200)baudrate=B19200; + else if (ttyspeed == 19200) + baudrate = B19200; #else #ifdef EXTA - else if(ttyspeed==19200)baudrate=EXTA; + else if (ttyspeed == 19200) + baudrate = EXTA; #endif #endif #ifdef B38400 - else if(ttyspeed==38400)baudrate=B38400; + else if (ttyspeed == 38400) + baudrate = B38400; #else #ifdef EXTB - else if(ttyspeed==38400)baudrate=EXTB; + else if (ttyspeed == 38400) + baudrate = EXTB; #endif #endif - else baudrate = B9600; + else + baudrate = B9600; #ifdef USE_SGTTY - nterm.sg_flags = (RAW | ANYP); - nterm.sg_ispeed = baudrate; - nterm.sg_ospeed = baudrate; + nterm.sg_flags = (RAW | ANYP); + nterm.sg_ispeed = baudrate; + nterm.sg_ospeed = baudrate; #else - nterm.c_iflag = 0; - nterm.c_oflag = 0; - nterm.c_cflag = baudrate | CS8 | CREAD | CLOCAL; - nterm.c_lflag = 0; - nterm.c_cc[VMIN] = 0; - nterm.c_cc[VTIME] = 0; + nterm.c_iflag = 0; + nterm.c_oflag = 0; + nterm.c_cflag = baudrate | CS8 | CREAD | CLOCAL; + nterm.c_lflag = 0; + nterm.c_cc[VMIN] = 0; + nterm.c_cc[VTIME] = 0; #endif #ifdef USE_TERMIOS - if(ioctl(ttyfd, TCSETS, &nterm)<0){ + if (ioctl(ttyfd, TCSETS, &nterm) < 0) { #endif #ifdef USE_TERMIO - if(ioctl(ttyfd, TCSETA, &nterm)<0){ + if (ioctl(ttyfd, TCSETA, &nterm) < 0) { #endif #ifdef USE_SGTTY - if(ioctl(ttyfd, TIOCSETP, &nterm)<0){ + if (ioctl + (ttyfd, TIOCSETP, + &nterm) < 0) { #endif - perror("setting tty device parameters"); - exit(1); - } + perror + ("setting tty device parameters"); + exit(1); + } - if(digi)send_params(); + if (digi) + send_params(); - last_bc_time = 0; /* force immediate id */ -} + last_bc_time = 0; /* force immediate id */ + } /* * Start up and run the I/O mechanisms. * run in a loop, using the select call to handle input. */ -void -io_start() -{ - int n, nb, hdr_len; - fd_set readfds; - unsigned char buf[MAX_FRAME]; - struct timeval wait; - struct iphdr *ipptr; - time_t now; - - for(;;){ - - if((bc_interval>0)&&digi){ - now = time(NULL); - if (last_bc_time + bc_interval < now){ - last_bc_time = now; - LOGL4("iostart: BEACON\n"); - do_beacon(); - } - } - - wait.tv_sec = 10; /* lets us keep the beacon going */ - wait.tv_usec = 0; - - FD_ZERO(&readfds); - - FD_SET(ttyfd, &readfds); - - if(ip_mode){ - FD_SET(sock, &readfds); + void io_start() { + int n, nb, hdr_len; + fd_set readfds; + unsigned char buf[MAX_FRAME]; + struct timeval wait; + struct iphdr *ipptr; + time_t now; + + for (;;) { + + if ((bc_interval > 0) + && digi) { + now = time(NULL); + if (last_bc_time + + bc_interval < + now) { + last_bc_time + = now; + LOGL4 + ("iostart: BEACON\n"); + do_beacon + (); + } + } + + wait.tv_sec = 10; /* lets us keep the beacon going */ + wait.tv_usec = 0; + + FD_ZERO(&readfds); + + FD_SET(ttyfd, &readfds); + + if (ip_mode) { + FD_SET(sock, + &readfds); #ifdef USE_ICMP - FD_SET(icmpsock, &readfds); + FD_SET(icmpsock, + &readfds); #endif - } - - if(udp_mode){ - FD_SET(udpsock, &readfds); - } - - nb = select(FD_SETSIZE,&readfds,(fd_set *)0,(fd_set *)0,&wait); - - if(nb < 0){ - if(errno == EINTR)continue; /* Ignore */ - perror("select"); - exit(1); - } - - if(nb == 0){ - fflush(stdout); - fflush(stderr); - /* just so we go back to the top of the loop! */ - continue; - } - - if(FD_ISSET(ttyfd, &readfds)){ - do { - n = read(ttyfd, buf, MAX_FRAME); - } while(io_error(n, buf, n, READ_MSG, TTY_MODE)); - LOGL4("ttydata l=%d\n",n); - if(n>0)assemble_kiss(buf,n); + } + + if (udp_mode) { + FD_SET(udpsock, + &readfds); + } + + nb = select + (FD_SETSIZE, + &readfds, + (fd_set *) 0, + (fd_set *) 0, &wait); + + if (nb < 0) { + if (errno == EINTR) + continue; /* Ignore */ + perror("select"); + exit(1); + } + + if (nb == 0) { + fflush(stdout); + fflush(stderr); + /* just so we go back to the top of the loop! */ + continue; + } + + if (FD_ISSET + (ttyfd, &readfds)) { + do { + n = read + (ttyfd, + buf, + MAX_FRAME); + } + while (io_error + (n, buf, n, + READ_MSG, + TTY_MODE)); + LOGL4 + ("ttydata l=%d\n", + n); + if (n > 0) + assemble_kiss + (buf, + n); /* * If we are in "beacon after" mode, reset the "last_bc_time" each time * we hear something on the channel. */ - if(!bc_every)last_bc_time = time(NULL); - } - - if(udp_mode){ - if(FD_ISSET(udpsock, &readfds)){ - do { - fromlen = sizeof from; - n = recvfrom(udpsock, buf, MAX_FRAME, 0, - (struct sockaddr *)&from, &fromlen); - } while(io_error(n, buf, n, READ_MSG, UDP_MODE)); - LOGL4("udpdata from=%s port=%d l=%d\n", - (char *)inet_ntoa(from.sin_addr), - ntohs(from.sin_port), n); - stats.udp_in++; - if(n>0)from_ip(buf, n); - } - } /* if udp_mode */ - - if(ip_mode){ - if(FD_ISSET(sock, &readfds)){ - do{ - fromlen = sizeof from; - n = recvfrom(sock, buf, MAX_FRAME, 0, - (struct sockaddr *)&from, &fromlen); - } while(io_error(n, buf, n, READ_MSG, IP_MODE)); - ipptr = (struct iphdr *)buf; - hdr_len = 4 * ipptr->ihl; - LOGL4("ipdata from=%s l=%d, hl=%d\n", - (char *)inet_ntoa(from.sin_addr), - n, hdr_len); - stats.ip_in++; - if(n>hdr_len)from_ip(buf+hdr_len, n-hdr_len); - } - + if (!bc_every) + last_bc_time + = + time + (NULL); + } + + if (udp_mode) { + if (FD_ISSET + (udpsock, + &readfds)) { + do { + fromlen + = + sizeof + from; + n = recvfrom(udpsock, buf, MAX_FRAME, 0, (struct sockaddr *) &from, &fromlen); + } + while + (io_error + (n, + buf, + n, + READ_MSG, + UDP_MODE)); + LOGL4 + ("udpdata from=%s port=%d l=%d\n", + (char + *) + inet_ntoa + (from. + sin_addr), + ntohs + (from. + sin_port), + n); + stats. + udp_in++; + if (n > 0) + from_ip + (buf, + n); + } + } + /* if udp_mode */ + if (ip_mode) { + if (FD_ISSET + (sock, + &readfds)) { + do { + fromlen + = + sizeof + from; + n = recvfrom(sock, buf, MAX_FRAME, 0, (struct sockaddr *) &from, &fromlen); + } + while + (io_error + (n, + buf, + n, + READ_MSG, + IP_MODE)); + ipptr = + (struct + iphdr + *) + buf; + hdr_len = + 4 * + ipptr-> + ihl; + LOGL4 + ("ipdata from=%s l=%d, hl=%d\n", + (char + *) + inet_ntoa + (from. + sin_addr), + n, + hdr_len); + stats. + ip_in++; + if (n > + hdr_len) + from_ip + (buf + + + hdr_len, + n + - + hdr_len); + } #ifdef USE_ICMP - if(FD_ISSET(icmpsock, &readfds)){ - do { - fromlen = sizeof from; - n = recvfrom(icmpsock, buf, MAX_FRAME, 0, - (struct sockaddr *)&from, &fromlen); - } while(io_error(n, buf, n, READ_MSG, ICMP_MODE)); - ipptr = (struct iphdr *)buf; - hdr_len = 4 * ipptr->ihl; - LOGL4("icmpdata from=%s l=%d, hl=%d\n", - (char *)inet_ntoa(from.sin_addr), - n, hdr_len); - } + if (FD_ISSET + (icmpsock, + &readfds)) { + do { + fromlen + = + sizeof + from; + n = recvfrom(icmpsock, buf, MAX_FRAME, 0, (struct sockaddr *) &from, &fromlen); + } + while + (io_error + (n, + buf, + n, + READ_MSG, + ICMP_MODE)); + ipptr = + (struct + iphdr + *) + buf; + hdr_len = + 4 * + ipptr-> + ihl; + LOGL4 + ("icmpdata from=%s l=%d, hl=%d\n", + (char + *) + inet_ntoa + (from. + sin_addr), + n, + hdr_len); + } #endif - } /* if ip_mode */ - - } /* for forever */ -} + } + /* if ip_mode */ + } /* for forever */ + } /* Send an IP frame */ -void -send_ip(buf, l, targetip) -unsigned char *buf; -int l; -unsigned char *targetip; -{ - int n; - - if(l<=0)return; - memcpy((char *)&to.sin_addr, targetip, 4); - memcpy((char *)&to.sin_port, &targetip[4], 2); - LOGL4("sendipdata to=%s %s %d l=%d\n", - (char *)inet_ntoa(to.sin_addr), - to.sin_port ? "udp" : "ip", - ntohs(to.sin_port), l); - if(to.sin_port){ - if(udp_mode){ - stats.udp_out++; - do { - n = sendto(udpsock, buf, l, 0, - (struct sockaddr *)&to, sizeof to); - } while(io_error(n, buf, l, SEND_MSG, UDP_MODE)); - } - } else { - if(ip_mode){ - stats.ip_out++; - do { - n = sendto(sock, buf, l, 0, - (struct sockaddr *)&to, sizeof to); - } while(io_error(n, buf, l, SEND_MSG, IP_MODE)); - } - } -} + void send_ip(buf, l, targetip) + unsigned char *buf; + int l; + unsigned char *targetip; + { + int n; + + if (l <= 0) + return; + memcpy((char *) &to.sin_addr, + targetip, 4); + memcpy((char *) &to.sin_port, + &targetip[4], 2); + LOGL4 + ("sendipdata to=%s %s %d l=%d\n", + (char *) inet_ntoa(to. + sin_addr), + to.sin_port ? "udp" : "ip", + ntohs(to.sin_port), l); + if (to.sin_port) { + if (udp_mode) { + stats.udp_out++; + do { + n = sendto + (udpsock, + buf, + l, 0, + (struct + sockaddr + *) + &to, + sizeof + to); + } + while (io_error + (n, buf, l, + SEND_MSG, + UDP_MODE)); + } + } else { + if (ip_mode) { + stats.ip_out++; + do { + n = sendto + (sock, + buf, + l, 0, + (struct + sockaddr + *) + &to, + sizeof + to); + } + while (io_error + (n, buf, l, + SEND_MSG, + IP_MODE)); + } + } + } /* Send a kiss frame */ -void -send_tty(buf, l) -unsigned char *buf; -int l; -{ - int n; - unsigned char *p; - int nc; + void send_tty(buf, l) + unsigned char *buf; + int l; + { + int n; + unsigned char *p; + int nc; - if(l<=0)return; - LOGL4("sendttydata l=%d\tsent: ",l); - stats.kiss_out++; + if (l <= 0) + return; + LOGL4("sendttydata l=%d\tsent: ", + l); + stats.kiss_out++; - p = buf; - nc = l; - n = 0; + p = buf; + nc = l; + n = 0; /* * we have to loop around here because each call to write may write a few @@ -459,116 +617,158 @@ int l; * compile-time options) by having io_error barf when it detects an EAGAIN * error code. */ - do { - if((n>0)&&(n0){ - if(n!=nc){ - LOGL4("%d ",n); /* no-one said loglevel 4 */ - } else { - LOGL4("%d\n",n); /* was efficient!!! */ - } - } - } while( ((n>0)&&(n 0) + && (n < nc)) { /* did we put only write a bit? */ + p += n; /* point to the new data */ + nc -= n; /* drop the length */ + } + n = write(ttyfd, p, nc); + if (n > 0) { + if (n != nc) { + LOGL4("%d ", n); /* no-one said loglevel 4 */ + } else { + LOGL4("%d\n", n); /* was efficient!!! */ + } + } + } + while (((n > 0) && (n < nc)) + || + (io_error + (n, p, nc, SEND_MSG, + TTY_MODE))); + } /* process an I/O error; return true if a retry is needed */ -int -io_error(oops, buf, bufsize, dir, mode) -int oops; /* the error flag; < 0 indicates a problem */ -unsigned char *buf; /* the data in question */ -int bufsize; /* the size of the data buffer */ -int dir; /* the direction; input or output */ -int mode; /* the fd on which we got the error */ -{ + int io_error(oops, buf, bufsize, dir, mode) int oops; /* the error flag; < 0 indicates a problem */ + unsigned char *buf; /* the data in question */ + int bufsize; /* the size of the data buffer */ + int dir; /* the direction; input or output */ + int mode; /* the fd on which we got the error */ + { - if(oops >= 0) return 0; /* do we have an error ? */ + if (oops >= 0) + return 0; /* do we have an error ? */ #ifdef EAGAIN - if(errno == EAGAIN){ - perror("System 5 I/O error!"); - fprintf(stderr,"A System 5 style I/O error was detected. This program requires BSD 4.2\n"); - fprintf(stderr,"behaviour. This is probably a result of compile-time environment.\n"); - exit(3); - } + if (errno == EAGAIN) { + perror + ("System 5 I/O error!"); + fprintf(stderr, + "A System 5 style I/O error was detected. This program requires BSD 4.2\n"); + fprintf(stderr, + "behaviour. This is probably a result of compile-time environment.\n"); + exit(3); + } #endif - if(dir == READ_MSG){ - if(errno == EINTR) return 0; /* never retry read */ - if(errno == EWOULDBLOCK){ - LOGL4("READ would block (?!), sleeping and retrying!\n"); - usleep(100000); /* sleep a bit */ - return 1; /* and retry */ - } - if(mode == IP_MODE){ - perror("reading from raw ip socket"); - exit(2); - } else if(mode == UDP_MODE){ - perror("reading from udp socket"); - exit(2); - } else if(mode == TTY_MODE){ - perror("reading from tty device"); - exit(2); - } else { - perror("reading from unknown I/O"); - exit(2); - } - } else if(dir == SEND_MSG){ - if(errno == EINTR) return 1; /* always retry on writes */ - if(mode == IP_MODE){ - if(errno == EMSGSIZE){ /* msg too big, drop it */ - perror("message dropped on raw ip socket"); - fprintf(stderr,"message was %d bytes long.\n",bufsize); - return 0; - } - if(errno == ENOBUFS){ /* congestion; sleep + retry */ - LOGL4("send congestion on raw ip, sleeping and retrying!\n"); - usleep(100000); - return 1; - } - if(errno == EWOULDBLOCK){ - LOGL4("send on raw ip would block, sleeping and retrying!\n"); - usleep(100000); /* sleep a bit */ - return 1; /* and retry */ - } - perror("writing to raw ip socket"); - exit(2); - } else if(mode == UDP_MODE){ - if(errno == EMSGSIZE){ /* msg too big, drop it */ - perror("message dropped on udp socket"); - fprintf(stderr,"message was %d bytes long.\n",bufsize); - return 0; - } - if(errno == ENOBUFS){ /* congestion; sleep + retry */ - LOGL4("send congestion on udp, sleeping and retrying!\n"); - usleep(100000); - return 1; - } - if(errno == EWOULDBLOCK){ - LOGL4("send on udp would block, sleeping and retrying!\n"); - usleep(100000); /* sleep a bit */ - return 1; /* and retry */ - } - perror("writing to udp socket"); - exit(2); - } else if(mode == TTY_MODE){ - if(errno == EWOULDBLOCK){ - LOGL4("write to tty would block, sleeping and retrying!\n"); - usleep(100000); /* sleep a bit */ - return 1; /* and retry */ - } - perror("writing to tty device"); - exit(2); - } else { - perror("writing to unknown I/O"); - exit(2); - } - } else { - perror("Unknown direction and I/O"); - exit(2); - } - return 0; -} + if (dir == READ_MSG) { + if (errno == EINTR) + return 0; /* never retry read */ + if (errno == EWOULDBLOCK) { + LOGL4 + ("READ would block (?!), sleeping and retrying!\n"); + usleep(100000); /* sleep a bit */ + return 1; /* and retry */ + } + if (mode == IP_MODE) { + perror + ("reading from raw ip socket"); + exit(2); + } else if (mode == + UDP_MODE) { + perror + ("reading from udp socket"); + exit(2); + } else if (mode == + TTY_MODE) { + perror + ("reading from tty device"); + exit(2); + } else { + perror + ("reading from unknown I/O"); + exit(2); + } + } else if (dir == SEND_MSG) { + if (errno == EINTR) + return 1; /* always retry on writes */ + if (mode == IP_MODE) { + if (errno == EMSGSIZE) { /* msg too big, drop it */ + perror + ("message dropped on raw ip socket"); + fprintf + (stderr, + "message was %d bytes long.\n", + bufsize); + return 0; + } + if (errno == ENOBUFS) { /* congestion; sleep + retry */ + LOGL4 + ("send congestion on raw ip, sleeping and retrying!\n"); + usleep + (100000); + return 1; + } + if (errno == + EWOULDBLOCK) { + LOGL4 + ("send on raw ip would block, sleeping and retrying!\n"); + usleep(100000); /* sleep a bit */ + return 1; /* and retry */ + } + perror + ("writing to raw ip socket"); + exit(2); + } else if (mode == + UDP_MODE) { + if (errno == EMSGSIZE) { /* msg too big, drop it */ + perror + ("message dropped on udp socket"); + fprintf + (stderr, + "message was %d bytes long.\n", + bufsize); + return 0; + } + if (errno == ENOBUFS) { /* congestion; sleep + retry */ + LOGL4 + ("send congestion on udp, sleeping and retrying!\n"); + usleep + (100000); + return 1; + } + if (errno == + EWOULDBLOCK) { + LOGL4 + ("send on udp would block, sleeping and retrying!\n"); + usleep(100000); /* sleep a bit */ + return 1; /* and retry */ + } + perror + ("writing to udp socket"); + exit(2); + } else if (mode == + TTY_MODE) { + if (errno == + EWOULDBLOCK) { + LOGL4 + ("write to tty would block, sleeping and retrying!\n"); + usleep(100000); /* sleep a bit */ + return 1; /* and retry */ + } + perror + ("writing to tty device"); + exit(2); + } else { + perror + ("writing to unknown I/O"); + exit(2); + } + } else { + perror + ("Unknown direction and I/O"); + exit(2); + } + return 0; + } diff --git a/ax25ipd/kiss.c b/ax25ipd/kiss.c index 6042cf0..b43d969 100644 --- a/ax25ipd/kiss.c +++ b/ax25ipd/kiss.c @@ -43,8 +43,7 @@ int param_tbl_top; * Initialize the KISS variables */ -void -kiss_init() +void kiss_init() { ifptr = iframe; ifcount = 0; @@ -60,31 +59,33 @@ kiss_init() * frame has been assembled. */ -void -assemble_kiss(buf, l) +void assemble_kiss(buf, l) unsigned char *buf; int l; { int i; unsigned char c; - for(i=0;i0){ + if (c == FEND) { + if (ifcount > 0) { /* Make sure that the control byte is zero */ - if(*iframe=='\0' || *iframe==0x10) { + if (*iframe == '\0' || *iframe == 0x10) { /* Room for CRC in buffer? */ - if(ifcount < (MAX_FRAME - 2)) { + if (ifcount < (MAX_FRAME - 2)) { stats.kiss_in++; - from_kiss(iframe+1,ifcount-1); + from_kiss(iframe + + 1, ifcount - 1); } else { stats.kiss_toobig++; - LOGL2("assemble_kiss: dumped - frame too large\n"); + LOGL2 + ("assemble_kiss: dumped - frame too large\n"); } } else { stats.kiss_badtype++; - LOGL2("assemble_kiss: dumped - control byte non-zero\n"); + LOGL2 + ("assemble_kiss: dumped - control byte non-zero\n"); } } ifcount = 0; @@ -92,26 +93,27 @@ int l; ifptr = iframe; continue; } - if(c==FESC){ - iescaped=1; + if (c == FESC) { + iescaped = 1; continue; } - if(iescaped){ - if(c==TFEND)c = FEND; - if(c==TFESC)c = FESC; + if (iescaped) { + if (c == TFEND) + c = FEND; + if (c == TFESC) + c = FESC; iescaped = 0; } - if(ifcount < MAX_FRAME){ + if (ifcount < MAX_FRAME) { *ifptr = c; ifptr++; ifcount++; } - } /* for every character in the buffer */ + } /* for every character in the buffer */ } /* convert a standard AX25 frame into a kiss frame */ -void -send_kiss(type, buf, l) +void send_kiss(type, buf, l) unsigned char type; unsigned char *buf; int l; @@ -125,27 +127,27 @@ int l; KISSEMIT(FEND); - if(type==FEND){ + if (type == FEND) { KISSEMIT(FESC); KISSEMIT(TFEND); - }else if (type==FESC){ + } else if (type == FESC) { KISSEMIT(FESC); KISSEMIT(TFESC); - }else { + } else { KISSEMIT(type); } - for(i=0;i= PTABLE_SIZE){ - fprintf(stderr,"param table is full; entry ignored.\n"); + if (param_tbl_top >= PTABLE_SIZE) { + fprintf(stderr, "param table is full; entry ignored.\n"); } - param_tbl[param_tbl_top].parameter = p&0xff; - param_tbl[param_tbl_top].value = v&0xff; + param_tbl[param_tbl_top].parameter = p & 0xff; + param_tbl[param_tbl_top].value = v & 0xff; LOGL4("added param: %d\t%d\n", - param_tbl[param_tbl_top].parameter, - param_tbl[param_tbl_top].value); + param_tbl[param_tbl_top].parameter, + param_tbl[param_tbl_top].value); param_tbl_top++; return; } /* dump the contents of the parameter table */ -void -dump_params() +void dump_params() { int i; - LOGL1("\n%d parameters\n",param_tbl_top); - for(i=0;i2) + if (loglevel > 2) dump_ax25frame("from_kiss: ", buf, l); - if(digi) { /* if we are in digi mode */ + if (digi) { /* if we are in digi mode */ a = next_addr(buf); - if(NOT_ME(a)){ + if (NOT_ME(a)) { stats.kiss_not_for_me++; LOGL4("from_kiss: (digi) dumped - not for me\n"); return; } - if (a==buf) { /* must be a digi */ + if (a == buf) { /* must be a digi */ stats.kiss_i_am_dest++; - LOGL2("from_kiss: (digi) dumped - I am destination!\n"); + LOGL2 + ("from_kiss: (digi) dumped - I am destination!\n"); return; } SETREPEATED(a); a = next_addr(buf); /* find who gets it after us */ - } else { /* must be tnc mode */ + } else { /* must be tnc mode */ a = next_addr(buf); #ifdef TNC_FILTER if (IS_ME(a)) { - LOGL2("from_kiss: (tnc) dumped - addressed to self!\n"); + LOGL2 + ("from_kiss: (tnc) dumped - addressed to self!\n"); return; } #endif - } /* end of tnc mode */ + } /* end of tnc mode */ /* Lookup the IP address for this route */ ipaddr = call_to_ip(a); - if (ipaddr==NULL) { + if (ipaddr == NULL) { if (is_call_bcast(a)) { /* Warning - assuming buffer has room for 2 bytes */ - add_crc(buf, l); l+=2; + add_crc(buf, l); + l += 2; send_broadcast(buf, l); } else { stats.kiss_no_ip_addr++; - LOGL2("from_kiss: dumped - cannot figure out where to send this!\n"); + LOGL2 + ("from_kiss: dumped - cannot figure out where to send this!\n"); } return; } else { /* Warning - assuming buffer has room for 2 bytes */ - add_crc(buf, l); l+=2; + add_crc(buf, l); + l += 2; send_ip(buf, l, ipaddr); if (is_call_bcast(a)) { send_broadcast(buf, l); @@ -144,54 +147,56 @@ int l; * We simply send the packet to the KISS send routine. */ -void -from_ip(buf, l) +void from_ip(buf, l) unsigned char *buf; int l; { int port = 0; unsigned char *a; - if(!ok_crc(buf, l)){ + if (!ok_crc(buf, l)) { stats.ip_failed_crc++; LOGL2("from_ip: dumped - CRC incorrect!\n"); return; } - l = l - 2; /* dump the blasted CRC */ + l = l - 2; /* dump the blasted CRC */ - if(l<15){ + if (l < 15) { stats.ip_tooshort++; LOGL2("from_ip: dumped - length wrong!\n"); return; } - if(loglevel>2)dump_ax25frame("from_ip: ", buf, l); + if (loglevel > 2) + dump_ax25frame("from_ip: ", buf, l); - if(digi){ /* if we are in digi mode */ + if (digi) { /* if we are in digi mode */ a = next_addr(buf); - if(NOT_ME(a)){ + if (NOT_ME(a)) { stats.ip_not_for_me++; LOGL2("from_ip: (digi) dumped - not for me!\n"); return; } - if(a==buf){ /* must be a digi */ + if (a == buf) { /* must be a digi */ stats.ip_i_am_dest++; - LOGL2("from_ip: (digi) dumped - I am destination!\n"); + LOGL2 + ("from_ip: (digi) dumped - I am destination!\n"); return; } - if(dual_port == 1 && FOR_PORT2(a)){ + if (dual_port == 1 && FOR_PORT2(a)) { port = 0x10; } SETREPEATED(a); - } else { /* must be tnc mode */ + } else { /* must be tnc mode */ a = next_addr(buf); #ifdef TNC_FILTER - if(NOT_ME(a)){ - LOGL2("from_ip: (tnc) dumped - I am not destination!\n"); + if (NOT_ME(a)) { + LOGL2 + ("from_ip: (tnc) dumped - I am not destination!\n"); return; } #endif - } /* end of tnc mode */ + } /* end of tnc mode */ send_kiss(port, buf, l); } @@ -199,38 +204,40 @@ int l; * Send an ID frame out the KISS port. */ -void -do_beacon() +void do_beacon() { int i; unsigned char *p; - if(bclen == 0) return; /* nothing to do! */ + if (bclen == 0) + return; /* nothing to do! */ - if(bclen < 0) { /* build the id string */ + if (bclen < 0) { /* build the id string */ p = bcbuf; - *p++ = ('I'<<1); - *p++ = ('D'<<1); - *p++ = (' '<<1); - *p++ = (' '<<1); - *p++ = (' '<<1); - *p++ = (' '<<1); - *p++ = '\0' | 0x60; /* SSID, set reserved bits */ + *p++ = ('I' << 1); + *p++ = ('D' << 1); + *p++ = (' ' << 1); + *p++ = (' ' << 1); + *p++ = (' ' << 1); + *p++ = (' ' << 1); + *p++ = '\0' | 0x60; /* SSID, set reserved bits */ - for(i=0;i<6;i++)*p++=mycallsign[i]; - *p++ = mycallsign[6] | 0x60; /* ensure reserved bits are set */ - SETLAST(bcbuf+7); /* Set the E bit -- last address */ + for (i = 0; i < 6; i++) + *p++ = mycallsign[i]; + *p++ = mycallsign[6] | 0x60; /* ensure reserved bits are set */ + SETLAST(bcbuf + 7); /* Set the E bit -- last address */ - *p++ = 0x03; /* Control field -- UI frame */ + *p++ = 0x03; /* Control field -- UI frame */ - *p++ = 0xf0; /* Protocol ID -- 0xf0 is no protocol */ + *p++ = 0xf0; /* Protocol ID -- 0xf0 is no protocol */ - strcpy(p, bc_text); /* add the text field */ + strcpy(p, bc_text); /* add the text field */ - bclen = 16 + strlen(bc_text); /* adjust the length nicely */ + bclen = 16 + strlen(bc_text); /* adjust the length nicely */ } - if(loglevel>2)dump_ax25frame("do_beacon: ", bcbuf, bclen); + if (loglevel > 2) + dump_ax25frame("do_beacon: ", bcbuf, bclen); stats.kiss_beacon_outs++; send_kiss(0, bcbuf, bclen); } @@ -239,20 +246,28 @@ do_beacon() * return true if the addresses supplied match * modified for wildcarding by vk5xxx */ -int -addrmatch(a,b) +int addrmatch(a, b) unsigned char *a, *b; { - if((*a=='\0') || (*b=='\0'))return 0; - - if((*a++^*b++)&0xfe)return 0; /* "K" */ - if((*a++^*b++)&0xfe)return 0; /* "A" */ - if((*a++^*b++)&0xfe)return 0; /* "9" */ - if((*a++^*b++)&0xfe)return 0; /* "W" */ - if((*a++^*b++)&0xfe)return 0; /* "S" */ - if((*a++^*b++)&0xfe)return 0; /* "B" */ - if(((*b++)&0x1e)==0)return 1; /* ssid 0 matches all ssid's */ - if((*a++^*b)&0x1e)return 0; /* ssid */ + if ((*a == '\0') || (*b == '\0')) + return 0; + + if ((*a++ ^ *b++) & 0xfe) + return 0; /* "K" */ + if ((*a++ ^ *b++) & 0xfe) + return 0; /* "A" */ + if ((*a++ ^ *b++) & 0xfe) + return 0; /* "9" */ + if ((*a++ ^ *b++) & 0xfe) + return 0; /* "W" */ + if ((*a++ ^ *b++) & 0xfe) + return 0; /* "S" */ + if ((*a++ ^ *b++) & 0xfe) + return 0; /* "B" */ + if (((*b++) & 0x1e) == 0) + return 1; /* ssid 0 matches all ssid's */ + if ((*a++ ^ *b) & 0x1e) + return 0; /* ssid */ /* if((*a++^*b++)&0x1e)return 0; ssid (how it was ...) */ return 1; } @@ -260,47 +275,47 @@ unsigned char *a, *b; /* * return pointer to the next station to get this packet */ -unsigned char * -next_addr(f) +unsigned char *next_addr(f) unsigned char *f; { unsigned char *a; /* If no digis, return the destination address */ - if(NO_DIGIS(f))return f; + if (NO_DIGIS(f)) + return f; /* check each digi field. The first one that hasn't seen it is the one */ a = f + 7; do { a += 7; - if(NOTREPEATED(a))return a; - }while(NOT_LAST(a)); + if (NOTREPEATED(a)) + return a; + } + while (NOT_LAST(a)); /* all the digis have seen it. return the destination address */ - return f; + return f; } /* * tack on the CRC for the frame. Note we assume the buffer is long * enough to have the two bytes tacked on. */ -void -add_crc(buf, l) +void add_crc(buf, l) unsigned char *buf; int l; { unsigned short int u; u = compute_crc(buf, l); - buf[l] = u&0xff; /* lsb first */ - buf[l+1] = (u>>8)&0xff; /* msb next */ + buf[l] = u & 0xff; /* lsb first */ + buf[l + 1] = (u >> 8) & 0xff; /* msb next */ } /* * Dump AX25 frame. */ -void -dump_ax25frame(t, buf, l) +void dump_ax25frame(t, buf, l) unsigned char *buf; char *t; int l; @@ -312,28 +327,31 @@ int l; printf("%s AX25: (l=%3d) ", t, l); - if(l<15){ + if (l < 15) { printf("Bogus size...\n"); return; } - printf("%s -> ", call_to_a(buf+7)); + printf("%s -> ", call_to_a(buf + 7)); printf("%s", call_to_a(buf)); - if(ARE_DIGIS(buf)){ + if (ARE_DIGIS(buf)) { printf(" v"); - a = buf+7; - do{ - a+=7; + a = buf + 7; + do { + a += 7; printf(" %s", call_to_a(a)); - if(REPEATED(a))printf("*"); - }while(NOT_LAST(a)); + if (REPEATED(a)) + printf("*"); + } + while (NOT_LAST(a)); } printf("\n"); #ifdef DEBUG - for(i=0;inext) - rl=rl->next; + rl = rl->next; - rn=(struct route_table_entry*)malloc(sizeof(struct route_table_entry)); + rn = (struct route_table_entry *) + malloc(sizeof(struct route_table_entry)); /* Build this entry ... */ - for (i=0; i<6; i++) + for (i = 0; i < 6; i++) rn->callsign[i] = call[i] & 0xfe; rn->callsign[6] = (call[6] & 0x1e) | 0x60; rn->padcall = 0; @@ -83,58 +82,57 @@ unsigned int flags; rn->pad1 = 0; rn->pad2 = 0; rn->flags = flags; - rn->next=NULL; + rn->next = NULL; /* Update the default_route pointer if this is a default route */ if (flags & AXRT_DEFAULT) - default_route=rn; + default_route = rn; - if (rl) /* ... the list is already started add the new route */ - rl->next=rn; - else /* ... start the list off */ - route_tbl=rn; + if (rl) /* ... the list is already started add the new route */ + rl->next = rn; + else /* ... start the list off */ + route_tbl = rn; /* Log this entry ... */ LOGL4("added route: %s\t%s\t%s\t%d\t%d\n", - call_to_a(rn->callsign), - (char *)inet_ntoa(*(struct in_addr *)rn->ip_addr), - rn->udp_port ? "udp" : "ip", - ntohs(rn->udp_port), flags); + call_to_a(rn->callsign), + (char *) inet_ntoa(*(struct in_addr *) rn->ip_addr), + rn->udp_port ? "udp" : "ip", ntohs(rn->udp_port), flags); return; } /* Add a new broadcast address entry */ -void -bcast_add(call) -unsigned char* call; +void bcast_add(call) +unsigned char *call; { struct bcast_table_entry *bl, *bn; int i; /* Check we have a callsign */ - if (call==NULL) + if (call == NULL) return; /* Find the last entry in the list */ - bl=bcast_tbl; + bl = bcast_tbl; if (bcast_tbl) while (bl->next) - bl=bl->next; + bl = bl->next; - bn=(struct bcast_table_entry*)malloc(sizeof(struct bcast_table_entry)); + bn = (struct bcast_table_entry *) + malloc(sizeof(struct bcast_table_entry)); /* Build this entry ... */ - for (i=0; i<6; i++) + for (i = 0; i < 6; i++) bn->callsign[i] = call[i] & 0xfe; bn->callsign[6] = (call[6] & 0x1e) | 0x60; - bn->next=NULL; + bn->next = NULL; - if (bl) /* ... the list is already started add the new route */ - bl->next=bn; - else /* ... start the list off */ - bcast_tbl=bn; + if (bl) /* ... the list is already started add the new route */ + bl->next = bn; + else /* ... start the list off */ + bcast_tbl = bn; /* Log this entry ... */ LOGL4("added broadcast address: %s\n", call_to_a(bn->callsign)); @@ -146,32 +144,32 @@ unsigned char* call; * immediately following the IP address. (UGLY coding; to be fixed later!) */ -unsigned char * -call_to_ip(call) +unsigned char *call_to_ip(call) unsigned char *call; { - struct route_table_entry* rp; + struct route_table_entry *rp; unsigned char mycall[7]; int i; - if(call==NULL) + if (call == NULL) return NULL; - for(i=0; i<6; i++) + for (i = 0; i < 6; i++) mycall[i] = call[i] & 0xfe; mycall[6] = (call[6] & 0x1e) | 0x60; - LOGL4("lookup call %s ",call_to_a(mycall)); + LOGL4("lookup call %s ", call_to_a(mycall)); - rp=route_tbl; + rp = route_tbl; while (rp) { - if (addrmatch(mycall,rp->callsign)) { + if (addrmatch(mycall, rp->callsign)) { LOGL4("found ip addr %s\n", - (char *)inet_ntoa(*(struct in_addr *)rp->ip_addr)); + (char *) inet_ntoa(*(struct in_addr *) + rp->ip_addr)); return rp->ip_addr; } - rp=rp->next; + rp = rp->next; } /* @@ -180,7 +178,8 @@ unsigned char *call; */ if (default_route) { LOGL4("failed, using default ip addr %s\n", - (char *)inet_ntoa(*(struct in_addr *)default_route->ip_addr)); + (char *) inet_ntoa(*(struct in_addr *) + default_route->ip_addr)); return default_route->ip_addr; } @@ -192,73 +191,70 @@ unsigned char *call; * Accept a callsign and return true if it is a broadcast address, or false * if it is not found on the list */ -int -is_call_bcast(call) +int is_call_bcast(call) unsigned char *call; { - struct bcast_table_entry* bp; + struct bcast_table_entry *bp; unsigned char bccall[7]; int i; - if(call==NULL) - return(FALSE); + if (call == NULL) + return (FALSE); - for(i=0; i<6; i++) + for (i = 0; i < 6; i++) bccall[i] = call[i] & 0xfe; bccall[6] = (call[6] & 0x1e) | 0x60; - LOGL4("lookup broadcast %s ",call_to_a(bccall)); + LOGL4("lookup broadcast %s ", call_to_a(bccall)); - bp=bcast_tbl; + bp = bcast_tbl; while (bp) { - if (addrmatch(bccall,bp->callsign)) { - LOGL4("found broadcast %s\n", call_to_a(bp->callsign)); - return(TRUE); + if (addrmatch(bccall, bp->callsign)) { + LOGL4("found broadcast %s\n", + call_to_a(bp->callsign)); + return (TRUE); } - bp=bp->next; + bp = bp->next; } - return(FALSE); + return (FALSE); } /* Traverse the routing table, transmitting the packet to each bcast route */ -void -send_broadcast(buf, l) +void send_broadcast(buf, l) unsigned char *buf; int l; { struct route_table_entry *rp; - rp=route_tbl; + rp = route_tbl; while (rp) { if (rp->flags & AXRT_BCAST) { send_ip(buf, l, rp->ip_addr); } - rp=rp->next; + rp = rp->next; } } /* print out the list of routes */ -void -dump_routes() +void dump_routes() { - struct route_table_entry* rp; + struct route_table_entry *rp; int i; - for (rp=route_tbl, i=0; rp; rp=rp->next) + for (rp = route_tbl, i = 0; rp; rp = rp->next) i++; - LOGL1("\n%d active routes.\n",i); + LOGL1("\n%d active routes.\n", i); - rp=route_tbl; + rp = route_tbl; while (rp) { LOGL1(" %s\t%s\t%s\t%d\t%d\n", - call_to_a(rp->callsign), - (char *)inet_ntoa(*(struct in_addr *)rp->ip_addr), - rp->udp_port ? "udp" : "ip", - ntohs(rp->udp_port), rp->flags); - rp=rp->next; + call_to_a(rp->callsign), + (char *) inet_ntoa(*(struct in_addr *) rp->ip_addr), + rp->udp_port ? "udp" : "ip", + ntohs(rp->udp_port), rp->flags); + rp = rp->next; } fflush(stdout); } - -- cgit v1.2.3