print-ip.c (98527) | print-ip.c (111729) |
---|---|
1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. 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 --- 4 unchanged lines hidden (view full) --- 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 * | 1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. 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 --- 4 unchanged lines hidden (view full) --- 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 * $FreeBSD: head/contrib/tcpdump/print-ip.c 98527 2002-06-21 00:49:02Z fenner $ | 21 * $FreeBSD: head/contrib/tcpdump/print-ip.c 111729 2003-03-02 08:25:48Z fenner $ |
22 */ 23 24#ifndef lint 25static const char rcsid[] = | 22 */ 23 24#ifndef lint 25static const char rcsid[] = |
26 "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.100 2001/09/17 21:58:03 fenner Exp $ (LBL)"; | 26 "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.100.4.1 2002/01/25 05:39:54 guy Exp $ (LBL)"; |
27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#include <sys/param.h> 34#include <sys/time.h> 35#include <sys/socket.h> 36 37#include <netinet/in.h> 38 | 27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#include <sys/param.h> 34#include <sys/time.h> 35#include <sys/socket.h> 36 37#include <netinet/in.h> 38 |
39#include <netdb.h> |
|
39#include <stdio.h> 40#include <stdlib.h> 41#include <string.h> 42#include <unistd.h> 43 44#include "addrtoname.h" 45#include "interface.h" 46#include "extract.h" /* must come after interface.h */ --- 207 unchanged lines hidden (view full) --- 254void 255ip_print(register const u_char *bp, register u_int length) 256{ 257 register const struct ip *ip; 258 register u_int hlen, len, len0, off; 259 register const u_char *cp; 260 u_char nh; 261 int advance; | 40#include <stdio.h> 41#include <stdlib.h> 42#include <string.h> 43#include <unistd.h> 44 45#include "addrtoname.h" 46#include "interface.h" 47#include "extract.h" /* must come after interface.h */ --- 207 unchanged lines hidden (view full) --- 255void 256ip_print(register const u_char *bp, register u_int length) 257{ 258 register const struct ip *ip; 259 register u_int hlen, len, len0, off; 260 register const u_char *cp; 261 u_char nh; 262 int advance; |
263 struct protoent *proto; |
|
262 263 ip = (const struct ip *)bp; 264#ifdef LBL_ALIGN 265 /* 266 * If the IP header is not aligned, copy into abuf. | 264 265 ip = (const struct ip *)bp; 266#ifdef LBL_ALIGN 267 /* 268 * If the IP header is not aligned, copy into abuf. |
267 * This will never happen with BPF. It does happen raw packet 268 * dumps from -r. | |
269 */ 270 if ((long)ip & 3) { 271 static u_char *abuf = NULL; 272 static int didwarn = 0; 273 274 if (abuf == NULL) { 275 abuf = (u_char *)malloc(snaplen); 276 if (abuf == NULL) --- 181 unchanged lines hidden (view full) --- 458#ifndef IPPROTO_VRRP 459#define IPPROTO_VRRP 112 460#endif 461 case IPPROTO_VRRP: 462 vrrp_print(cp, len, ip->ip_ttl); 463 break; 464 465 default: | 269 */ 270 if ((long)ip & 3) { 271 static u_char *abuf = NULL; 272 static int didwarn = 0; 273 274 if (abuf == NULL) { 275 abuf = (u_char *)malloc(snaplen); 276 if (abuf == NULL) --- 181 unchanged lines hidden (view full) --- 458#ifndef IPPROTO_VRRP 459#define IPPROTO_VRRP 112 460#endif 461 case IPPROTO_VRRP: 462 vrrp_print(cp, len, ip->ip_ttl); 463 break; 464 465 default: |
466 (void)printf(" ip-proto-%d %d", nh, len); | 466 if ((proto = getprotobynumber(nh)) != NULL) 467 (void)printf(" %s", proto->p_name); 468 else 469 (void)printf(" ip-proto-%d", nh); 470 printf(" %d", len); |
467 break; 468 } 469 } 470 471 /* Ultra quiet now means that all this stuff should be suppressed */ 472 /* res 3-Nov-98 */ 473 if (qflag > 1) return; 474 475 476 /* 477 * for fragmented datagrams, print id:size@offset. On all 478 * but the last stick a "+". For unfragmented datagrams, note 479 * the don't fragment flag. 480 */ 481 len = len0; /* get the original length */ 482 if (off & 0x3fff) { 483 /* 484 * if this isn't the first frag, we're missing the | 471 break; 472 } 473 } 474 475 /* Ultra quiet now means that all this stuff should be suppressed */ 476 /* res 3-Nov-98 */ 477 if (qflag > 1) return; 478 479 480 /* 481 * for fragmented datagrams, print id:size@offset. On all 482 * but the last stick a "+". For unfragmented datagrams, note 483 * the don't fragment flag. 484 */ 485 len = len0; /* get the original length */ 486 if (off & 0x3fff) { 487 /* 488 * if this isn't the first frag, we're missing the |
485 * next level protocol header. print the ip addr. | 489 * next level protocol header. print the ip addr 490 * and the protocol. |
486 */ | 491 */ |
487 if (off & 0x1fff) | 492 if (off & 0x1fff) { |
488 (void)printf("%s > %s:", ipaddr_string(&ip->ip_src), 489 ipaddr_string(&ip->ip_dst)); | 493 (void)printf("%s > %s:", ipaddr_string(&ip->ip_src), 494 ipaddr_string(&ip->ip_dst)); |
495 if ((proto = getprotobynumber(ip->ip_p)) != NULL) 496 (void)printf(" %s", proto->p_name); 497 else 498 (void)printf(" ip-proto-%d", ip->ip_p); 499 } |
|
490#ifndef IP_MF 491#define IP_MF 0x2000 492#endif /* IP_MF */ 493#ifndef IP_DF 494#define IP_DF 0x4000 495#endif /* IP_DF */ 496 (void)printf(" (frag %d:%u@%d%s)", ntohs(ip->ip_id), len, 497 (off & 0x1fff) * 8, --- 82 unchanged lines hidden --- | 500#ifndef IP_MF 501#define IP_MF 0x2000 502#endif /* IP_MF */ 503#ifndef IP_DF 504#define IP_DF 0x4000 505#endif /* IP_DF */ 506 (void)printf(" (frag %d:%u@%d%s)", ntohs(ip->ip_id), len, 507 (off & 0x1fff) * 8, --- 82 unchanged lines hidden --- |