print-tftp.c (146773) | print-tftp.c (172683) |
---|---|
1/* 2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 9 unchanged lines hidden (view full) --- 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * 21 * Format and print trivial file transfer protocol packets. 22 */ 23 24#ifndef lint 25static const char rcsid[] _U_ = | 1/* 2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 9 unchanged lines hidden (view full) --- 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * 21 * Format and print trivial file transfer protocol packets. 22 */ 23 24#ifndef lint 25static const char rcsid[] _U_ = |
26 "@(#) $Header: /tcpdump/master/tcpdump/print-tftp.c,v 1.37 2003/11/16 09:36:40 guy Exp $ (LBL)"; | 26 "@(#) $Header: /tcpdump/master/tcpdump/print-tftp.c,v 1.37.2.1 2007/09/14 01:03:12 guy Exp $ (LBL)"; |
27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#include <tcpdump-stdinc.h> 34 35#ifdef SEGSIZE 36#undef SEGSIZE /* SINIX sucks */ 37#endif | 27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#include <tcpdump-stdinc.h> 34 35#ifdef SEGSIZE 36#undef SEGSIZE /* SINIX sucks */ 37#endif |
38#include <arpa/tftp.h> | |
39 40#include <stdio.h> 41#include <string.h> 42 43#include "interface.h" 44#include "addrtoname.h" 45#include "extract.h" | 38 39#include <stdio.h> 40#include <string.h> 41 42#include "interface.h" 43#include "addrtoname.h" 44#include "extract.h" |
45#include "tftp.h" |
|
46 47/* op code to string mapping */ 48static struct tok op2str[] = { 49 { RRQ, "RRQ" }, /* read request */ 50 { WRQ, "WRQ" }, /* write request */ 51 { DATA, "DATA" }, /* data packet */ 52 { ACK, "ACK" }, /* acknowledgement */ 53 { ERROR, "ERROR" }, /* error code */ | 46 47/* op code to string mapping */ 48static struct tok op2str[] = { 49 { RRQ, "RRQ" }, /* read request */ 50 { WRQ, "WRQ" }, /* write request */ 51 { DATA, "DATA" }, /* data packet */ 52 { ACK, "ACK" }, /* acknowledgement */ 53 { ERROR, "ERROR" }, /* error code */ |
54 { OACK, "OACK" }, /* option acknowledgement */ |
|
54 { 0, NULL } 55}; 56 57/* error code to string mapping */ 58static struct tok err2str[] = { 59 { EUNDEF, "EUNDEF" }, /* not defined */ 60 { ENOTFOUND, "ENOTFOUND" }, /* file not found */ 61 { EACCESS, "EACCESS" }, /* access violation */ --- 30 unchanged lines hidden (view full) --- 92 /* Bail if bogus opcode */ 93 if (*cp == 't') 94 return; 95 96 switch (opcode) { 97 98 case RRQ: 99 case WRQ: | 55 { 0, NULL } 56}; 57 58/* error code to string mapping */ 59static struct tok err2str[] = { 60 { EUNDEF, "EUNDEF" }, /* not defined */ 61 { ENOTFOUND, "ENOTFOUND" }, /* file not found */ 62 { EACCESS, "EACCESS" }, /* access violation */ --- 30 unchanged lines hidden (view full) --- 93 /* Bail if bogus opcode */ 94 if (*cp == 't') 95 return; 96 97 switch (opcode) { 98 99 case RRQ: 100 case WRQ: |
101 case OACK: |
|
100 /* 101 * XXX Not all arpa/tftp.h's specify th_stuff as any 102 * array; use address of th_block instead 103 */ 104#ifdef notdef 105 p = (u_char *)tp->th_stuff; 106#else 107 p = (u_char *)&tp->th_block; 108#endif | 102 /* 103 * XXX Not all arpa/tftp.h's specify th_stuff as any 104 * array; use address of th_block instead 105 */ 106#ifdef notdef 107 p = (u_char *)tp->th_stuff; 108#else 109 p = (u_char *)&tp->th_block; 110#endif |
109 fputs(" \"", stdout); | 111 putchar(' '); 112 /* Print filename or first option */ 113 if (opcode != OACK) 114 putchar('"'); |
110 i = fn_print(p, snapend); | 115 i = fn_print(p, snapend); |
111 putchar('"'); | 116 if (opcode != OACK) 117 putchar('"'); |
112 | 118 |
113 /* Print the mode and any options */ | 119 /* Print the mode (RRQ and WRQ only) and any options */ |
114 while ((p = (const u_char *)strchr((const char *)p, '\0')) != NULL) { 115 if (length <= (u_int)(p - (const u_char *)&tp->th_block)) 116 break; 117 p++; 118 if (*p != '\0') { 119 putchar(' '); 120 fn_print(p, snapend); 121 } --- 7 unchanged lines hidden (view full) --- 129 case DATA: 130 TCHECK(tp->th_block); 131 printf(" block %d", EXTRACT_16BITS(&tp->th_block)); 132 break; 133 134 case ERROR: 135 /* Print error code string */ 136 TCHECK(tp->th_code); | 120 while ((p = (const u_char *)strchr((const char *)p, '\0')) != NULL) { 121 if (length <= (u_int)(p - (const u_char *)&tp->th_block)) 122 break; 123 p++; 124 if (*p != '\0') { 125 putchar(' '); 126 fn_print(p, snapend); 127 } --- 7 unchanged lines hidden (view full) --- 135 case DATA: 136 TCHECK(tp->th_block); 137 printf(" block %d", EXTRACT_16BITS(&tp->th_block)); 138 break; 139 140 case ERROR: 141 /* Print error code string */ 142 TCHECK(tp->th_code); |
137 printf(" %s ", tok2str(err2str, "tftp-err-#%d \"", | 143 printf(" %s \"", tok2str(err2str, "tftp-err-#%d \"", |
138 EXTRACT_16BITS(&tp->th_code))); 139 /* Print error message string */ 140 i = fn_print((const u_char *)tp->th_data, snapend); 141 putchar('"'); 142 if (i) 143 goto trunc; 144 break; 145 146 default: 147 /* We shouldn't get here */ 148 printf("(unknown #%d)", opcode); 149 break; 150 } 151 return; 152trunc: 153 fputs(tstr, stdout); 154 return; 155} | 144 EXTRACT_16BITS(&tp->th_code))); 145 /* Print error message string */ 146 i = fn_print((const u_char *)tp->th_data, snapend); 147 putchar('"'); 148 if (i) 149 goto trunc; 150 break; 151 152 default: 153 /* We shouldn't get here */ 154 printf("(unknown #%d)", opcode); 155 break; 156 } 157 return; 158trunc: 159 fputs(tstr, stdout); 160 return; 161} |