📄 _icmp6.c
字号:
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#if 0
static const char rcsid[] = "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.42 2000/12/13 07:57:05 itojun Exp $";
#endif
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "interfac.h"
#include "a2name.h"
#include "ip6.h"
#include "udp.h"
#include "ah.h"
#include "icmp6.h"
#ifdef USE_INET6
#ifndef ICMPV6_ROUTER_SOLICITATION
#define ICMPV6_ROUTER_SOLICITATION 133
#endif
#ifndef ICMPV6_ROUTER_ADVERTISEMENT
#define ICMPV6_ROUTER_ADVERTISEMENT 134
#endif
#ifndef ICMPV6_NEIGHBOR_SOLICITATION
#define ICMPV6_NEIGHBOR_SOLICITATION 135
#endif
#ifndef ICMPV6_NEIGHBOR_ADVERTISEMENT
#define ICMPV6_NEIGHBOR_ADVERTISEMENT 136
#endif
#define ICMPV6_MINLEN 8
/* Error messages and codes.
*/
#define ICMPV6_UNREACH 1 /* dest unreachable, codes: */
#define ICMPV6_UNREACH_NOROUTE 0 /* No route to dest. */
#define ICMPV6_UNREACH_ADMIN 1 /* Admin. prohibited */
#define ICMPV6_UNREACH_NOTNEIGHBOR 2 /* For strict source routing. */
#define ICMPV6_UNREACH_ADDRESS 3 /* Address unreach. */
#define ICMPV6_UNREACH_PORT 4 /* Port unreachable */
#define ICMPV6_TOOBIG 2 /* Packet too big. */
#define ICMPV6_TIMXCEED 3 /* time exceeded, code: */
#define ICMPV6_TIMXCEED_INTRANS 0 /* ttl==0 in transit */
#define ICMPV6_TIMXCEED_REASS 1 /* Reassembly t.o. */
#define ICMPV6_PARAMPROB 4 /* ip header bad */
#define ICMPV6_PARAMPROB_PROB 0 /* Actual incorrect parameter. */
#define ICMPV6_PARAMPROB_NEXTHDR 1 /* Bad next hdr. */
#define ICMPV6_PARAMPROB_BADOPT 2 /* Unrec. option */
/* Info messages.
*/
#define ICMPV6_ECHO 128 /* echo service */
#define ICMPV6_ECHOREPLY 129 /* echo reply */
#define ICMPV6_GRPQUERY 130 /* Query group membership. */
#define ICMPV6_GRPREPORT 131 /* Join mcast group. */
#define ICMPV6_GRPTERM 132 /* Leave mcast group. */
#define ICMPV6_ROUTERSOL 133 /* Router solicit. */
#define ICMPV6_ROUTERADV 134 /* Router advertisement. */
#define ICMPV6_NEIGHBORSOL 135 /* Neighbor solicit. */
#define ICMPV6_NEIGHBORADV 136 /* Neighbor advertisement. */
#define ICMPV6_REDIRECT 137 /* ICMPv6 redirect. */
/* Defined this way to save some HTONL cycles on little-endian boxes.
*/
#if BYTE_ORDER == BIG_ENDIAN
#define ICMPV6_NEIGHBORADV_RTR 0x80000000 /* Router flag. */
#define ICMPV6_NEIGHBORADV_SOL 0x40000000 /* Solicited flag. */
#define ICMPV6_NEIGHBORADV_OVERRIDE 0x20000000 /* Override flag. */
#else /* BYTE_ORDER == LITTLE_ENDIAN */
#define ICMPV6_NEIGHBORADV_RTR 0x80 /* Router flag. */
#define ICMPV6_NEIGHBORADV_SOL 0x40 /* Solicited flag. */
#define ICMPV6_NEIGHBORADV_OVERRIDE 0x20 /* Override flag. */
#endif
#define ICMPV6_MAXTYPE 137
#define ICMPV6_INFOTYPE(type) ((type) >= 128)
struct na_hdr {
u_int8_t type;
u_int8_t code;
u_int16_t cksum;
u_int32_t flags;
#define NA_ROUTER htonl(0x80000000)
#define NA_SOLICITED htonl(0x40000000)
#define NA_OVERRIDE htonl(0x20000000)
#define NA_RESERVED htonl(0x1FFFFFFF)
struct in6_addr targ_addr;
};
struct ns_hdr {
u_int8_t type;
u_int8_t code;
u_int16_t cksum;
u_int32_t reserved;
struct in6_addr target;
};
struct red_hdr {
u_int8_t type;
u_int8_t code;
u_int16_t cksum;
u_int32_t reserved;
struct in6_addr target;
struct in6_addr destination;
};
struct rs_hdr {
u_int8_t type;
u_int8_t code;
u_int16_t cksum;
u_int32_t reserved;
};
struct ra_hdr {
u_int8_t type;
u_int8_t code;
u_int16_t cksum;
u_int8_t hoplimit;
u_int8_t flags;
#define RA_MANAGED 0x80
#define RA_OTHER_STATEFUL 0x40
#define RA_RESERVED 0x3F
u_int16_t router_lft;
u_int32_t reachable;
u_int32_t retrans;
};
struct ra_pinfo {
u_int8_t type;
u_int8_t length;
u_int8_t prefix_len;
u_int8_t flags;
#define RA_PINFO_ONLINK 0x80
#define RA_PINFO_AUTO 0x40
#define RA_PINFO_RESERVED1 0x20
#define RA_PINFO_SITE 0x10
#define RA_PINFO_RESERVED 0x0F
u_int32_t valid;
u_int32_t prefered;
u_int8_t site_plen;
u_int8_t reserved1;
u_int16_t reserved2;
struct in6_addr prefix;
};
struct ndisc_opt {
u_int8_t type;
u_int8_t length;
};
void ndisc_opt_print (struct ndisc_opt *opt, int len)
{
int i;
switch (opt->type)
{
case 1:
PUTS (" src[");
break;
case 2:
PUTS (" target[");
break;
case 3:
PUTS (" prefix[");
if (opt->length * 8 < sizeof(struct ra_pinfo))
{
PUTS ("!too short]");
return;
}
if (opt->length * 8 > len)
{
PRINTF ("%s]", ((u_char*)opt) + opt->length * 8 > snapend ?
"|" : "!truncated");
return;
}
if (vflag > 1)
{
struct ra_pinfo *p = (struct ra_pinfo*)opt;
PRINTF (" %s/%d", ip6addr_string(&p->prefix), p->prefix_len);
if (p->flags)
{
PUTS (" (");
if (p->flags & RA_PINFO_AUTO)
PUTCHAR ('A');
if (p->flags & RA_PINFO_ONLINK)
PUTCHAR ('L');
if (p->flags & RA_PINFO_RESERVED1)
PUTCHAR ('R');
if (p->flags & RA_PINFO_SITE)
PUTCHAR ('S');
if (p->flags & RA_PINFO_RESERVED)
PRINTF ("?{%02x}", p->flags & RA_PINFO_RESERVED);
PUTCHAR (')');
}
if (p->site_plen)
PRINTF (" site %d", p->site_plen);
if (p->reserved1)
PRINTF (" res1 %02x", p->reserved1);
if (p->reserved2)
PRINTF (" res2 %04x", ntohs (p->reserved2));
if (p->valid == 0xFFFFFFFF)
PUTS (" valid forever");
else if (p->valid == 0)
PUTS (" invalid");
else PRINTF (" valid %us", ntohl (p->valid));
if (p->prefered == 0xFFFFFFFF)
PUTS (" prefered forever");
else if (p->prefered == 0)
PUTS (" deprecated");
else PRINTF (" pref %us", ntohl (p->prefered));
}
PUTCHAR (']');
return;
case 4:
PUTS (" hdr[");
if (!opt->length)
{
PUTCHAR (']');
return;
}
if (opt->length * 8 > len)
{
if (((u_char *) opt) + opt->length * 8 <= snapend)
PUTS ("!truncated");
else PUTCHAR ('|');
if (len <= 8)
{
PUTCHAR (']');
return;
}
else
PUTS (": ");
len -= 8;
}
else
len = (opt->length - 1) * 8;
if (vflag > 1)
{
partial_frame++;
ip6_print (((u_char *) opt) + 8, len);
partial_frame--;
}
PUTCHAR (']');
return;
case 5:
if (opt->length * 8 > len)
{
PRINTF ("%s]", ((u_char*)opt) + opt->length * 8 > snapend ?
"|" : "!truncated");
return;
}
if (!opt->length)
{
PUTS ("mtu[]");
return;
}
PRINTF (" mtu[%d]", ntohl(*(((u_int32_t*)opt) + 1)));
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -