1 /*
2  * TCPVIEW
3  *
4  * Author:	Martin Hunt
5  *		Networks and Distributed Computing
6  *		Computing & Communications
7  *		University of Washington
8  *		Administration Building, AG-44
9  *		Seattle, WA  98195
10  *		Internet: martinh@cac.washington.edu
11  *
12  *
13  * Copyright 1992 by the University of Washington
14  *
15  * Permission to use, copy, modify, and distribute this software and its
16  * documentation for any purpose and without fee is hereby granted, provided
17  * that the above copyright notice appears in all copies and that both the
18  * above copyright notice and this permission notice appear in supporting
19  * documentation, and that the name of the University of Washington not be
20  * used in advertising or publicity pertaining to distribution of the software
21  * without specific, written prior permission.  This software is made
22  * available "as is", and
23  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
24  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
26  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
27  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
28  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
29  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
30  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31  *
32  */
33 
34 #ifndef lint
35 static char rcsid[] =
36     "@(#) $Header: /usr/staff/martinh/tcpview/RCS/detail-udp.c,v 1.4 1993/04/22 20:17:56 martinh Exp $ (UW)";
37 #endif
38 
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <netinet/in_systm.h>
44 #include <netinet/ip.h>
45 #include <netinet/ip_var.h>
46 #include <netinet/udp.h>
47 #include <netinet/udp_var.h>
48 
49 #include <arpa/nameser.h>
50 #include <arpa/tftp.h>
51 #include <errno.h>
52 #include <sys/time.h>
53 #include <rpc/types.h>
54 #include <rpc/xdr.h>
55 #include <rpc/auth.h>
56 #include <rpc/auth_unix.h>
57 #include <rpc/svc.h>
58 #include <rpc/rpc_msg.h>
59 #include <sys/ucred.h>
60 #include <sys/mount.h>
61 #if defined(__FreeBSD_version) && __FreeBSD_version >= 800100
62 #include <vfs/nfs/nfsport.h>
63 #include <vfs/nfs/rpcv2.h>
64 #include <vfs/nfs/nfsproto.h>
65 #else
66 #include <vfs/nfs/rpcv2.h>
67 #include <vfs/nfs/nfsproto.h>
68 #endif
69 
70 #include "interface.h"
71 #include "addrtoname.h"
72 #include "appletalk.h"
73 
74 #include "bootp.h"
75 
76 #include "tcpview.h"
77 
78 extern u_short D_Src_Port, D_Dst_Port;
79 extern u_short TFTP_PORT, SNMP_PORT, NTP_PORT, SNMPTRAP_PORT, RIP_PORT, SUNRPC_PORT;
80 
detail_udp(up,length)81 void detail_udp( up, length )
82 register struct udphdr *up;
83 u_short length;
84 {
85   register u_char  *cp = (u_char *)(up + 1);
86   u_short sport, dport, len;
87   register struct rpc_msg *rp;
88   enum msg_type direction;
89 
90 
91   if (Phdr->caplen-Offset < sizeof(struct udphdr)) {
92     printf("*** UDP (truncated) ***\n");
93     hex(0, Phdr->caplen - Offset - 1);
94     return;
95   }
96 
97   D_Src_Port = sport = ntohs(up->uh_sport);
98   D_Dst_Port = dport = ntohs(up->uh_dport);
99   len   = ntohs(up->uh_ulen);
100 
101   printf("----- UDP Header -----\n\n");
102   hex( 0, sizeof(struct udphdr) - 1);      /* header */
103 
104   printf("Source port = %d  ( %s )\n",sport,udpport_string(sport));
105   printf("Destination port = %d  ( %s )\n",dport,udpport_string(dport));
106   if(len == length)
107     printf("Length = %d\n",len);
108   else
109     printf("Length = %d  Should be %d according to IP!\n",len,length);
110   printf("Checksum = %x\n\n",ntohs(up->uh_sum));
111   hex( -1, -1 );                         /* blank line */
112   hex( 0, 1 );                           /* source port */
113   hex( 2, 3 );                           /* dest port */
114   hex( 4, 5 );                           /* length */
115   hex( 6, 7 );                           /* checksum */
116   hex( -1, -1 );                         /* blank line */
117 
118   length -= sizeof(struct udphdr);
119   Offset += sizeof(struct udphdr);
120 
121   /*
122     rp = (struct rpc_msg *)(up + 1);
123     direction = (enum msg_type)ntohl(rp->rm_direction);
124     if (up->uh_dport == NFS_PORT && direction == CALL) {
125     nfsreq_print(rp, length, ip);
126     return;
127     }
128     else if (up->uh_sport == NFS_PORT && direction==REPLY) {
129     nfsreply_print(rp, length, ip);
130     return;
131     }
132     else if (cp[2] == 2 && (atalk_port(up->uh_sport) ||
133     atalk_port(up->uh_dport))) {
134     ddp_print((struct atDDP *)(&cp[3]), length - 3);
135     return;
136     }
137     */
138 
139 #define ISPORT(p) (dport == (p) || sport == (p))
140 
141   /*
142     if (ISPORT(NAMESERVER_PORT))
143     ns_print((HEADER *)(up + 1), length);
144     else if (ISPORT(TFTP_PORT))
145     tftp_print((struct tftphdr *)(up + 1), length);
146     else if (ISPORT(IPPORT_BOOTPC) || ISPORT(IPPORT_BOOTPS))
147     bootp_print((struct bootp *)(up + 1), length,
148     up->uh_sport, up->uh_dport);
149     else
150     */
151   if ( ISPORT(RIP_PORT) )
152     detail_rip((u_char *)(up + 1), length);
153   else if ( ISPORT(NAMESERVER_PORT) )
154     detail_domain((u_char *)(up + 1), length);
155   else if (ISPORT(SNMP_PORT) || ISPORT(SNMPTRAP_PORT))
156     detail_snmp((u_char *)(up + 1), length);
157     /*
158     else if (ISPORT(NTP_PORT))
159     ntp_print((struct ntpdata *)(up + 1), length);
160     else
161     (void)printf(" udp %d", up->uh_ulen - sizeof(*up));
162     */
163 #undef ISPORT
164 }
165 
166 
167 
168 
169 
170 
171 
172 
173