/* File : parse.c */ /* Copyright (C) 1992 Indian Institute of Technology, Bombay Written by V. Srinivas and Vishwas Joglekar, Dept of Computer Science and Engineering. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "yapcbr.h" #include "ipxwatch.h" #include "diag.h" extern void prnt_hex(BYTE *str,unsigned char *buf,int len); extern NODE_INFO *node_lookup(INTERNET_ADDRESS *node_address, struct nodes_on_net *node_info,int append_flag); extern struct network_info *net_lookup(BYTE *net_id, int append_flag); int read_hex(unsigned char *s,int len); int read_file(FILE *infile, int flag); void parse_input(BYTE *instr,BYTE *outstr,int len); int read_conifg(); int read_config() { FILE *fp1,*fp2; if((fp2=fopen("net.ipx","r")) == (FILE *)NULL) fprintf(stderr,"net.ipx not found\n"); else{ read_file(fp2,1); fclose(fp2); } if((fp1=fopen("node.ipx","r")) == (FILE *)NULL) fprintf(stderr,"node.ipx not found\n"); else{ read_file(fp1,0); fclose(fp1); } } void parse_input(BYTE *instr,BYTE *outstr,int len) { register int i; unsigned char ch; i=0; /* convert ascii to packed hex */ while(i= 'A' && ch <= 'F') ch = ch - 'A' + 10; else ch = ch - '0'; outstr[i/2] = (i %2) ? (outstr[i/2] + ch) : ((ch << 4) ) ; i++; } } /* Following funcion takes two arguments. FIrst is a file argument which gives a pointer to FILE open in a read mode. Second is a flag, it is 0 if file open is node.ipx and 1 if file open is net.ipx. This function thwen calls parse_input function and converts ascii addresses into hex form. */ read_file(FILE *infile, int fflag) { char str[124],st[124],fil[4][144]; char *ch ; INTERNET_ADDRESS node_address; int i=0,j=0,k,hash; BYTE address[13]; NODE_INFO *new_node; struct network_info *new_net; while(fgets(str,144,infile)!=NULL){ ch = str; if (*ch == '#' || *ch == '\n') continue; i=0; while(str[i] !='\n'){ while(str[i] == '\t' || str[i] == ' ')i++; k = 0; while (str[i] != '\t'&& str[i] !='\n' && str[i] != ' ') st[k++] = str[i++]; st[k] = '\0'; strcpy(fil[j],st); j++; } if(fflag == 1 && j == 2){ /* update the network info table */ parse_input(fil[0],address,8); new_net = net_lookup(address,TRUE); if(new_net != NULLNWPTR && strlen(fil[1]) > 0){ strcpy(new_net->name,fil[1]); /* cprintf("Adding net %s %s \r\n",fil[0],fil[1]); getch(); */ } } else{ if(fflag == 0 && j == 3){ /* update the node information table */ parse_input(fil[0],node_address.net_id,8); new_net = net_lookup(node_address.net_id,FALSE); parse_input(fil[1],node_address.node_id,12); if(new_net != NULLNWPTR && strlen(fil[2]) >0){ new_node = node_lookup(&node_address,&new_net->node_info,TRUE); strcpy(new_node->name,fil[2]); new_node->status = UNKNOWN; /* cprintf("Adding node %s %s %s\r\n",fil[0],fil[1],fil[2]); getch(); */ } } } /* printf("%s",fil); printf("%s\n",fil[0]); printf("%s\n",fil[1]); printf("%s\n",fil[2]);*/ j = 0; } } int read_hex(unsigned char *s,int len) { register int i; unsigned char ch; char tmp[50]; tmp[0]='\0'; i=0; fflush(stdin); cscanf("%[0-9A-Fa-f]",tmp); /* convert ascii to packed hex */ while(i= 'A' && ch <= 'F') ch = ch - 'A' + 10; else ch = ch - '0'; s[i/2] = (i %2) ? (s[i/2] + ch) : ((ch << 4) ) ; i++; } }