/*- * Copyright (c) 2001-2005 Christian S.J. Peron * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static const char rcsid[] = \ "@(#) $Header: /usr/cvs/ipex/udp_print.c,v 1.7 2005/03/10 01:24:16 modulus Exp $"; #endif #include "ipex_includes.h" int print_udp(u_char *b, struct pcap_pkthdr *h, u_char *p) { char *d; int len; struct ip *ip = (struct ip *)(p + opts.loffset); unsigned ip_hl = (ip->ip_hl * 0x4); unsigned ip_off = ntohs(ip->ip_off); unsigned frag = ip_off & (IP_MF|IP_OFFMASK); unsigned frag_off = frag ? (ip_off & IP_OFFMASK) * 8:0; struct udphdr *udp = (struct udphdr *)(((char *)ip) + ip_hl); unsigned udp_off = (frag) ? 0 : sizeof(struct udphdr); struct ehdr *mhdr = NULL; u_32_t *sa, *da; d = ((char *)udp) + (udp_off); len = (ntohs(ip->ip_len) - ip_hl - udp_off); sa = (u_32_t *)&ip->ip_src; da = (u_32_t *)&ip->ip_dst; if (opts.Lflag) mhdr = process_link_headers(b, h, p); #if (defined(USE_DUMB_UDP_HEADERS)) printf("%s %s%s:%s ", time_stamp(&h->ts, x->thiszone), (opts.Lflags ? mhdr->smac : ""), hostname(4, sa), portname(opts.pflag, "udp", ntohs(udp->source))); printf( "> %s%s:%s udp", (opts.Lflag ? mhdr->dmac : ""), hostname(4, da), portname(opts.pflag, "udp", ntohs(udp->dest))); #else printf("%s %s%s:%s ", time_stamp(&h->ts, opts.thiszone), (opts.Lflag ? mhdr->smac : ""), hostname(4, sa), portname(opts.nflag, "udp", udp->uh_sport)); printf("> %s%s:%s udp", (opts.Lflag ? mhdr->dmac : ""), hostname(4, da), portname(opts.nflag, "udp", udp->uh_dport)); #endif if (frag) { printf( " %d:%d@%d%s\n", ntohs(ip->ip_id), len, frag_off, frag_off ? "" : "+"); } else printf( " (DF)\n"); return (0); }