17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
23*2e3b6467Skcpoon * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24*2e3b6467Skcpoon * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27*2e3b6467Skcpoon #pragma ident "%Z%%M% %I% %E% SMI"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include <stdio.h>
307c478bd9Sstevel@tonic-gate #include <ctype.h>
317c478bd9Sstevel@tonic-gate #include <string.h>
327c478bd9Sstevel@tonic-gate #include <fcntl.h>
337c478bd9Sstevel@tonic-gate #include <string.h>
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <sys/time.h>
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate #include <sys/socket.h>
387c478bd9Sstevel@tonic-gate #include <sys/sockio.h>
397c478bd9Sstevel@tonic-gate #include <net/if.h>
407c478bd9Sstevel@tonic-gate #include <netinet/in_systm.h>
417c478bd9Sstevel@tonic-gate #include <netinet/in.h>
427c478bd9Sstevel@tonic-gate #include <netinet/ip.h>
437c478bd9Sstevel@tonic-gate #include <netinet/if_ether.h>
447c478bd9Sstevel@tonic-gate #include <netinet/udp.h>
457c478bd9Sstevel@tonic-gate #include "snoop.h"
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate extern char *dlc_header;
487c478bd9Sstevel@tonic-gate
49*2e3b6467Skcpoon int
interpret_udp(int flags,struct udphdr * udp,int iplen,int fraglen)50*2e3b6467Skcpoon interpret_udp(int flags, struct udphdr *udp, int iplen, int fraglen)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate char *data;
537c478bd9Sstevel@tonic-gate int udplen;
547c478bd9Sstevel@tonic-gate int sunrpc;
557c478bd9Sstevel@tonic-gate char *pname;
567c478bd9Sstevel@tonic-gate char buff [32];
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate if (fraglen < sizeof (struct udphdr))
597c478bd9Sstevel@tonic-gate return (fraglen); /* incomplete header */
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate data = (char *)udp + sizeof (struct udphdr);
62*2e3b6467Skcpoon udplen = ntohs((ushort_t)udp->uh_ulen) - sizeof (struct udphdr);
637c478bd9Sstevel@tonic-gate fraglen -= sizeof (struct udphdr);
647c478bd9Sstevel@tonic-gate if (fraglen > udplen)
657c478bd9Sstevel@tonic-gate fraglen = udplen;
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
687c478bd9Sstevel@tonic-gate (void) sprintf(get_sum_line(),
697c478bd9Sstevel@tonic-gate "UDP D=%d S=%d LEN=%d",
707c478bd9Sstevel@tonic-gate ntohs(udp->uh_dport),
717c478bd9Sstevel@tonic-gate ntohs(udp->uh_sport),
72*2e3b6467Skcpoon ntohs((ushort_t)udp->uh_ulen));
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate sunrpc = !reservedport(IPPROTO_UDP, ntohs(udp->uh_dport)) &&
767c478bd9Sstevel@tonic-gate !reservedport(IPPROTO_UDP, ntohs(udp->uh_sport)) &&
777c478bd9Sstevel@tonic-gate valid_rpc(data, udplen);
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
807c478bd9Sstevel@tonic-gate show_header("UDP: ", "UDP Header", udplen);
817c478bd9Sstevel@tonic-gate show_space();
82*2e3b6467Skcpoon (void) sprintf(get_line((char *)(uintptr_t)udp->uh_sport -
83*2e3b6467Skcpoon dlc_header, 1), "Source port = %d", ntohs(udp->uh_sport));
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate if (sunrpc) {
867c478bd9Sstevel@tonic-gate pname = "(Sun RPC)";
877c478bd9Sstevel@tonic-gate } else {
887c478bd9Sstevel@tonic-gate pname = getportname(IPPROTO_UDP, ntohs(udp->uh_dport));
897c478bd9Sstevel@tonic-gate if (pname == NULL) {
907c478bd9Sstevel@tonic-gate pname = "";
917c478bd9Sstevel@tonic-gate } else {
927c478bd9Sstevel@tonic-gate (void) sprintf(buff, "(%s)", pname);
937c478bd9Sstevel@tonic-gate pname = buff;
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate }
96*2e3b6467Skcpoon (void) sprintf(get_line((char *)(uintptr_t)udp->uh_dport -
97*2e3b6467Skcpoon dlc_header, 1), "Destination port = %d %s",
987c478bd9Sstevel@tonic-gate ntohs(udp->uh_dport), pname);
99*2e3b6467Skcpoon (void) sprintf(get_line((char *)(uintptr_t)udp->uh_ulen -
100*2e3b6467Skcpoon dlc_header, 1), "Length = %d %s",
101*2e3b6467Skcpoon ntohs((ushort_t)udp->uh_ulen),
1027c478bd9Sstevel@tonic-gate udplen > fraglen ?
1037c478bd9Sstevel@tonic-gate "(Not all data contained in this fragment)"
1047c478bd9Sstevel@tonic-gate : "");
105*2e3b6467Skcpoon (void) sprintf(get_line((char *)(uintptr_t)udp->uh_sum -
106*2e3b6467Skcpoon dlc_header, 1), "Checksum = %04X %s",
1077c478bd9Sstevel@tonic-gate ntohs(udp->uh_sum),
1087c478bd9Sstevel@tonic-gate udp->uh_sum == 0 ? "(no checksum)" : "");
1097c478bd9Sstevel@tonic-gate show_space();
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate /* go to the next protocol layer */
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate if (!interpret_reserved(flags, IPPROTO_UDP,
1167c478bd9Sstevel@tonic-gate ntohs(udp->uh_sport),
1177c478bd9Sstevel@tonic-gate ntohs(udp->uh_dport),
1187c478bd9Sstevel@tonic-gate data, fraglen)) {
1197c478bd9Sstevel@tonic-gate if (fraglen > 0 && sunrpc)
1207c478bd9Sstevel@tonic-gate interpret_rpc(flags, data, fraglen, IPPROTO_UDP);
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate return (fraglen);
1247c478bd9Sstevel@tonic-gate }
125