/* * TCPVIEW * * Author: Martin Hunt * Networks and Distributed Computing * Computing & Communications * University of Washington * Administration Building, AG-44 * Seattle, WA 98195 * Internet: martinh@cac.washington.edu * * * Copyright 1992 by the University of Washington * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, provided * that the above copyright notice appears in all copies and that both the * above copyright notice and this permission notice appear in supporting * documentation, and that the name of the University of Washington not be * used in advertising or publicity pertaining to distribution of the software * without specific, written prior permission. This software is made * available "as is", and * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ #ifndef lint static char rcsid[] = "@(#) $Header: /usr/staff/martinh/tcpview/RCS/bgp.c,v 1.2 1993/04/22 20:11:19 martinh Exp $ (UW)"; #endif #include #include #include #include "os.h" #include "md.h" int PrintFrames = 0; #ifdef __STDC__ int getbyte(void); u_short getword(void); u_long getlword(void); #else int getbyte(); u_short getword(); u_long getlword(); #endif char *msg_type[]= { "null","OPEN","UPDATE","NOTIFICATION","KEEPALIVE" }; char *origin_str[] = { "IGP","EGP","INCOMPLETE" }; void bgp_open(), bgp_update(), bgp_note(), bgp_keepalive(); void mess_err(), update_err(), open_err(); int getattributes(); void (*type_func[])() = { NULL, bgp_open, bgp_update, bgp_note, bgp_keepalive }; main(argc, argv) int argc; char *argv[]; { int c, i=0; int type; int length; if( argc > 1 ) if( *argv[1]=='-' && argv[1][1]=='f' ) PrintFrames=1; sync: /* look for 16 0xFF octets */ while( (c = getbyte()) != EOF) { if( c == 0xFF ) { i++; if( i == 16 ) break; } else i = 0; } while(1) { length = getword(); if( length < 19 || length > 4096 ) goto sync; type = getbyte(); if( type < 1 || type > 4 ) goto sync; (type_func[type])(length); /* eat Marker */ for(i=0;i<16;i++) if(getbyte()==EOF) exit(0); } } void bgp_open(length) int length; { int i, min_length; u_short asn, htime, version, auth; long id; version = getbyte(); if(version > 2) min_length = 29; else min_length = 25; if( length < min_length) printf("OPEN: ERROR has a length of %d. Must be >= %d\n",length,min_length); asn = getword(); htime = getword(); if(version > 2) id = getlword(); auth = getbyte(); if(version > 2) printf("OPEN: version: %d, asn=%d, htime=%d, id=%d auth=%d\n", version,asn,htime,id,auth); else printf("OPEN version: %d, asn=%d, htime=%d, auth=%d\n", version,asn,htime,auth); if( length > min_length ) { printf("WARNING: authentication data present\n"); /*fread(&auth_data,length-min_length,1,stdin); */ } /* eat any excess */ for(i=min_length;i0 && code <7 ) { printf("%s: ",e_msg[code]); switch (code) { case 1: mess_err(sub, data_len); break; case 2: open_err(sub, data_len); break; case 3: update_err(sub, data_len); break; default: for(i=21;i0 && subtype <11) { printf("%s",update_error[subtype]); if(getattributes(length)) printf("\nERROR parsing subcode data"); putchar('\n'); } else { printf("bad subtype (%d)\n",subtype); for(i=0;i2) printf("ORIGIN: unknown "); else printf("ORIGIN: %s ",origin_str[origin]); break; case 2: printf("ASN_PATH: "); for(i=0;i