⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _ip6opts.c

📁 This directory contains source code for tcpdump, a tool for network monitoring and data acquisition
💻 C
字号:
/*
 * Copyright (C) 1998 WIDE Project.
 * 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.
 * 3. Neither the name of the project nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 PROJECT 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.
 */

#if 0
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/tcpdump/print-ip6opts.c,v 1.2.2.1 2000/01/11 06:58:25 fenner Exp $";
#endif

#include <stdio.h>
#include <limits.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>

#include <netinet/in.h>
#include <netinet/ipv6.h>

#include "interfac.h"
#include "a2name.h"

#ifdef USE_INET6

#define IP6OPT_PAD1        0
#define IP6OPT_PADN        1
#define IP6OPT_RTALERT     2          /* !!wrong */
#define IP6OPT_JUMBO       194

#define IP6OPT_MINLEN      8          /* ?? */
#define IP6OPT_JUMBO_LEN   USHRT_MAX  /* ?? */
#define IP6OPT_RTALERT_LEN 6          /* ?? */

static void ip6_opt_print (const u_char *bp, int len)
{
  int i, optlen;

  for (i = 0; i < len; i += optlen)
  {
    switch (bp[i])
    {
      case IP6OPT_PAD1:
           optlen = 1;
           break;

      case IP6OPT_PADN:
           if (len - i < IP6OPT_MINLEN)
           {
             PUTS ("(padn: trunc)");
             goto trunc;
           }
           optlen = bp[i+1] + 2;
           break;

      case IP6OPT_RTALERT:
           if (len - i < IP6OPT_RTALERT_LEN)
           {
             PUTS ("(rtalert: trunc)");
             goto trunc;
           }
           if (bp[i+1] != IP6OPT_RTALERT_LEN - 2)
           {
             PRINTF ("(rtalert: invalid len %d)", bp[i+1]);
             goto trunc;
           }
           PRINTF ("(rtalert: 0x%04x) ", ntohs (*(u_short*)&bp[i+2]));
           optlen = IP6OPT_RTALERT_LEN;
           break;

      case IP6OPT_JUMBO:
           if (len - i < IP6OPT_JUMBO_LEN)
           {
             PUTS ("(jumbo: trunc)");
             goto trunc;
           }
           if (bp[i+1] != IP6OPT_JUMBO_LEN - 2)
           {
             PRINTF ("(jumbo: invalid len %d)", bp[i + 1]);
             goto trunc;
           }
           PRINTF ("(jumbo: %lu) ", ntohl (*(u_int*)&bp[i+2]));
           optlen = IP6OPT_JUMBO_LEN;
           break;

      default:
           if (len - i < IP6OPT_MINLEN)
           {
             PRINTF ("(type %d: trunc)", bp[i]);
             goto trunc;
           }
           PRINTF ("(type 0x%02x: len=%d) ", bp[i], bp[i+1]);
           optlen = bp[i+1] + 2;
           break;
    }
  }
  return;

trunc:
  PUTS ("[trunc] ");
}

int hbhopt_print (const u_char * bp)
{
  const struct ipv6_rt_hdr *dp = (struct ipv6_rt_hdr*) bp;
  int   hbhlen = 0;

  TCHECK (dp->hdrlen);
  hbhlen = (int) ((dp->hdrlen + 1) << 3);
  TCHECK2 (dp, hbhlen);
  PUTS ("HBH ");
  if (vflag)
     ip6_opt_print ((const u_char*)dp + sizeof(*dp), hbhlen - sizeof(*dp));

  return (hbhlen);

trunc:
  PUTS ("[|HBH]");
  return (hbhlen);
}

int dstopt_print (const u_char * bp)
{
  const struct ipv6_rt_hdr *dp = (struct ipv6_rt_hdr*) bp;
  int   dstoptlen = 0;

  TCHECK (dp->hdrlen);
  dstoptlen = (int) ((dp->hdrlen + 1) << 3);
  TCHECK2 (dp, dstoptlen);
  PUTS ("DSTOPT ");
  if (vflag)
     ip6_opt_print ((const u_char*)dp + sizeof(*dp), dstoptlen - sizeof(*dp));

  return (dstoptlen);

trunc:
  PUTS ("[|DSTOPT]");
  return (dstoptlen);
}
#endif     /* USE_INET6 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -