[insert project logo here (125x200px max)] Navigator Mailinglists Please report any errors or ommissions you find to our `Help' mailinglist, or post a message in the Forums. Copyright and Licensing Information Snap is (c) Jonathan T. Moore, 1999-2002 and licensed under the GNU General Public License (GPL). All other parts of Splash are (c) Willem de Bruijn, 2002-2003 and licensed under the BSD Open Source License. All sourcecode is made publicly available. Acknowledgement Splash and the Splash website are hosted by SourceForge.net |
Splash - DocumentationSNMP Plus a Lightweight API for SNAP Handlingsnap-1.1-wjdb/utils/snapdis.cGo to the documentation of this file.00001 /* snap-1.0. Copyright (C) 2000 by Jonathan T. Moore and Michael Hicks. 00002 * 00003 * snapdis.c : SNAP disassembler. Goes from wire-format back to 00004 * (ascii) SNAP assembly language. 00005 * 00006 * $Id: snapdis.c,v 1.1 2002/12/22 16:20:16 wdebruij Exp $ 00007 */ 00008 00009 #include <stdio.h> 00010 #include <sys/types.h> 00011 #include <sys/stat.h> 00012 #include <string.h> 00013 #include <fcntl.h> 00014 #include <unistd.h> 00015 #include "../lib/bytecode.h" 00016 #include "../lib/packet.h" 00017 #include "../lib/io.h" 00018 #include "../lib/memalloc.h" 00019 #include "../lib/d_printf.h" 00020 00021 int infd; /* input file descriptor */ 00022 FILE *outfile; /* output file pointer */ 00023 00024 extern char *basename(const char *); 00025 00026 void parse_cmdline(int argc, char **argv); 00027 00028 int main(int argc, char **argv) { 00029 buffer_t buf; 00030 packet_t *p; 00031 int packet_lenb; 00032 00033 d_printf(10,"%s:%d: starting up\n",__FILE__,__LINE__); 00034 00035 outfile = stdout; 00036 00037 parse_cmdline(argc,argv); 00038 packet_lenb = file_to_str(infd,&buf); 00039 p = unmarshal_packet(buf.s,packet_lenb,buf.lenb); 00040 if (p != NULL) { 00041 fprintf_packet(outfile,p); 00042 fflush(outfile); 00043 return(0); 00044 } 00045 else 00046 return(1); 00047 } 00048 00049 void usage(int argc, char **argv) { 00050 printf("usage: %s [-?] [-o outfile] infile\n",basename(argv[0])); 00051 printf("\t-? : print this help\n"); 00052 printf("\t-o : set the output file name (default = stdout)\n"); 00053 } 00054 00055 void parse_cmdline(int argc, char **argv) { 00056 char *opts = "?o:"; 00057 char c; 00058 int args_expected = 1; 00059 int args_processed = 0; 00060 int argidx; 00061 char *outfilename; 00062 char *infilename; 00063 00064 while((c = getopt(argc,argv,opts)) != EOF) { 00065 switch(c) { 00066 case '?': 00067 usage(argc,argv); 00068 exit(1); 00069 case 'o': 00070 outfilename = optarg; 00071 if (strcmp(outfilename,"-") != 0) { 00072 outfile = fopen(outfilename,"w"); 00073 if (outfile == NULL) { 00074 fprintf(stderr,"%s: unable to open file \"%s\" for output\n", 00075 basename(argv[0]),outfilename); 00076 fflush(stderr); 00077 exit(1); 00078 } 00079 } 00080 break; 00081 } 00082 } 00083 argidx = optind; 00084 while(args_processed < args_expected) { 00085 if (argidx >= argc) { 00086 /* missing arguments */ 00087 printf("%s: missing argument(s)\n",basename(argv[0])); 00088 usage(argc,argv); 00089 exit(1); 00090 } 00091 switch(args_processed) { 00092 case 0: 00093 infilename = argv[argidx]; 00094 if (strcmp(infilename,"-") != 0) { 00095 infd = open(infilename,O_RDONLY); 00096 if (infd < 0) { 00097 fprintf(stderr,"%s: unable to open file \"%s\" for input\n", 00098 basename(argv[0]),infilename); 00099 fflush(stderr); 00100 exit(1); 00101 } 00102 } 00103 break; 00104 } 00105 argidx++; 00106 args_processed++; 00107 } 00108 if (argidx < argc) { 00109 /* extra arguments */ 00110 printf("%s: extra argument(s)\n",basename(argv[0])); 00111 usage(argc,argv); 00112 exit(1); 00113 } 00114 return; 00115 } 00116 |