/* File : main.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. */ #define TIME # include "help.h" # include "ipxwatch.h" # include "yapcbr.h" # include "sap.h" # include "ipxrip.h" # include "diag.h" /***************************** Externs defined in screen.c *****************/ extern void format_ether(ETH_IPX *pkt,unsigned char *new_disp_buf); /***************************** Externs defined in parse.c ******************/ extern int read_hex(unsigned char *s,int len); /****************************** Externs defined in yapcbr.c ****************/ extern int release_type (int intno,int handle); /**************************** externs defined in sap.c *********************/ extern void slist(); extern int hash_addr(char *s); extern int hash_lookup(int hashret,unsigned char *destination ); /*************************** externs defined in ipxrip.c *******************/ extern void nlist(); /************************** externs defined in timer.c *********************/ extern void init_timer(); extern void release_timer(); /************************** externs defined in diag.c **********************/ extern void node_list(); extern struct network_info *net_lookup(BYTE *net_id, int append_flag); /************* defined in this file *************************************/ int find_pkt_type(unsigned char *pkt); void check_options(ETH_IPX *pkt,int type); void parse_command(int option); void disp_pkt(ETH_IPX *pkt,int type); void init_win(); void disp_statistics(); /*************** global variables *****************************************/ int rx_head =0,rx_tail=0,rx_count=0; unsigned int rcv_count=0,lost_count =0; int flag=FALSE,send_diag=TRUE; int pres,prev,ptype; int log_data=FALSE; int command = 6; /* initially set option to match all pkt's */ struct ipxpktdv Ipxpktdv; /* packet driver interface table */ char *novel_pkts[MAX_PKT_TYPES] = {"NCP","SAP","RIP","NB","DIAG", "IPX","SPX","NONE"}; struct pkt_type_stat statistics[MAX_PKT_TYPES]; /* pkt type statistics info */ struct rxstruct rx[MAX_QSIZ] ; /* global packet buffer, keep it large enough */ /*** server information table *******/ struct sap_tbl *sap_lookup[MAX_PRIME]; /* choose MAX_PRIME large enough to avoid collisons */ /*** route information table ********/ struct rip_table *rip_lookup[MAX_PRIME]; struct rxstruct *rxptr; struct time t; /* to store the current time */ /*************** buffer ptrs ********************/ struct sap_tbl *sap_q_t, *sap_q_h; struct rip_table *rip_q_t, *rip_q_h; /*************** network information table, for diagnostics ***********/ struct network_info *network_info_table[MAX_PRIME], *current_net, *pred_net; NODE_INFO *current_node; /*************************************************************/ FILE *fp; /* pointer to the log file */ unsigned char src[7],dest[7],src_dest[13]; /***************************************************************************/ INTERNET_ADDRESS dest_net; /* destination network to which diagnostic pkts are to be sent */ BYTE all_nodes[] = {0xff,0xff,0xff,0xff,0xff,0xff}; BYTE same_net[] = {0x00,0x00,0x00,0x00}; BYTE diag_sock[] = {0x04,0x56}; BYTE my_router[] = {0x00,0x00,0x00,0x00,0x00,0x00}; struct my_route my_route_info; /* my net_id router id, etc ... */ /**************************************************************************/ void main(int argc, char *argv[]) { int type,i,bflag,ch,ether_type,discard,brodcst = 0; unsigned char *pkt,*old_disp_buff,*new_disp_buff,*tmp; char buff[80]; WORD pkt_length; directvideo=1; /* direct o/p to display ram */ printf("\nNovell IPX Protocol Analyzer version 1.0\n"); printf("Copyright (C) 1992 Indian Institute of Technology Bombay\n"); printf("This Program is free software see the file COPYING for\n"); printf("details; NO WARRANTY see the file COPYING for details\n\n"); /* initialize the hash tables */ for(i=0;i \n where a - arcnet b - ethernet\n"); exit(-1); } ch = argv[1][1]; if(strcmp(argv[1],"b")==0) ether_type = ETHERNET_II; else { if(strcmp(argv[1],"a")==0) ether_type = ARCETHER; else { fprintf(stderr,"Unknown type %s valid types are a or b \n",argv[1]); exit(-1); } } new_disp_buff = (unsigned char *)calloc(80,sizeof(char)); old_disp_buff = (unsigned char *)calloc(80,sizeof(char)); if(new_disp_buff == NULL || old_disp_buff == NULL){ fprintf(stderr,"Not enough memory\n"); exit(-1); } /* initialize the packet driver */ rxptr = &rx[rx_head]; if(pkt_init(argv[2],"IPXNET",ether_type) ==-1){ exit(-1); } /* initialise statistics counters */ for(i=0;ircv_flag == SET){ /* There is a packet !! */ if(( rxptr->rcv_buffer.destination[0] & 0xff) == 0xff ){ /* is it a broadcast pkt ? */ brodcst++; bflag=TRUE; } /* send diagnostic configuration request packet ? */ if(send_diag == TRUE){ if(current_net != 0) send_diag_pkt(dest_net.node_id,current_net->net_id); else send_diag_pkt(dest_net.node_id,dest_net.net_id); send_diag = FALSE; } /* bzero(new_disp_buff,80); */ new_disp_buff[0] = '\0'; format_ether(&rxptr->rcv_buffer,new_disp_buff); /* sprintf(new_disp_buff+strlen(new_disp_buff),"h %u t %u f %u",rx_head,rx_tail,rxptr->rcv_flag);*/ type = proc_ipx_pkt(&rxptr->rcv_buffer.pkt,new_disp_buff+strlen(new_disp_buff),bflag); /* update statistics information */ statistics[type].pkt_count++; statistics[type].bytes_in = statistics[type].bytes_in + (long) rxptr->len; check_options(&rxptr->rcv_buffer,type); if(flag == TRUE){ if(pres != prev) { gotoxy(2,prev); restore(); cprintf("%.78s",old_disp_buff); } gotoxy(2,pres); cprintf(" "); reverse(); gotoxy(2,pres); cprintf("%.78s",new_disp_buff); if(log_data==TRUE){ if(fprintf(fp,"%s\n",new_disp_buff) == EOF){ gotoxy(1,25); cprintf("Error Writing to log file - Press any key to continue"); fclose(fp); log_data=FALSE; } } restore(); prev=pres; /* swap the two buffers */ tmp = old_disp_buff; old_disp_buff = new_disp_buff; new_disp_buff = tmp; pres++; if(pres==24) pres = 4; } /* if flag */ rxptr->rcv_flag = RESET; rx_head++; if(rx_head == MAX_QSIZ) /* wrap around */ rx_head = 0; rx_count--; } /* if */ if(kbhit()){ ch = toupper(getch()); if(ch == 'Q') break; parse_command(ch); } flag=FALSE; /* display time */ gettime(&t); gotoxy(66,1); reverse(); cprintf(" %2d:%02d:%02d",t.ti_hour, t.ti_min, t.ti_sec); gotoxy(43,25); cprintf("bcasts %-.5u Pkts recvd % -.5u" ,brodcst,rcv_count); restore(); } /* while */ release_timer(); /*--------------------------------------------------------*/ restore(); if(release_type(Ipxpktdv.intno,Ipxpktdv.handle) == -1){ fprintf(stderr,"Error releasing driver\n"); exit(-1); } _setcursortype(_NORMALCURSOR); if(log_data == TRUE){ fflush(fp); fclose(fp); } exit(0); } void check_options(ETH_IPX *pkt,int type) { flag=FALSE; switch(command){ case 0: /* Match on source */ if(memcmp(pkt->source,src,ETHER_ADDR_LEN) == 0) flag = TRUE; break; case 1: /* Match on destination */ if(memcmp(pkt->destination,dest,ETHER_ADDR_LEN) == 0) flag = TRUE; break; case 2: /* Match on source destination */ if(memcmp(pkt,src_dest,12) == 0) flag = TRUE; break; case 3: /* match on pkt type */ if(type == ptype) flag = TRUE; break; case 4: /* match on network address */ break; case 5: init_win(); break; case 6: /* match all packet types */ flag=TRUE; break; default : break; } if(type == NONE) flag = FALSE; } void parse_command(int option) { char temp[10],logfile[13]; char buffer[4500]; int i; _setcursortype(_NORMALCURSOR); reverse(); switch(option){ case 'A' : gotoxy(1,25); cprintf("Match all packets "); command = 6; break; case 'B' : _setcursortype(_NOCURSOR); gettext(1, 1, 80, 25, buffer); disp_statistics(); window(1,1,80,25); puttext(1,1,80,25,buffer); break; case 'C' : init_win(); break; case 'D' : gotoxy(1,25); cprintf("Enter destination address in hex : "); read_hex(dest,12); command = 1; break; case 'P' : gotoxy(1,25); cprintf("Enter source destination pair in hex : "); read_hex(src_dest,25); command = 2; break; case 'F' : gotoxy(1,25); if(fclose(fp) == 0) cprintf("Log file closed - Press any key to continue"); else cprintf("Error closing log file - Press any key to continue"); log_data =FALSE; getch(); break; case 'H' : case 'h' : /* display this help screen */ _setcursortype(_NOCURSOR); gettext(1, 1, 80, 25, buffer); make_win(19,5,70,22,2,"HELP"); disp_mesg("ESC Close Window"); for(i=0;i