2 * Routines for UDP packet disassembly
4 * $Id: packet-udp.c,v 1.2 1998/09/16 03:22:13 gerald Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
47 dissect_udp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
49 guint16 uh_sport, uh_dport, uh_ulen, uh_sum;
50 GtkWidget *udp_tree, *ti;
52 /* To do: Check for {cap len,pkt len} < struct len */
53 uh = (e_udphdr *) &pd[offset];
54 uh_sport = ntohs(uh->uh_sport);
55 uh_dport = ntohs(uh->uh_dport);
56 uh_ulen = ntohs(uh->uh_ulen);
57 uh_sum = ntohs(uh->uh_sum);
59 if (fd->win_info[0]) {
60 strcpy(fd->win_info[3], "UDP");
61 sprintf(fd->win_info[4], "Source port: %s Destination port: %s",
62 get_udp_port(uh_sport), get_udp_port(uh_dport));
66 ti = add_item_to_tree(GTK_WIDGET(tree), offset, 8,
67 "User Datagram Protocol");
68 udp_tree = gtk_tree_new();
69 add_subtree(ti, udp_tree, ETT_UDP);
70 add_item_to_tree(udp_tree, offset, 2, "Source port: %s", get_udp_port(uh_sport));
71 add_item_to_tree(udp_tree, offset + 2, 2, "Destination port: %s", get_udp_port(uh_dport));
72 add_item_to_tree(udp_tree, offset + 4, 2, "Length: %d", uh_ulen);
73 add_item_to_tree(udp_tree, offset + 6, 2, "Checksum: 0x%04x", uh_sum);
76 /* Skip over header */
79 /* To do: make sure we aren't screwing ourselves with the MIN call. */
80 switch (MIN(uh_sport, uh_dport)) {
82 dissect_bootp(pd, offset, fd, tree);
85 dissect_dns(pd, offset, fd, tree);
88 /* we should check the source port too (RIP: UDP src and dst port 520) */
89 dissect_rip(pd, offset, fd, tree);
92 dissect_data(pd, offset, fd, tree);