Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * Copyright (c) 1988-1990 The Regents of the University of California. | |
3 | * 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 | * this paragraph in its entirety in the documentation or other materials | |
10 | * provided with the distribution, and (3) all advertising materials mentioning | |
11 | * features or use of this software display the following acknowledgement: | |
12 | * ``This product includes software developed by the University of California, | |
13 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of | |
14 | * the University nor the names of its contributors may be used to endorse | |
15 | * or promote products derived from this software without specific prior | |
16 | * written permission. | |
17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED | |
18 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | |
19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
20 | */ | |
21 | ||
22 | #ifndef lint | |
23 | static char rcsid[] = | |
78ed81a3 | 24 | "@(#) $Header: /a/cvs/386BSD/src/contrib/tcpdump/tcpdump/print-udp.c,v 1.1.1.1 1993/06/12 14:42:06 rgrimes Exp $ (LBL)"; |
15637ed4 RG |
25 | #endif |
26 | ||
27 | #include <sys/param.h> | |
28 | #include <sys/types.h> | |
29 | #include <sys/socket.h> | |
30 | #include <netinet/in.h> | |
31 | #include <netinet/in_systm.h> | |
32 | #include <netinet/ip.h> | |
33 | #include <netinet/ip_var.h> | |
34 | #include <netinet/udp.h> | |
35 | #include <netinet/udp_var.h> | |
36 | ||
37 | #include <arpa/nameser.h> | |
38 | #include <arpa/tftp.h> | |
39 | #include <errno.h> | |
40 | #include <sys/time.h> | |
78ed81a3 | 41 | #include <rpc/rpc.h> |
15637ed4 RG |
42 | |
43 | #include "interface.h" | |
44 | /* These must come after interface.h for BSD. */ | |
45 | #if BSD >= 199006 | |
46 | #include <sys/ucred.h> | |
47 | #include <nfs/nfsv2.h> | |
48 | #endif | |
49 | #include <nfs/nfs.h> | |
50 | ||
51 | #include "addrtoname.h" | |
52 | #include "appletalk.h" | |
53 | ||
54 | #include "bootp.h" | |
55 | ||
56 | /* XXX probably should use getservbyname() and cache answers */ | |
57 | #define TFTP_PORT 69 /*XXX*/ | |
58 | #define SUNRPC_PORT 111 /*XXX*/ | |
59 | #define SNMP_PORT 161 /*XXX*/ | |
60 | #define NTP_PORT 123 /*XXX*/ | |
61 | #define SNMPTRAP_PORT 162 /*XXX*/ | |
62 | #define RIP_PORT 520 /*XXX*/ | |
63 | ||
64 | void | |
65 | udp_print(up, length, ip) | |
66 | register struct udphdr *up; | |
67 | int length; | |
68 | register struct ip *ip; | |
69 | { | |
70 | register u_char *cp = (u_char *)(up + 1); | |
71 | ||
72 | if (cp > snapend) { | |
73 | printf("[|udp]"); | |
74 | return; | |
75 | } | |
76 | if (length < sizeof(struct udphdr)) { | |
77 | (void)printf(" truncated-udp %d", length); | |
78 | return; | |
79 | } | |
80 | length -= sizeof(struct udphdr); | |
81 | ||
82 | NTOHS(up->uh_sport); | |
83 | NTOHS(up->uh_dport); | |
84 | NTOHS(up->uh_ulen); | |
85 | ||
86 | if (! qflag) { | |
87 | register struct rpc_msg *rp; | |
88 | enum msg_type direction; | |
89 | ||
90 | rp = (struct rpc_msg *)(up + 1); | |
91 | direction = (enum msg_type)ntohl(rp->rm_direction); | |
92 | if (up->uh_dport == NFS_PORT && direction == CALL) { | |
93 | nfsreq_print(rp, length, ip); | |
94 | return; | |
95 | } | |
96 | else if (up->uh_sport == NFS_PORT && direction == REPLY) { | |
97 | nfsreply_print(rp, length, ip); | |
98 | return; | |
99 | } | |
100 | #ifdef notdef | |
101 | else if (up->uh_dport == SUNRPC_PORT && direction == CALL) { | |
102 | sunrpcrequest_print(rp, length, ip); | |
103 | return; | |
104 | } | |
105 | #endif | |
106 | else if (cp[2] == 2 && (atalk_port(up->uh_sport) || | |
107 | atalk_port(up->uh_dport))) { | |
108 | ddp_print((struct atDDP *)(&cp[3]), length - 3); | |
109 | return; | |
110 | } | |
111 | } | |
112 | (void)printf("%s.%s > %s.%s:", | |
113 | ipaddr_string(&ip->ip_src), udpport_string(up->uh_sport), | |
114 | ipaddr_string(&ip->ip_dst), udpport_string(up->uh_dport)); | |
115 | ||
116 | if (!qflag) { | |
117 | #define ISPORT(p) (up->uh_dport == (p) || up->uh_sport == (p)) | |
118 | if (ISPORT(NAMESERVER_PORT)) | |
119 | ns_print((HEADER *)(up + 1), length); | |
120 | else if (ISPORT(TFTP_PORT)) | |
121 | tftp_print((struct tftphdr *)(up + 1), length); | |
122 | else if (ISPORT(IPPORT_BOOTPC) || ISPORT(IPPORT_BOOTPS)) | |
123 | bootp_print((struct bootp *)(up + 1), length, | |
124 | up->uh_sport, up->uh_dport); | |
125 | else if (up->uh_dport == RIP_PORT) | |
126 | rip_print((u_char *)(up + 1), length); | |
127 | else if (ISPORT(SNMP_PORT) || ISPORT(SNMPTRAP_PORT)) | |
128 | snmp_print((u_char *)(up + 1), length); | |
129 | else if (ISPORT(NTP_PORT)) | |
130 | ntp_print((struct ntpdata *)(up + 1), length); | |
131 | else | |
132 | (void)printf(" udp %d", up->uh_ulen - sizeof(*up)); | |
133 | #undef ISPORT | |
134 | } else | |
135 | (void)printf(" udp %d", up->uh_ulen - sizeof(*up)); | |
136 | } |