Grab tcpdump out of src/contrib/tcpdump
This commit is contained in:
parent
e8e91bdf52
commit
3629a694ff
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=17694
@ -1,22 +1,31 @@
|
||||
# $Id: Makefile,v 1.10 1995/08/29 19:48:10 wollman Exp $
|
||||
|
||||
PROG= tcpdump
|
||||
CFLAGS+=-DCSLIP -DPPP -DFDDI -DETHER_SERVICE
|
||||
CFLAGS+=-DHAVE_FCNTL_H=1 -DHAVE_NET_SLIP_H=1 -DTIME_WITH_SYS_TIME=1 \
|
||||
-DHAVE_ETHER_NTOA=1 -DHAVE_SETLINEBUF=1 -DSTDC_HEADERS=1 \
|
||||
-DRETSIGTYPE=void -DRETSIGVAL= -DHAVE_SOCKADDR_SA_LEN=1 \
|
||||
-DHAVE_TM_GMTOFF=1 -DLBL_ALIGN=1 -DPPP -DHAVE_FDDI
|
||||
MAN1= tcpdump.1
|
||||
SRCS= version.c addrtoname.c bpf_dump.c parsenfsfh.c \
|
||||
print-arp.c print-atalk.c print-bootp.c print-decnet.c print-domain.c \
|
||||
print-egp.c print-ether.c print-fddi.c print-icmp.c print-ip.c \
|
||||
print-ipx.c print-isoclns.c print-llc.c print-krb.c \
|
||||
print-nfs.c print-ntp.c print-null.c print-ospf.c print-ppp.c \
|
||||
print-rip.c print-sl.c print-snmp.c print-sunrpc.c print-tcp.c \
|
||||
print-tftp.c print-udp.c print-wb.c tcpdump.c \
|
||||
util.c
|
||||
SRCS= version.c tcpdump.c addrtoname.c \
|
||||
print-ether.c print-ip.c print-arp.c print-tcp.c \
|
||||
print-udp.c print-atalk.c print-domain.c print-tftp.c \
|
||||
print-bootp.c print-nfs.c print-icmp.c print-igrp.c \
|
||||
print-sl.c print-ppp.c print-rip.c print-snmp.c \
|
||||
print-ntp.c print-null.c print-egp.c print-ospf.c \
|
||||
print-fddi.c print-llc.c print-sunrpc.c print-wb.c \
|
||||
print-decnet.c print-isoclns.c print-ipx.c \
|
||||
print-atm.c print-dvmrp.c print-pim.c print-krb.c \
|
||||
util.c machdep.c bpf_dump.c parsenfsfh.c
|
||||
CLEANFILES+= version.c
|
||||
DPADD+= ${LIBL} ${LIBPCAP}
|
||||
LDADD+= -ll -lpcap
|
||||
|
||||
version.c: VERSION
|
||||
DISTDIR?= ${.CURDIR}/../../contrib/tcpdump
|
||||
CFLAGS+= -I${DISTDIR}/lbl
|
||||
.PATH: ${DISTDIR}
|
||||
|
||||
version.c: ${DISTDIR}/VERSION
|
||||
rm -f version.c ; \
|
||||
sed 's/.*/char version[] = "&";/' $(.CURDIR)/VERSION > version.c
|
||||
sed 's/.*/char version[] = "&";/' ${DISTDIR}/VERSION > version.c
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -1 +0,0 @@
|
||||
3.0
|
@ -1,722 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1990, 1991, 1992, 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.
|
||||
*
|
||||
* Internet, ethernet, port, and protocol string to address
|
||||
* and address to string conversion routines
|
||||
*/
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/addrtoname.c,v 1.2 1995/03/08 12:52:07 olah Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <netdb.h>
|
||||
#include <pcap.h>
|
||||
#include <pcap-namedb.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
#include "llc.h"
|
||||
|
||||
static SIGRET nohostname(int);
|
||||
#ifdef ETHER_SERVICE
|
||||
struct ether_addr;
|
||||
extern int ether_ntohost(char *, struct ether_addr *);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* hash tables for whatever-to-name translations
|
||||
*/
|
||||
|
||||
#define HASHNAMESIZE 4096
|
||||
|
||||
struct hnamemem {
|
||||
u_int32 addr;
|
||||
char *name;
|
||||
struct hnamemem *nxt;
|
||||
};
|
||||
|
||||
struct hnamemem hnametable[HASHNAMESIZE];
|
||||
struct hnamemem tporttable[HASHNAMESIZE];
|
||||
struct hnamemem uporttable[HASHNAMESIZE];
|
||||
struct hnamemem eprototable[HASHNAMESIZE];
|
||||
struct hnamemem dnaddrtable[HASHNAMESIZE];
|
||||
struct hnamemem llcsaptable[HASHNAMESIZE];
|
||||
|
||||
struct enamemem {
|
||||
u_short e_addr0;
|
||||
u_short e_addr1;
|
||||
u_short e_addr2;
|
||||
char *e_name;
|
||||
u_char *e_nsap; /* used only for nsaptable[] */
|
||||
struct enamemem *e_nxt;
|
||||
};
|
||||
|
||||
struct enamemem enametable[HASHNAMESIZE];
|
||||
struct enamemem nsaptable[HASHNAMESIZE];
|
||||
|
||||
struct protoidmem {
|
||||
u_long p_oui;
|
||||
u_short p_proto;
|
||||
char *p_name;
|
||||
struct protoidmem *p_nxt;
|
||||
};
|
||||
|
||||
struct protoidmem protoidtable[HASHNAMESIZE];
|
||||
|
||||
/*
|
||||
* A faster replacement for inet_ntoa().
|
||||
*/
|
||||
char *
|
||||
intoa(u_int32 addr)
|
||||
{
|
||||
register char *cp;
|
||||
register u_int byte;
|
||||
register int n;
|
||||
static char buf[sizeof(".xxx.xxx.xxx.xxx")];
|
||||
|
||||
NTOHL(addr);
|
||||
cp = &buf[sizeof buf];
|
||||
*--cp = '\0';
|
||||
|
||||
n = 4;
|
||||
do {
|
||||
byte = addr & 0xff;
|
||||
*--cp = byte % 10 + '0';
|
||||
byte /= 10;
|
||||
if (byte > 0) {
|
||||
*--cp = byte % 10 + '0';
|
||||
byte /= 10;
|
||||
if (byte > 0)
|
||||
*--cp = byte + '0';
|
||||
}
|
||||
*--cp = '.';
|
||||
addr >>= 8;
|
||||
} while (--n > 0);
|
||||
|
||||
return cp + 1;
|
||||
}
|
||||
|
||||
static u_int32 f_netmask;
|
||||
static u_int32 f_localnet;
|
||||
static u_int32 netmask;
|
||||
|
||||
/*
|
||||
* "getname" is written in this atrocious way to make sure we don't
|
||||
* wait forever while trying to get hostnames from yp.
|
||||
*/
|
||||
#include <setjmp.h>
|
||||
|
||||
jmp_buf getname_env;
|
||||
|
||||
static SIGRET
|
||||
nohostname(int signo)
|
||||
{
|
||||
longjmp(getname_env, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a name for the IP address pointed to by ap. This address
|
||||
* is assumed to be in network byte order.
|
||||
*/
|
||||
char *
|
||||
getname(const u_char *ap)
|
||||
{
|
||||
register struct hostent *hp;
|
||||
register char *cp;
|
||||
u_int32 addr;
|
||||
static struct hnamemem *p; /* static for longjmp() */
|
||||
|
||||
#ifndef TCPDUMP_ALIGN
|
||||
addr = *(const u_int32 *)ap;
|
||||
#else
|
||||
/*
|
||||
* Deal with alignment.
|
||||
*/
|
||||
switch ((int)ap & 3) {
|
||||
|
||||
case 0:
|
||||
addr = *(u_int32 *)ap;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
addr = ((u_int32)*(u_short *)(ap + 2) << 16) |
|
||||
(u_int32)*(u_short *)ap;
|
||||
#else
|
||||
addr = ((u_int32)*(u_short *)ap << 16) |
|
||||
(u_int32)*(u_short *)(ap + 2);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
addr = ((u_int32)ap[0] << 24) |
|
||||
((u_int32)ap[1] << 16) |
|
||||
((u_int32)ap[2] << 8) |
|
||||
(u_int32)ap[3];
|
||||
#else
|
||||
addr = ((u_int32)ap[3] << 24) |
|
||||
((u_int32)ap[2] << 16) |
|
||||
((u_int32)ap[1] << 8) |
|
||||
(u_int32)ap[0];
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
p = &hnametable[addr & (HASHNAMESIZE-1)];
|
||||
for (; p->nxt; p = p->nxt) {
|
||||
if (p->addr == addr)
|
||||
return (p->name);
|
||||
}
|
||||
p->addr = addr;
|
||||
p->nxt = (struct hnamemem *)calloc(1, sizeof (*p));
|
||||
|
||||
/*
|
||||
* Only print names when:
|
||||
* (1) -n was not given.
|
||||
* (2) Address is foreign and -f was given. If -f was not
|
||||
* present, f_netmask and f_local are 0 and the second
|
||||
* test will succeed.
|
||||
* (3) The host portion is not 0 (i.e., a network address).
|
||||
* (4) The host portion is not broadcast.
|
||||
*/
|
||||
if (!nflag && (addr & f_netmask) == f_localnet
|
||||
&& (addr &~ netmask) != 0 && (addr | netmask) != 0xffffffff) {
|
||||
if (!setjmp(getname_env)) {
|
||||
(void)signal(SIGALRM, nohostname);
|
||||
(void)alarm(20);
|
||||
hp = gethostbyaddr((char *)&addr, 4, AF_INET);
|
||||
(void)alarm(0);
|
||||
if (hp) {
|
||||
char *dotp;
|
||||
|
||||
p->name = savestr(hp->h_name);
|
||||
if (Nflag) {
|
||||
/* Remove domain qualifications */
|
||||
dotp = strchr(p->name, '.');
|
||||
if (dotp)
|
||||
*dotp = 0;
|
||||
}
|
||||
return (p->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
cp = intoa(addr);
|
||||
p->name = savestr(cp);
|
||||
return (p->name);
|
||||
}
|
||||
|
||||
static char hex[] = "0123456789abcdef";
|
||||
|
||||
|
||||
/* Find the hash node that corresponds the ether address 'ep'. */
|
||||
|
||||
static inline struct enamemem *
|
||||
lookup_emem(const u_char *ep)
|
||||
{
|
||||
register u_int i, j, k;
|
||||
struct enamemem *tp;
|
||||
|
||||
k = (ep[0] << 8) | ep[1];
|
||||
j = (ep[2] << 8) | ep[3];
|
||||
i = (ep[4] << 8) | ep[5];
|
||||
|
||||
tp = &enametable[(i ^ j) & (HASHNAMESIZE-1)];
|
||||
while (tp->e_nxt)
|
||||
if (tp->e_addr0 == i &&
|
||||
tp->e_addr1 == j &&
|
||||
tp->e_addr2 == k)
|
||||
return tp;
|
||||
else
|
||||
tp = tp->e_nxt;
|
||||
tp->e_addr0 = i;
|
||||
tp->e_addr1 = j;
|
||||
tp->e_addr2 = k;
|
||||
tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
|
||||
|
||||
return tp;
|
||||
}
|
||||
|
||||
/* Find the hash node that corresponds the NSAP 'nsap'. */
|
||||
|
||||
static inline struct enamemem *
|
||||
lookup_nsap(register const u_char *nsap)
|
||||
{
|
||||
register u_int i, j, k;
|
||||
int nlen = *nsap;
|
||||
struct enamemem *tp;
|
||||
const u_char *ensap = nsap + nlen - 6;
|
||||
|
||||
if (nlen > 6) {
|
||||
k = (ensap[0] << 8) | ensap[1];
|
||||
j = (ensap[2] << 8) | ensap[3];
|
||||
i = (ensap[4] << 8) | ensap[5];
|
||||
}
|
||||
else
|
||||
i = j = k = 0;
|
||||
|
||||
tp = &nsaptable[(i ^ j) & (HASHNAMESIZE-1)];
|
||||
while (tp->e_nxt)
|
||||
if (tp->e_addr0 == i &&
|
||||
tp->e_addr1 == j &&
|
||||
tp->e_addr2 == k &&
|
||||
tp->e_nsap[0] == nlen &&
|
||||
bcmp((char *)&(nsap[1]),
|
||||
(char *)&(tp->e_nsap[1]), nlen) == 0)
|
||||
return tp;
|
||||
else
|
||||
tp = tp->e_nxt;
|
||||
tp->e_addr0 = i;
|
||||
tp->e_addr1 = j;
|
||||
tp->e_addr2 = k;
|
||||
tp->e_nsap = (u_char *) calloc(1, nlen + 1);
|
||||
bcopy(nsap, tp->e_nsap, nlen + 1);
|
||||
tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
|
||||
|
||||
return tp;
|
||||
}
|
||||
|
||||
/* Find the hash node that corresponds the protoid 'pi'. */
|
||||
|
||||
static inline struct protoidmem *
|
||||
lookup_protoid(const u_char *pi)
|
||||
{
|
||||
register u_int i, j;
|
||||
struct protoidmem *tp;
|
||||
|
||||
/* 5 octets won't be aligned */
|
||||
i = (((pi[0] << 8) + pi[1]) << 8) + pi[2];
|
||||
j = (pi[3] << 8) + pi[4];
|
||||
/* XXX should be endian-insensitive, but do big-endian testing XXX */
|
||||
|
||||
tp = &protoidtable[(i ^ j) & (HASHNAMESIZE-1)];
|
||||
while (tp->p_nxt)
|
||||
if (tp->p_oui == i && tp->p_proto == j)
|
||||
return tp;
|
||||
else
|
||||
tp = tp->p_nxt;
|
||||
tp->p_oui = i;
|
||||
tp->p_proto = j;
|
||||
tp->p_nxt = (struct protoidmem *)calloc(1, sizeof(*tp));
|
||||
|
||||
return tp;
|
||||
}
|
||||
|
||||
char *
|
||||
etheraddr_string(register const u_char *ep)
|
||||
{
|
||||
register u_int i, j;
|
||||
register char *cp;
|
||||
register struct enamemem *tp;
|
||||
|
||||
tp = lookup_emem(ep);
|
||||
if (tp->e_name)
|
||||
return (tp->e_name);
|
||||
#ifdef ETHER_SERVICE
|
||||
if (!nflag) {
|
||||
char buf[128];
|
||||
if (ether_ntohost(buf, (struct ether_addr *)ep) == 0) {
|
||||
tp->e_name = savestr(buf);
|
||||
return (tp->e_name);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
tp->e_name = cp = (char *)malloc(sizeof("00:00:00:00:00:00"));
|
||||
|
||||
if ((j = *ep >> 4) != 0)
|
||||
*cp++ = hex[j];
|
||||
*cp++ = hex[*ep++ & 0xf];
|
||||
for (i = 5; (int)--i >= 0;) {
|
||||
*cp++ = ':';
|
||||
if ((j = *ep >> 4) != 0)
|
||||
*cp++ = hex[j];
|
||||
*cp++ = hex[*ep++ & 0xf];
|
||||
}
|
||||
*cp = '\0';
|
||||
return (tp->e_name);
|
||||
}
|
||||
|
||||
char *
|
||||
etherproto_string(u_short port)
|
||||
{
|
||||
register char *cp;
|
||||
register struct hnamemem *tp;
|
||||
register u_long i = port;
|
||||
|
||||
for (tp = &eprototable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
|
||||
if (tp->addr == i)
|
||||
return (tp->name);
|
||||
|
||||
tp->name = cp = (char *)malloc(sizeof("0000"));
|
||||
tp->addr = i;
|
||||
tp->nxt = (struct hnamemem *)calloc(1, sizeof (*tp));
|
||||
|
||||
NTOHS(port);
|
||||
*cp++ = hex[port >> 12 & 0xf];
|
||||
*cp++ = hex[port >> 8 & 0xf];
|
||||
*cp++ = hex[port >> 4 & 0xf];
|
||||
*cp++ = hex[port & 0xf];
|
||||
*cp++ = '\0';
|
||||
return (tp->name);
|
||||
}
|
||||
|
||||
char *
|
||||
protoid_string(register const u_char *pi)
|
||||
{
|
||||
register u_int i, j;
|
||||
register char *cp;
|
||||
register struct protoidmem *tp;
|
||||
|
||||
tp = lookup_protoid(pi);
|
||||
if (tp->p_name)
|
||||
return tp->p_name;
|
||||
|
||||
tp->p_name = cp = (char *)malloc(sizeof("00:00:00:00:00"));
|
||||
|
||||
if ((j = *pi >> 4) != 0)
|
||||
*cp++ = hex[j];
|
||||
*cp++ = hex[*pi++ & 0xf];
|
||||
for (i = 4; (int)--i >= 0;) {
|
||||
*cp++ = ':';
|
||||
if ((j = *pi >> 4) != 0)
|
||||
*cp++ = hex[j];
|
||||
*cp++ = hex[*pi++ & 0xf];
|
||||
}
|
||||
*cp = '\0';
|
||||
return (tp->p_name);
|
||||
}
|
||||
|
||||
char *
|
||||
llcsap_string(u_char sap)
|
||||
{
|
||||
register char *cp;
|
||||
register struct hnamemem *tp;
|
||||
register u_long i = sap;
|
||||
|
||||
for (tp = &llcsaptable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
|
||||
if (tp->addr == i)
|
||||
return (tp->name);
|
||||
|
||||
tp->name = cp = (char *)malloc(sizeof("sap 00"));
|
||||
tp->addr = i;
|
||||
tp->nxt = (struct hnamemem *)calloc(1, sizeof (*tp));
|
||||
|
||||
(void)strcpy(cp, "sap ");
|
||||
cp += strlen(cp);
|
||||
*cp++ = hex[sap >> 4 & 0xf];
|
||||
*cp++ = hex[sap & 0xf];
|
||||
*cp++ = '\0';
|
||||
return (tp->name);
|
||||
}
|
||||
|
||||
char *
|
||||
isonsap_string(const u_char *nsap)
|
||||
{
|
||||
register u_int i, nlen = nsap[0];
|
||||
register char *cp;
|
||||
register struct enamemem *tp;
|
||||
|
||||
tp = lookup_nsap(nsap);
|
||||
if (tp->e_name)
|
||||
return tp->e_name;
|
||||
|
||||
tp->e_name = cp = (char *)malloc(nlen * 2 + 2);
|
||||
|
||||
nsap++;
|
||||
*cp++ = '/';
|
||||
for (i = nlen; (int)--i >= 0;) {
|
||||
*cp++ = hex[*nsap >> 4];
|
||||
*cp++ = hex[*nsap++ & 0xf];
|
||||
}
|
||||
*cp = '\0';
|
||||
return (tp->e_name);
|
||||
}
|
||||
|
||||
char *
|
||||
tcpport_string(u_short port)
|
||||
{
|
||||
register struct hnamemem *tp;
|
||||
register u_long i = port;
|
||||
|
||||
for (tp = &tporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
|
||||
if (tp->addr == i)
|
||||
return (tp->name);
|
||||
|
||||
tp->name = (char *)malloc(sizeof("00000"));
|
||||
tp->addr = i;
|
||||
tp->nxt = (struct hnamemem *)calloc(1, sizeof (*tp));
|
||||
|
||||
(void)sprintf(tp->name, "%d", i);
|
||||
return (tp->name);
|
||||
}
|
||||
|
||||
char *
|
||||
udpport_string(register u_short port)
|
||||
{
|
||||
register struct hnamemem *tp;
|
||||
register u_long i = port;
|
||||
|
||||
for (tp = &uporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
|
||||
if (tp->addr == i)
|
||||
return (tp->name);
|
||||
|
||||
tp->name = (char *)malloc(sizeof("00000"));
|
||||
tp->addr = i;
|
||||
tp->nxt = (struct hnamemem *)calloc(1, sizeof(*tp));
|
||||
|
||||
(void)sprintf(tp->name, "%d", i);
|
||||
|
||||
return (tp->name);
|
||||
}
|
||||
|
||||
static void
|
||||
init_servarray(void)
|
||||
{
|
||||
struct servent *sv;
|
||||
register struct hnamemem *table;
|
||||
register int i;
|
||||
|
||||
while ((sv = getservent()) != NULL) {
|
||||
int port = ntohs(sv->s_port);
|
||||
i = port & (HASHNAMESIZE-1);
|
||||
if (strcmp(sv->s_proto, "tcp") == 0)
|
||||
table = &tporttable[i];
|
||||
else if (strcmp(sv->s_proto, "udp") == 0)
|
||||
table = &uporttable[i];
|
||||
else
|
||||
continue;
|
||||
|
||||
while (table->name)
|
||||
table = table->nxt;
|
||||
if (nflag) {
|
||||
char buf[32];
|
||||
|
||||
(void)sprintf(buf, "%d", port);
|
||||
table->name = savestr(buf);
|
||||
} else
|
||||
table->name = savestr(sv->s_name);
|
||||
table->addr = port;
|
||||
table->nxt = (struct hnamemem *)calloc(1, sizeof(*table));
|
||||
}
|
||||
endservent();
|
||||
}
|
||||
|
||||
/*XXX from libbpfc.a */
|
||||
extern struct eproto {
|
||||
char *s;
|
||||
u_short p;
|
||||
} eproto_db[];
|
||||
|
||||
static void
|
||||
init_eprotoarray(void)
|
||||
{
|
||||
register int i;
|
||||
register struct hnamemem *table;
|
||||
|
||||
for (i = 0; eproto_db[i].s; i++) {
|
||||
int j = ntohs(eproto_db[i].p) & (HASHNAMESIZE-1);
|
||||
table = &eprototable[j];
|
||||
while (table->name)
|
||||
table = table->nxt;
|
||||
table->name = eproto_db[i].s;
|
||||
table->addr = ntohs(eproto_db[i].p);
|
||||
table->nxt = (struct hnamemem *)calloc(1, sizeof(*table));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* SNAP proto IDs with org code 0:0:0 are actually encapsulated Ethernet
|
||||
* types.
|
||||
*/
|
||||
static void
|
||||
init_protoidarray(void)
|
||||
{
|
||||
register int i;
|
||||
register struct protoidmem *tp;
|
||||
u_char protoid[5];
|
||||
|
||||
protoid[0] = 0;
|
||||
protoid[1] = 0;
|
||||
protoid[2] = 0;
|
||||
for (i = 0; eproto_db[i].s; i++) {
|
||||
u_short etype = htons(eproto_db[i].p);
|
||||
bcopy((char *)&etype, (char *)&protoid[3], 2);
|
||||
tp = lookup_protoid(protoid);
|
||||
tp->p_name = savestr(eproto_db[i].s);
|
||||
}
|
||||
}
|
||||
|
||||
static struct etherlist {
|
||||
u_char addr[6];
|
||||
char *name;
|
||||
} etherlist[] = {
|
||||
{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, "Broadcast" },
|
||||
{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
* Initialize the ethers hash table. We take two different approaches
|
||||
* depending on whether or not the system provides the ethers name
|
||||
* service. If it does, we just wire in a few names at startup,
|
||||
* and etheraddr_string() fills in the table on demand. If it doesn't,
|
||||
* then we suck in the entire /etc/ethers file at startup. The idea
|
||||
* is that parsing the local file will be fast, but spinning through
|
||||
* all the ethers entries via NIS & next_etherent might be very slow.
|
||||
*
|
||||
* XXX pcap_next_etherent doesn't belong in the pcap interface, but
|
||||
* since the pcap module already does name-to-address translation,
|
||||
* it's already does most of the work for the ethernet address-to-name
|
||||
* translation, so we just pcap_next_etherent as a convenience.
|
||||
*/
|
||||
static void
|
||||
init_etherarray(void)
|
||||
{
|
||||
register struct etherlist *el;
|
||||
register struct enamemem *tp;
|
||||
#ifndef ETHER_SERVICE
|
||||
register struct pcap_etherent *ep;
|
||||
register FILE *fp;
|
||||
|
||||
/* Suck in entire ethers file */
|
||||
fp = fopen(PCAP_ETHERS_FILE, "r");
|
||||
if (fp != NULL) {
|
||||
while ((ep = pcap_next_etherent(fp)) != NULL) {
|
||||
tp = lookup_emem(ep->addr);
|
||||
tp->e_name = savestr(ep->name);
|
||||
}
|
||||
(void)fclose(fp);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Hardwire some ethernet names */
|
||||
for (el = etherlist; el->name != NULL; ++el) {
|
||||
#ifdef ETHER_SERVICE
|
||||
/* Use yp/nis version of name if available */
|
||||
char wrk[256];
|
||||
if (ether_ntohost(wrk, (struct ether_addr *)el->addr) == 0) {
|
||||
tp = lookup_emem(el->addr);
|
||||
tp->e_name = savestr(wrk);
|
||||
}
|
||||
#else
|
||||
/* install if not already present */
|
||||
tp = lookup_emem(el->addr);
|
||||
if (tp->e_name == NULL)
|
||||
tp->e_name = el->name;
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static struct token llcsap_db[] = {
|
||||
{ LLCSAP_NULL, "null" },
|
||||
{ LLCSAP_8021B_I, "802.1b-gsap" },
|
||||
{ LLCSAP_8021B_G, "802.1b-isap" },
|
||||
{ LLCSAP_IP, "ip-sap" },
|
||||
{ LLCSAP_PROWAYNM, "proway-nm" },
|
||||
{ LLCSAP_8021D, "802.1d" },
|
||||
{ LLCSAP_RS511, "eia-rs511" },
|
||||
{ LLCSAP_ISO8208, "x.25/llc2" },
|
||||
{ LLCSAP_PROWAY, "proway" },
|
||||
{ LLCSAP_ISONS, "iso-clns" },
|
||||
{ LLCSAP_GLOBAL, "global" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static void
|
||||
init_llcsaparray(void)
|
||||
{
|
||||
register int i;
|
||||
register struct hnamemem *table;
|
||||
|
||||
for (i = 0; llcsap_db[i].s != NULL; i++) {
|
||||
table = &llcsaptable[llcsap_db[i].v];
|
||||
while (table->name)
|
||||
table = table->nxt;
|
||||
table->name = llcsap_db[i].s;
|
||||
table->addr = llcsap_db[i].v;
|
||||
table->nxt = (struct hnamemem *)calloc(1, sizeof(*table));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the address to name translation machinery. We map all
|
||||
* non-local IP addresses to numeric addresses if fflag is true (i.e.,
|
||||
* to prevent blocking on the nameserver). localnet is the IP address
|
||||
* of the local network. mask is its subnet mask.
|
||||
*/
|
||||
void
|
||||
init_addrtoname(int fflag, u_int32 localnet, u_int32 mask)
|
||||
{
|
||||
netmask = mask;
|
||||
if (fflag) {
|
||||
f_localnet = localnet;
|
||||
f_netmask = mask;
|
||||
}
|
||||
if (nflag)
|
||||
/*
|
||||
* Simplest way to suppress names.
|
||||
*/
|
||||
return;
|
||||
|
||||
init_etherarray();
|
||||
init_servarray();
|
||||
init_eprotoarray();
|
||||
init_llcsaparray();
|
||||
init_protoidarray();
|
||||
}
|
||||
|
||||
char *
|
||||
dnaddr_string(u_short dnaddr)
|
||||
{
|
||||
register struct hnamemem *tp;
|
||||
|
||||
for (tp = &dnaddrtable[dnaddr & (HASHNAMESIZE-1)]; tp->nxt != 0;
|
||||
tp = tp->nxt)
|
||||
if (tp->addr == dnaddr)
|
||||
return (tp->name);
|
||||
|
||||
tp->addr = dnaddr;
|
||||
tp->nxt = (struct hnamemem *)calloc(1, sizeof(*tp));
|
||||
if (nflag)
|
||||
tp->name = dnnum_string(dnaddr);
|
||||
else
|
||||
tp->name = dnname_string(dnaddr);
|
||||
|
||||
return(tp->name);
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1990, 1992, 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.
|
||||
*
|
||||
* @(#) $Header: addrtoname.h,v 1.11 94/06/14 20:11:41 leres Exp $ (LBL)
|
||||
*/
|
||||
|
||||
/* Name to address translation routines. */
|
||||
|
||||
extern char *etheraddr_string(const u_char *);
|
||||
extern char *etherproto_string(u_short);
|
||||
extern char *tcpport_string(u_short);
|
||||
extern char *udpport_string(u_short);
|
||||
extern char *getname(const u_char *);
|
||||
extern char *intoa(u_int32);
|
||||
|
||||
extern void init_addrtoname(int, u_int32, u_int32);
|
||||
|
||||
#define ipaddr_string(p) getname((const u_char *)(p))
|
@ -1,167 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 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.
|
||||
*
|
||||
* AppleTalk protocol formats (courtesy Bill Croft of Stanford/SUMEX).
|
||||
*
|
||||
* @(#) $Header: appletalk.h,v 1.10 94/06/14 20:11:44 leres Exp $ (LBL)
|
||||
*/
|
||||
|
||||
struct LAP {
|
||||
u_char dst;
|
||||
u_char src;
|
||||
u_char type;
|
||||
};
|
||||
#define lapShortDDP 1 /* short DDP type */
|
||||
#define lapDDP 2 /* DDP type */
|
||||
#define lapKLAP 'K' /* Kinetics KLAP type */
|
||||
|
||||
/* Datagram Delivery Protocol */
|
||||
|
||||
struct atDDP {
|
||||
u_short length;
|
||||
u_short checksum;
|
||||
u_short dstNet;
|
||||
u_short srcNet;
|
||||
u_char dstNode;
|
||||
u_char srcNode;
|
||||
u_char dstSkt;
|
||||
u_char srcSkt;
|
||||
u_char type;
|
||||
};
|
||||
|
||||
struct atShortDDP {
|
||||
u_short length;
|
||||
u_char dstSkt;
|
||||
u_char srcSkt;
|
||||
u_char type;
|
||||
};
|
||||
|
||||
#define ddpMaxWKS 0x7F
|
||||
#define ddpMaxData 586
|
||||
#define ddpLengthMask 0x3FF
|
||||
#define ddpHopShift 10
|
||||
#define ddpSize 13 /* size of DDP header (avoid struct padding) */
|
||||
#define ddpSSize 5
|
||||
#define ddpWKS 128 /* boundary of DDP well known sockets */
|
||||
#define ddpRTMP 1 /* RTMP type */
|
||||
#define ddpRTMPrequest 5 /* RTMP request type */
|
||||
#define ddpNBP 2 /* NBP type */
|
||||
#define ddpATP 3 /* ATP type */
|
||||
#define ddpECHO 4 /* ECHO type */
|
||||
#define ddpIP 22 /* IP type */
|
||||
#define ddpARP 23 /* ARP type */
|
||||
#define ddpKLAP 0x4b /* Kinetics KLAP type */
|
||||
|
||||
|
||||
/* AppleTalk Transaction Protocol */
|
||||
|
||||
struct atATP {
|
||||
u_char control;
|
||||
u_char bitmap;
|
||||
u_short transID;
|
||||
int32 userData;
|
||||
};
|
||||
|
||||
#define atpReqCode 0x40
|
||||
#define atpRspCode 0x80
|
||||
#define atpRelCode 0xC0
|
||||
#define atpXO 0x20
|
||||
#define atpEOM 0x10
|
||||
#define atpSTS 0x08
|
||||
#define atpFlagMask 0x3F
|
||||
#define atpControlMask 0xF8
|
||||
#define atpMaxNum 8
|
||||
#define atpMaxData 578
|
||||
|
||||
|
||||
/* AppleTalk Echo Protocol */
|
||||
|
||||
struct atEcho {
|
||||
u_char echoFunction;
|
||||
u_char *echoData;
|
||||
};
|
||||
|
||||
#define echoSkt 4 /* the echoer socket */
|
||||
#define echoSize 1 /* size of echo header */
|
||||
#define echoRequest 1 /* echo request */
|
||||
#define echoReply 2 /* echo request */
|
||||
|
||||
|
||||
/* Name Binding Protocol */
|
||||
|
||||
struct atNBP {
|
||||
u_char control;
|
||||
u_char id;
|
||||
};
|
||||
|
||||
struct atNBPtuple {
|
||||
u_short net;
|
||||
u_char node;
|
||||
u_char skt;
|
||||
u_char enumerator;
|
||||
};
|
||||
|
||||
#define nbpBrRq 0x10
|
||||
#define nbpLkUp 0x20
|
||||
#define nbpLkUpReply 0x30
|
||||
|
||||
#define nbpNIS 2
|
||||
#define nbpTupleMax 15
|
||||
|
||||
#define nbpHeaderSize 2
|
||||
#define nbpTupleSize 5
|
||||
|
||||
#define nbpSkt 2 /* NIS */
|
||||
|
||||
|
||||
/* Routing Table Maint. Protocol */
|
||||
|
||||
#define rtmpSkt 1 /* number of RTMP socket */
|
||||
#define rtmpSize 4 /* minimum size */
|
||||
#define rtmpTupleSize 3
|
||||
|
||||
|
||||
/* Zone Information Protocol */
|
||||
|
||||
struct zipHeader {
|
||||
u_char command;
|
||||
u_char netcount;
|
||||
};
|
||||
|
||||
#define zipHeaderSize 2
|
||||
#define zipQuery 1
|
||||
#define zipReply 2
|
||||
#define zipTakedown 3
|
||||
#define zipBringup 4
|
||||
#define ddpZIP 6
|
||||
#define zipSkt 6
|
||||
#define GetMyZone 7
|
||||
#define GetZoneList 8
|
||||
|
||||
/*
|
||||
* UDP port range used for ddp-in-udp encapsulation is 16512-16639
|
||||
* for client sockets (128-255) and 200-327 for server sockets
|
||||
* (0-127). We also try to recognize the pre-April 88 server
|
||||
* socket range of 768-895.
|
||||
*/
|
||||
#define atalk_port(p) \
|
||||
(((unsigned)((p) - 16512) < 128) || \
|
||||
((unsigned)((p) - 200) < 128) || \
|
||||
((unsigned)((p) - 768) < 128))
|
@ -1,109 +0,0 @@
|
||||
/* @(#) $Header: bootp.h,v 1.6 94/01/13 19:06:29 leres Exp $ (LBL) */
|
||||
/*
|
||||
* Bootstrap Protocol (BOOTP). RFC951 and RFC1048.
|
||||
*
|
||||
* This file specifies the "implementation-independent" BOOTP protocol
|
||||
* information which is common to both client and server.
|
||||
*
|
||||
* Copyright 1988 by Carnegie Mellon.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this program for any
|
||||
* purpose and without fee is hereby granted, provided that this copyright
|
||||
* and permission notice appear on all copies and supporting documentation,
|
||||
* the name of Carnegie Mellon not be used in advertising or publicity
|
||||
* pertaining to distribution of the program without specific prior
|
||||
* permission, and notice be given in supporting documentation that copying
|
||||
* and distribution is by permission of Carnegie Mellon and Stanford
|
||||
* University. Carnegie Mellon makes no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*/
|
||||
|
||||
|
||||
struct bootp {
|
||||
unsigned char bp_op; /* packet opcode type */
|
||||
unsigned char bp_htype; /* hardware addr type */
|
||||
unsigned char bp_hlen; /* hardware addr length */
|
||||
unsigned char bp_hops; /* gateway hops */
|
||||
u_int32 bp_xid; /* transaction ID */
|
||||
unsigned short bp_secs; /* seconds since boot began */
|
||||
unsigned short bp_unused;
|
||||
struct in_addr bp_ciaddr; /* client IP address */
|
||||
struct in_addr bp_yiaddr; /* 'your' IP address */
|
||||
struct in_addr bp_siaddr; /* server IP address */
|
||||
struct in_addr bp_giaddr; /* gateway IP address */
|
||||
unsigned char bp_chaddr[16]; /* client hardware address */
|
||||
unsigned char bp_sname[64]; /* server host name */
|
||||
unsigned char bp_file[128]; /* boot file name */
|
||||
unsigned char bp_vend[64]; /* vendor-specific area */
|
||||
};
|
||||
|
||||
/*
|
||||
* UDP port numbers, server and client.
|
||||
*/
|
||||
#define IPPORT_BOOTPS 67
|
||||
#define IPPORT_BOOTPC 68
|
||||
|
||||
#define BOOTREPLY 2
|
||||
#define BOOTREQUEST 1
|
||||
|
||||
|
||||
/*
|
||||
* Vendor magic cookie (v_magic) for CMU
|
||||
*/
|
||||
#define VM_CMU "CMU"
|
||||
|
||||
/*
|
||||
* Vendor magic cookie (v_magic) for RFC1048
|
||||
*/
|
||||
#define VM_RFC1048 { 99, 130, 83, 99 }
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* RFC1048 tag values used to specify what information is being supplied in
|
||||
* the vendor field of the packet.
|
||||
*/
|
||||
|
||||
#define TAG_PAD ((unsigned char) 0)
|
||||
#define TAG_SUBNET_MASK ((unsigned char) 1)
|
||||
#define TAG_TIME_OFFSET ((unsigned char) 2)
|
||||
#define TAG_GATEWAY ((unsigned char) 3)
|
||||
#define TAG_TIME_SERVER ((unsigned char) 4)
|
||||
#define TAG_NAME_SERVER ((unsigned char) 5)
|
||||
#define TAG_DOMAIN_SERVER ((unsigned char) 6)
|
||||
#define TAG_LOG_SERVER ((unsigned char) 7)
|
||||
#define TAG_COOKIE_SERVER ((unsigned char) 8)
|
||||
#define TAG_LPR_SERVER ((unsigned char) 9)
|
||||
#define TAG_IMPRESS_SERVER ((unsigned char) 10)
|
||||
#define TAG_RLP_SERVER ((unsigned char) 11)
|
||||
#define TAG_HOSTNAME ((unsigned char) 12)
|
||||
#define TAG_BOOTSIZE ((unsigned char) 13)
|
||||
#define TAG_END ((unsigned char) 255)
|
||||
/* RFC1497 tags */
|
||||
#define TAG_DUMPPATH ((unsigned char) 14)
|
||||
#define TAG_DOMAINNAME ((unsigned char) 15)
|
||||
#define TAG_SWAP_SERVER ((unsigned char) 16)
|
||||
#define TAG_ROOTPATH ((unsigned char) 17)
|
||||
#define TAG_EXTPATH ((unsigned char) 18)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* "vendor" data permitted for CMU bootp clients.
|
||||
*/
|
||||
|
||||
struct cmu_vend {
|
||||
unsigned char v_magic[4]; /* magic number */
|
||||
u_int32 v_flags; /* flags/opcodes, etc. */
|
||||
struct in_addr v_smask; /* Subnet mask */
|
||||
struct in_addr v_dgate; /* Default gateway */
|
||||
struct in_addr v_dns1, v_dns2; /* Domain name servers */
|
||||
struct in_addr v_ins1, v_ins2; /* IEN-116 name servers */
|
||||
struct in_addr v_ts1, v_ts2; /* Time servers */
|
||||
unsigned char v_unused[24]; /* currently unused */
|
||||
};
|
||||
|
||||
|
||||
/* v_flags values */
|
||||
#define VF_SMASK 1 /* Subnet mask field contains valid data */
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1992, 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.
|
||||
*/
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: bpf_dump.c,v 1.6 94/06/06 14:31:21 leres Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <pcap.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
extern void bpf_dump(struct bpf_program *, int);
|
||||
|
||||
void
|
||||
bpf_dump(struct bpf_program *p, int option)
|
||||
{
|
||||
struct bpf_insn *insn;
|
||||
int i;
|
||||
int n = p->bf_len;
|
||||
|
||||
insn = p->bf_insns;
|
||||
if (option > 2) {
|
||||
printf("%d\n", n);
|
||||
for (i = 0; i < n; ++insn, ++i) {
|
||||
printf("%lu %lu %lu %lu\n", insn->code,
|
||||
insn->jt, insn->jf, insn->k);
|
||||
}
|
||||
return ;
|
||||
}
|
||||
if (option > 1) {
|
||||
for (i = 0; i < n; ++insn, ++i)
|
||||
printf("{ 0x%x, %d, %d, 0x%08x },\n",
|
||||
insn->code, insn->jt, insn->jf, insn->k);
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < n; ++insn, ++i) {
|
||||
#ifdef BDEBUG
|
||||
extern int bids[];
|
||||
printf(bids[i] > 0 ? "[%02d]" : " -- ", bids[i] - 1);
|
||||
#endif
|
||||
puts(bpf_image(insn, i));
|
||||
}
|
||||
}
|
@ -1,480 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1992, 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.
|
||||
*
|
||||
* @(#) $Header: decnet.h,v 1.3 94/06/14 20:11:44 leres Exp $ (LBL)
|
||||
*/
|
||||
|
||||
typedef unsigned char byte[1]; /* single byte field */
|
||||
typedef unsigned char word[2]; /* 2 byte field */
|
||||
typedef unsigned char longword[4]; /* 4 bytes field */
|
||||
|
||||
/*
|
||||
* Definitions for DECNET Phase IV protocol headers
|
||||
*/
|
||||
union etheraddress {
|
||||
unsigned char dne_addr[6]; /* full ethernet address */
|
||||
struct {
|
||||
unsigned char dne_hiord[4]; /* DECnet HIORD prefix */
|
||||
unsigned char dne_nodeaddr[2]; /* DECnet node address */
|
||||
} dne_remote;
|
||||
};
|
||||
|
||||
typedef union etheraddress etheraddr; /* Ethernet address */
|
||||
|
||||
#define HIORD 0x000400aa /* high 32-bits of address (swapped) */
|
||||
|
||||
#define AREAMASK 0176000 /* mask for area field */
|
||||
#define AREASHIFT 10 /* bit-offset for area field */
|
||||
#define NODEMASK 01777 /* mask for node address field */
|
||||
|
||||
#define DN_MAXADDL 20 /* max size of DECnet address */
|
||||
struct dn_naddr {
|
||||
unsigned short a_len; /* length of address */
|
||||
unsigned char a_addr[DN_MAXADDL]; /* address as bytes */
|
||||
};
|
||||
|
||||
/*
|
||||
* Define long and short header formats.
|
||||
*/
|
||||
struct shorthdr
|
||||
{
|
||||
byte sh_flags; /* route flags */
|
||||
word sh_dst; /* destination node address */
|
||||
word sh_src; /* source node address */
|
||||
byte sh_visits; /* visit count */
|
||||
};
|
||||
|
||||
struct longhdr
|
||||
{
|
||||
byte lg_flags; /* route flags */
|
||||
byte lg_darea; /* destination area (reserved) */
|
||||
byte lg_dsarea; /* destination subarea (reserved) */
|
||||
etheraddr lg_dst; /* destination id */
|
||||
byte lg_sarea; /* source area (reserved) */
|
||||
byte lg_ssarea; /* source subarea (reserved) */
|
||||
etheraddr lg_src; /* source id */
|
||||
byte lg_nextl2; /* next level 2 router (reserved) */
|
||||
byte lg_visits; /* visit count */
|
||||
byte lg_service; /* service class (reserved) */
|
||||
byte lg_pt; /* protocol type (reserved) */
|
||||
};
|
||||
|
||||
union routehdr
|
||||
{
|
||||
struct shorthdr rh_short; /* short route header */
|
||||
struct longhdr rh_long; /* long route header */
|
||||
};
|
||||
|
||||
/*
|
||||
* Define the values of various fields in the protocol messages.
|
||||
*
|
||||
* 1. Data packet formats.
|
||||
*/
|
||||
#define RMF_MASK 7 /* mask for message type */
|
||||
#define RMF_SHORT 2 /* short message format */
|
||||
#define RMF_LONG 6 /* long message format */
|
||||
#ifndef RMF_RQR
|
||||
#define RMF_RQR 010 /* request return to sender */
|
||||
#define RMF_RTS 020 /* returning to sender */
|
||||
#define RMF_IE 040 /* intra-ethernet packet */
|
||||
#endif /* RMR_RQR */
|
||||
#define RMF_FVER 0100 /* future version flag */
|
||||
#define RMF_PAD 0200 /* pad field */
|
||||
#define RMF_PADMASK 0177 /* pad field mask */
|
||||
|
||||
#define VIS_MASK 077 /* visit field mask */
|
||||
|
||||
/*
|
||||
* 2. Control packet formats.
|
||||
*/
|
||||
#define RMF_CTLMASK 017 /* mask for message type */
|
||||
#define RMF_CTLMSG 01 /* control message indicator */
|
||||
#define RMF_INIT 01 /* initialisation message */
|
||||
#define RMF_VER 03 /* verification message */
|
||||
#define RMF_TEST 05 /* hello and test message */
|
||||
#define RMF_L1ROUT 07 /* level 1 routing message */
|
||||
#define RMF_L2ROUT 011 /* level 2 routing message */
|
||||
#define RMF_RHELLO 013 /* router hello message */
|
||||
#define RMF_EHELLO 015 /* endnode hello message */
|
||||
|
||||
#define TI_L2ROUT 01 /* level 2 router */
|
||||
#define TI_L1ROUT 02 /* level 1 router */
|
||||
#define TI_ENDNODE 03 /* endnode */
|
||||
#define TI_VERIF 04 /* verification required */
|
||||
#define TI_BLOCK 010 /* blocking requested */
|
||||
|
||||
#define VE_VERS 2 /* version number (2) */
|
||||
#define VE_ECO 0 /* ECO number */
|
||||
#define VE_UECO 0 /* user ECO number (0) */
|
||||
|
||||
#define P3_VERS 1 /* phase III version number (1) */
|
||||
#define P3_ECO 3 /* ECO number (3) */
|
||||
#define P3_UECO 0 /* user ECO number (0) */
|
||||
|
||||
#define II_L2ROUT 01 /* level 2 router */
|
||||
#define II_L1ROUT 02 /* level 1 router */
|
||||
#define II_ENDNODE 03 /* endnode */
|
||||
#define II_VERIF 04 /* verification required */
|
||||
#define II_NOMCAST 040 /* no multicast traffic accepted */
|
||||
#define II_BLOCK 0100 /* blocking requested */
|
||||
#define II_TYPEMASK 03 /* mask for node type */
|
||||
|
||||
#define TESTDATA 0252 /* test data bytes */
|
||||
#define TESTLEN 1 /* length of transmitted test data */
|
||||
|
||||
/*
|
||||
* Define control message formats.
|
||||
*/
|
||||
struct initmsgIII /* phase III initialisation message */
|
||||
{
|
||||
byte inIII_flags; /* route flags */
|
||||
word inIII_src; /* source node address */
|
||||
byte inIII_info; /* routing layer information */
|
||||
word inIII_blksize; /* maximum data link block size */
|
||||
byte inIII_vers; /* version number */
|
||||
byte inIII_eco; /* ECO number */
|
||||
byte inIII_ueco; /* user ECO number */
|
||||
byte inIII_rsvd; /* reserved image field */
|
||||
};
|
||||
|
||||
struct initmsg /* initialisation message */
|
||||
{
|
||||
byte in_flags; /* route flags */
|
||||
word in_src; /* source node address */
|
||||
byte in_info; /* routing layer information */
|
||||
word in_blksize; /* maximum data link block size */
|
||||
byte in_vers; /* version number */
|
||||
byte in_eco; /* ECO number */
|
||||
byte in_ueco; /* user ECO number */
|
||||
word in_hello; /* hello timer */
|
||||
byte in_rsvd; /* reserved image field */
|
||||
};
|
||||
|
||||
struct verifmsg /* verification message */
|
||||
{
|
||||
byte ve_flags; /* route flags */
|
||||
word ve_src; /* source node address */
|
||||
byte ve_fcnval; /* function value image field */
|
||||
};
|
||||
|
||||
struct testmsg /* hello and test message */
|
||||
{
|
||||
byte te_flags; /* route flags */
|
||||
word te_src; /* source node address */
|
||||
byte te_data; /* test data image field */
|
||||
};
|
||||
|
||||
struct l1rout /* level 1 routing message */
|
||||
{
|
||||
byte r1_flags; /* route flags */
|
||||
word r1_src; /* source node address */
|
||||
byte r1_rsvd; /* reserved field */
|
||||
};
|
||||
|
||||
struct l2rout /* level 2 routing message */
|
||||
{
|
||||
byte r2_flags; /* route flags */
|
||||
word r2_src; /* source node address */
|
||||
byte r2_rsvd; /* reserved field */
|
||||
};
|
||||
|
||||
struct rhellomsg /* router hello message */
|
||||
{
|
||||
byte rh_flags; /* route flags */
|
||||
byte rh_vers; /* version number */
|
||||
byte rh_eco; /* ECO number */
|
||||
byte rh_ueco; /* user ECO number */
|
||||
etheraddr rh_src; /* source id */
|
||||
byte rh_info; /* routing layer information */
|
||||
word rh_blksize; /* maximum data link block size */
|
||||
byte rh_priority; /* router's priority */
|
||||
byte rh_area; /* reserved */
|
||||
word rh_hello; /* hello timer */
|
||||
byte rh_mpd; /* reserved */
|
||||
};
|
||||
|
||||
struct ehellomsg /* endnode hello message */
|
||||
{
|
||||
byte eh_flags; /* route flags */
|
||||
byte eh_vers; /* version number */
|
||||
byte eh_eco; /* ECO number */
|
||||
byte eh_ueco; /* user ECO number */
|
||||
etheraddr eh_src; /* source id */
|
||||
byte eh_info; /* routing layer information */
|
||||
word eh_blksize; /* maximum data link block size */
|
||||
byte eh_area; /* area (reserved) */
|
||||
byte eh_seed[8]; /* verification seed */
|
||||
etheraddr eh_router; /* designated router */
|
||||
word eh_hello; /* hello timer */
|
||||
byte eh_mpd; /* (reserved) */
|
||||
byte eh_data; /* test data image field */
|
||||
};
|
||||
|
||||
union controlmsg
|
||||
{
|
||||
struct initmsg cm_init; /* initialisation message */
|
||||
struct verifmsg cm_ver; /* verification message */
|
||||
struct testmsg cm_test; /* hello and test message */
|
||||
struct l1rout cm_l1rou; /* level 1 routing message */
|
||||
struct l2rout cm_l2rout; /* level 2 routing message */
|
||||
struct rhellomsg cm_rhello; /* router hello message */
|
||||
struct ehellomsg cm_ehello; /* endnode hello message */
|
||||
};
|
||||
|
||||
/* Macros for decoding routing-info fields */
|
||||
#define RI_COST(x) ((x)&0777)
|
||||
#define RI_HOPS(x) (((x)>>10)&037)
|
||||
|
||||
/*
|
||||
* NSP protocol fields and values.
|
||||
*/
|
||||
|
||||
#define NSP_TYPEMASK 014 /* mask to isolate type code */
|
||||
#define NSP_SUBMASK 0160 /* mask to isolate subtype code */
|
||||
#define NSP_SUBSHFT 4 /* shift to move subtype code */
|
||||
|
||||
#define MFT_DATA 0 /* data message */
|
||||
#define MFT_ACK 04 /* acknowledgement message */
|
||||
#define MFT_CTL 010 /* control message */
|
||||
|
||||
#define MFS_ILS 020 /* data or I/LS indicator */
|
||||
#define MFS_BOM 040 /* beginning of message (data) */
|
||||
#define MFS_MOM 0 /* middle of message (data) */
|
||||
#define MFS_EOM 0100 /* end of message (data) */
|
||||
#define MFS_INT 040 /* interrupt message */
|
||||
|
||||
#define MFS_DACK 0 /* data acknowledgement */
|
||||
#define MFS_IACK 020 /* I/LS acknowledgement */
|
||||
#define MFS_CACK 040 /* connect acknowledgement */
|
||||
|
||||
#define MFS_NOP 0 /* no operation */
|
||||
#define MFS_CI 020 /* connect initiate */
|
||||
#define MFS_CC 040 /* connect confirm */
|
||||
#define MFS_DI 060 /* disconnect initiate */
|
||||
#define MFS_DC 0100 /* disconnect confirm */
|
||||
#define MFS_RCI 0140 /* retransmitted connect initiate */
|
||||
|
||||
#define SGQ_ACK 0100000 /* ack */
|
||||
#define SGQ_NAK 0110000 /* negative ack */
|
||||
#define SGQ_OACK 0120000 /* other channel ack */
|
||||
#define SGQ_ONAK 0130000 /* other channel negative ack */
|
||||
#define SGQ_MASK 07777 /* mask to isolate seq # */
|
||||
#define SGQ_OTHER 020000 /* other channel qualifier */
|
||||
#define SGQ_DELAY 010000 /* ack delay flag */
|
||||
|
||||
#define SGQ_EOM 0100000 /* pseudo flag for end-of-message */
|
||||
|
||||
#define LSM_MASK 03 /* mask for modifier field */
|
||||
#define LSM_NOCHANGE 0 /* no change */
|
||||
#define LSM_DONOTSEND 1 /* do not send data */
|
||||
#define LSM_SEND 2 /* send data */
|
||||
|
||||
#define LSI_MASK 014 /* mask for interpretation field */
|
||||
#define LSI_DATA 0 /* data segment or message count */
|
||||
#define LSI_INTR 4 /* interrupt request count */
|
||||
#define LSI_INTM 0377 /* funny marker for int. message */
|
||||
|
||||
#define COS_MASK 014 /* mask for flow control field */
|
||||
#define COS_NONE 0 /* no flow control */
|
||||
#define COS_SEGMENT 04 /* segment flow control */
|
||||
#define COS_MESSAGE 010 /* message flow control */
|
||||
#define COS_CRYPTSER 020 /* cryptographic services requested */
|
||||
#define COS_DEFAULT 1 /* default value for field */
|
||||
|
||||
#define COI_MASK 3 /* mask for version field */
|
||||
#define COI_32 0 /* version 3.2 */
|
||||
#define COI_31 1 /* version 3.1 */
|
||||
#define COI_40 2 /* version 4.0 */
|
||||
#define COI_41 3 /* version 4.1 */
|
||||
|
||||
#define MNU_MASK 140 /* mask for session control version */
|
||||
#define MNU_10 000 /* session V1.0 */
|
||||
#define MNU_20 040 /* session V2.0 */
|
||||
#define MNU_ACCESS 1 /* access control present */
|
||||
#define MNU_USRDATA 2 /* user data field present */
|
||||
#define MNU_INVKPROXY 4 /* invoke proxy field present */
|
||||
#define MNU_UICPROXY 8 /* use uic-based proxy */
|
||||
|
||||
#define DC_NORESOURCES 1 /* no resource reason code */
|
||||
#define DC_NOLINK 41 /* no link terminate reason code */
|
||||
#define DC_COMPLETE 42 /* disconnect complete reason code */
|
||||
|
||||
#define DI_NOERROR 0 /* user disconnect */
|
||||
#define DI_SHUT 3 /* node is shutting down */
|
||||
#define DI_NOUSER 4 /* destination end user does not exist */
|
||||
#define DI_INVDEST 5 /* invalid end user destination */
|
||||
#define DI_REMRESRC 6 /* insufficient remote resources */
|
||||
#define DI_TPA 8 /* third party abort */
|
||||
#define DI_PROTOCOL 7 /* protocol error discovered */
|
||||
#define DI_ABORT 9 /* user abort */
|
||||
#define DI_LOCALRESRC 32 /* insufficient local resources */
|
||||
#define DI_REMUSERRESRC 33 /* insufficient remote user resources */
|
||||
#define DI_BADACCESS 34 /* bad access control information */
|
||||
#define DI_BADACCNT 36 /* bad ACCOUNT information */
|
||||
#define DI_CONNECTABORT 38 /* connect request cancelled */
|
||||
#define DI_TIMEDOUT 38 /* remote node or user crashed */
|
||||
#define DI_UNREACHABLE 39 /* local timers expired due to ... */
|
||||
#define DI_BADIMAGE 43 /* bad image data in connect */
|
||||
#define DI_SERVMISMATCH 54 /* cryptographic service mismatch */
|
||||
|
||||
#define UC_OBJREJECT 0 /* object rejected connect */
|
||||
#define UC_USERDISCONNECT 0 /* user disconnect */
|
||||
#define UC_RESOURCES 1 /* insufficient resources (local or remote) */
|
||||
#define UC_NOSUCHNODE 2 /* unrecognised node name */
|
||||
#define UC_REMOTESHUT 3 /* remote node shutting down */
|
||||
#define UC_NOSUCHOBJ 4 /* unrecognised object */
|
||||
#define UC_INVOBJFORMAT 5 /* invalid object name format */
|
||||
#define UC_OBJTOOBUSY 6 /* object too busy */
|
||||
#define UC_NETWORKABORT 8 /* network abort */
|
||||
#define UC_USERABORT 9 /* user abort */
|
||||
#define UC_INVNODEFORMAT 10 /* invalid node name format */
|
||||
#define UC_LOCALSHUT 11 /* local node shutting down */
|
||||
#define UC_ACCESSREJECT 34 /* invalid access control information */
|
||||
#define UC_NORESPONSE 38 /* no response from object */
|
||||
#define UC_UNREACHABLE 39 /* node unreachable */
|
||||
|
||||
/*
|
||||
* NSP message formats.
|
||||
*/
|
||||
struct nsphdr /* general nsp header */
|
||||
{
|
||||
byte nh_flags; /* message flags */
|
||||
word nh_dst; /* destination link address */
|
||||
word nh_src; /* source link address */
|
||||
};
|
||||
|
||||
struct seghdr /* data segment header */
|
||||
{
|
||||
byte sh_flags; /* message flags */
|
||||
word sh_dst; /* destination link address */
|
||||
word sh_src; /* source link address */
|
||||
word sh_seq[3]; /* sequence numbers */
|
||||
};
|
||||
|
||||
struct minseghdr /* minimum data segment header */
|
||||
{
|
||||
byte ms_flags; /* message flags */
|
||||
word ms_dst; /* destination link address */
|
||||
word ms_src; /* source link address */
|
||||
word ms_seq; /* sequence number */
|
||||
};
|
||||
|
||||
struct lsmsg /* link service message (after hdr) */
|
||||
{
|
||||
byte ls_lsflags; /* link service flags */
|
||||
byte ls_fcval; /* flow control value */
|
||||
};
|
||||
|
||||
struct ackmsg /* acknowledgement message */
|
||||
{
|
||||
byte ak_flags; /* message flags */
|
||||
word ak_dst; /* destination link address */
|
||||
word ak_src; /* source link address */
|
||||
word ak_acknum[2]; /* acknowledgement numbers */
|
||||
};
|
||||
|
||||
struct minackmsg /* minimum acknowledgement message */
|
||||
{
|
||||
byte mk_flags; /* message flags */
|
||||
word mk_dst; /* destination link address */
|
||||
word mk_src; /* source link address */
|
||||
word mk_acknum; /* acknowledgement number */
|
||||
};
|
||||
|
||||
struct ciackmsg /* connect acknowledgement message */
|
||||
{
|
||||
byte ck_flags; /* message flags */
|
||||
word ck_dst; /* destination link address */
|
||||
};
|
||||
|
||||
struct cimsg /* connect initiate message */
|
||||
{
|
||||
byte ci_flags; /* message flags */
|
||||
word ci_dst; /* destination link address (0) */
|
||||
word ci_src; /* source link address */
|
||||
byte ci_services; /* requested services */
|
||||
byte ci_info; /* information */
|
||||
word ci_segsize; /* maximum segment size */
|
||||
};
|
||||
|
||||
struct ccmsg /* connect confirm message */
|
||||
{
|
||||
byte cc_flags; /* message flags */
|
||||
word cc_dst; /* destination link address */
|
||||
word cc_src; /* source link address */
|
||||
byte cc_services; /* requested services */
|
||||
byte cc_info; /* information */
|
||||
word cc_segsize; /* maximum segment size */
|
||||
byte cc_optlen; /* optional data length */
|
||||
};
|
||||
|
||||
struct cnmsg /* generic connect message */
|
||||
{
|
||||
byte cn_flags; /* message flags */
|
||||
word cn_dst; /* destination link address */
|
||||
word cn_src; /* source link address */
|
||||
byte cn_services; /* requested services */
|
||||
byte cn_info; /* information */
|
||||
word cn_segsize; /* maximum segment size */
|
||||
};
|
||||
|
||||
struct dimsg /* disconnect initiate message */
|
||||
{
|
||||
byte di_flags; /* message flags */
|
||||
word di_dst; /* destination link address */
|
||||
word di_src; /* source link address */
|
||||
word di_reason; /* reason code */
|
||||
byte di_optlen; /* optional data length */
|
||||
};
|
||||
|
||||
struct dcmsg /* disconnect confirm message */
|
||||
{
|
||||
byte dc_flags; /* message flags */
|
||||
word dc_dst; /* destination link address */
|
||||
word dc_src; /* source link address */
|
||||
word dc_reason; /* reason code */
|
||||
};
|
||||
|
||||
/*
|
||||
* Like the macros in extract.h, except that since DECNET is a little-endian
|
||||
* protocol, the BYTEORDER sense is reversed.
|
||||
*/
|
||||
#define EXTRACT_8BITS(p) (*(p))
|
||||
#if BYTEORDER == BIG_ENDIAN
|
||||
#define EXTRACT_16BITS(p)\
|
||||
((u_short)\
|
||||
(*((u_char *)p+1)<<8|\
|
||||
*((u_char *)p+0)<<0))
|
||||
#define EXTRACT_32BITS(p)\
|
||||
(*((u_char *)p+3)<<24|\
|
||||
*((u_char *)p+2)<<16|\
|
||||
*((u_char *)p+1)<<8|\
|
||||
*((u_char *)p+0)<<0)
|
||||
#else
|
||||
#define EXTRACT_16BITS(p)\
|
||||
((u_short)\
|
||||
(*((u_char *)p+0)<<8|\
|
||||
*((u_char *)p+1)<<0))
|
||||
#define EXTRACT_32BITS(p)\
|
||||
(*((u_char *)p+0)<<24|\
|
||||
*((u_char *)p+1)<<16|\
|
||||
*((u_char *)p+2)<<8|\
|
||||
*((u_char *)p+3)<<0)
|
||||
#endif
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* @(#) $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/ethertype.h,v 1.1 1995/03/08 12:52:12 olah Exp $ (LBL)
|
||||
*/
|
||||
|
||||
/* Map between Ethernet protocol types and names */
|
||||
|
||||
/* Add other Ethernet packet types here */
|
||||
#ifndef ETHERTYPE_SPRITE
|
||||
#define ETHERTYPE_SPRITE 0x0500
|
||||
#endif
|
||||
#ifndef ETHERTYPE_MOPDL
|
||||
#define ETHERTYPE_MOPDL 0x6001
|
||||
#endif
|
||||
#ifndef ETHERTYPE_MOPRC
|
||||
#define ETHERTYPE_MOPRC 0x6002
|
||||
#endif
|
||||
#ifndef ETHERTYPE_DN
|
||||
#define ETHERTYPE_DN 0x6003
|
||||
#endif
|
||||
#ifndef ETHERTYPE_LAT
|
||||
#define ETHERTYPE_LAT 0x6004
|
||||
#endif
|
||||
#ifndef ETHERTYPE_LANBRIDGE
|
||||
#define ETHERTYPE_LANBRIDGE 0x8038
|
||||
#endif
|
||||
#ifndef ETHERTYPE_DECDNS
|
||||
#define ETHERTYPE_DECDNS 0x803c
|
||||
#endif
|
||||
#ifndef ETHERTYPE_DECDTS
|
||||
#define ETHERTYPE_DECDTS 0x803e
|
||||
#endif
|
||||
#ifndef ETHERTYPE_VEXP
|
||||
#define ETHERTYPE_VEXP 0x805b
|
||||
#endif
|
||||
#ifndef ETHERTYPE_VPROD
|
||||
#define ETHERTYPE_VPROD 0x805c
|
||||
#endif
|
||||
#ifndef ETHERTYPE_LOOPBACK
|
||||
#define ETHERTYPE_LOOPBACK 0x9000
|
||||
#endif
|
||||
|
||||
#ifndef ETHERTYPE_ATALK
|
||||
#define ETHERTYPE_ATALK 0x809b
|
||||
#endif
|
||||
#ifndef ETHERTYPE_AARP
|
||||
#define ETHERTYPE_AARP 0x80f3
|
||||
#endif
|
||||
#ifndef ETHERTYPE_NS
|
||||
#define ETHERTYPE_NS 0x0600
|
||||
#endif
|
||||
#ifndef ETHERTYPE_IPX
|
||||
#define ETHERTYPE_IPX 0x8137
|
||||
#endif
|
||||
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1992, 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.
|
||||
*
|
||||
* @(#) $Header: extract.h,v 1.7 94/06/14 20:11:45 leres Exp $ (LBL)
|
||||
*/
|
||||
|
||||
#ifdef TCPDUMP_ALIGN
|
||||
#if BYTEORDER == LITTLE_ENDIAN
|
||||
#define EXTRACT_SHORT(p)\
|
||||
((u_short)\
|
||||
((u_short)*((u_char *)p+1)<<8|\
|
||||
(u_short)*((u_char *)p+0)<<0))
|
||||
#define EXTRACT_LONG(p)\
|
||||
((u_int32)*((u_char *)p+3)<<24|\
|
||||
(u_int32)*((u_char *)p+2)<<16|\
|
||||
(u_int32)*((u_char *)p+1)<<8|\
|
||||
(u_int32)*((u_char *)p+0)<<0)
|
||||
#else
|
||||
#define EXTRACT_SHORT(p)\
|
||||
((u_short)\
|
||||
((u_short)*((u_char *)p+0)<<8|\
|
||||
(u_short)*((u_char *)p+1)<<0))
|
||||
#define EXTRACT_LONG(p)\
|
||||
((u_int32)*((u_char *)p+0)<<24|\
|
||||
(u_int32)*((u_char *)p+1)<<16|\
|
||||
(u_int32)*((u_char *)p+2)<<8|\
|
||||
(u_int32)*((u_char *)p+3)<<0)
|
||||
#endif
|
||||
#else
|
||||
#define EXTRACT_SHORT(p) ((u_short)ntohs(*(u_short *)p))
|
||||
#define EXTRACT_LONG(p) (ntohl(*(u_int32 *)p))
|
||||
#endif
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1992, 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.
|
||||
*
|
||||
* @(#) $Header: fddi.h,v 1.6 94/06/14 20:12:35 leres Exp $ (LBL)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Based on Ultrix if_fddi.h
|
||||
*/
|
||||
|
||||
/*
|
||||
* This stuff should come from a system header file, but there's no
|
||||
* obviously portable way to do that and it's not really going
|
||||
* to change from system to system (except for the padding business).
|
||||
*/
|
||||
|
||||
struct fddi_header {
|
||||
#if defined(ultrix) || defined(__alpha)
|
||||
/* Ultrix pads to make everything line up on a nice boundary */
|
||||
#define FDDIPAD 3
|
||||
u_char fddi_ph[FDDIPAD];
|
||||
#else
|
||||
#define FDDIPAD 0
|
||||
#endif
|
||||
u_char fddi_fc; /* frame control */
|
||||
u_char fddi_dhost[6];
|
||||
u_char fddi_shost[6];
|
||||
};
|
||||
|
||||
|
||||
/* Useful values for fddi_fc (frame control) field */
|
||||
|
||||
/*
|
||||
* FDDI Frame Control bits
|
||||
*/
|
||||
#define FDDIFC_C 0x80 /* Class bit */
|
||||
#define FDDIFC_L 0x40 /* Address length bit */
|
||||
#define FDDIFC_F 0x30 /* Frame format bits */
|
||||
#define FDDIFC_Z 0x0f /* Control bits */
|
||||
|
||||
/*
|
||||
* FDDI Frame Control values. (48-bit addressing only).
|
||||
*/
|
||||
#define FDDIFC_VOID 0x40 /* Void frame */
|
||||
#define FDDIFC_NRT 0x80 /* Nonrestricted token */
|
||||
#define FDDIFC_RT 0xc0 /* Restricted token */
|
||||
#define FDDIFC_SMT_INFO 0x41 /* SMT Info */
|
||||
#define FDDIFC_SMT_NSA 0x4F /* SMT Next station adrs */
|
||||
#define FDDIFC_MAC_BEACON 0xc2 /* MAC Beacon frame */
|
||||
#define FDDIFC_MAC_CLAIM 0xc3 /* MAC Claim frame */
|
||||
#define FDDIFC_LLC_ASYNC 0x50 /* Async. LLC frame */
|
||||
#define FDDIFC_LLC_SYNC 0xd0 /* Sync. LLC frame */
|
||||
#define FDDIFC_IMP_ASYNC 0x60 /* Implementor Async. */
|
||||
#define FDDIFC_IMP_SYNC 0xe0 /* Implementor Synch. */
|
||||
#define FDDIFC_SMT 0x40 /* SMT frame */
|
||||
#define FDDIFC_MAC 0xc0 /* MAC frame */
|
||||
|
||||
#define FDDIFC_CLFF 0xF0 /* Class/Length/Format bits */
|
||||
#define FDDIFC_ZZZZ 0x0F /* Control bits */
|
@ -1,150 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 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.
|
||||
*
|
||||
* @(#) $Header: interface.h,v 1.66 94/06/14 20:21:37 leres Exp $ (LBL)
|
||||
*/
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define inline __inline
|
||||
#ifndef __dead
|
||||
#define __dead volatile
|
||||
#endif
|
||||
#else
|
||||
#define inline
|
||||
#define __dead
|
||||
#endif
|
||||
|
||||
#include "os.h" /* operating system stuff */
|
||||
#include "md.h" /* machine dependent stuff */
|
||||
|
||||
#ifndef SIGRET
|
||||
#define SIGRET void /* default */
|
||||
#endif
|
||||
|
||||
struct token {
|
||||
int v; /* value */
|
||||
char *s; /* string */
|
||||
};
|
||||
|
||||
extern int dflag; /* print filter code */
|
||||
extern int eflag; /* print ethernet header */
|
||||
extern int nflag; /* leave addresses as numbers */
|
||||
extern int Nflag; /* remove domains from printed host names */
|
||||
extern int qflag; /* quick (shorter) output */
|
||||
extern int Sflag; /* print raw TCP sequence numbers */
|
||||
extern int tflag; /* print packet arrival time */
|
||||
extern int vflag; /* verbose */
|
||||
extern int xflag; /* print packet in hex */
|
||||
|
||||
extern char *program_name; /* used to generate self-identifying messages */
|
||||
|
||||
extern int snaplen;
|
||||
/* global pointers to beginning and end of current packet (during printing) */
|
||||
extern const u_char *packetp;
|
||||
extern const u_char *snapend;
|
||||
|
||||
extern int fddipad; /* alignment offset for FDDI headers, in bytes */
|
||||
|
||||
/* Eliminate some bogus warnings. */
|
||||
struct timeval;
|
||||
|
||||
typedef void (*printfunc)(u_char *, struct timeval *, int, int);
|
||||
|
||||
extern void ts_print(const struct timeval *);
|
||||
extern int clock_sigfigs(void);
|
||||
int gmt2local(void);
|
||||
|
||||
extern int fn_print(const u_char *, const u_char *);
|
||||
extern int fn_printn(const u_char *, u_int, const u_char *);
|
||||
extern const char *tok2str(const struct token *, const char *, int);
|
||||
extern char *dnaddr_string(u_short);
|
||||
extern char *savestr(const char *);
|
||||
|
||||
extern int initdevice(char *, int, int *);
|
||||
extern void wrapup(int);
|
||||
|
||||
extern __dead void error(char *, ...);
|
||||
extern void warning(char *, ...);
|
||||
|
||||
extern char *read_infile(char *);
|
||||
extern char *copy_argv(char **);
|
||||
|
||||
extern void usage(void);
|
||||
extern char *isonsap_string(const u_char *);
|
||||
extern char *llcsap_string(u_char);
|
||||
extern char *protoid_string(const u_char *);
|
||||
extern char *dnname_string(u_short);
|
||||
extern char *dnnum_string(u_short);
|
||||
|
||||
/* The printer routines. */
|
||||
|
||||
struct pcap_pkthdr;
|
||||
|
||||
extern void ether_if_print(u_char *, const struct pcap_pkthdr *,
|
||||
const u_char *);
|
||||
extern void fddi_if_print(u_char *, const struct pcap_pkthdr *, const u_char*);
|
||||
extern void null_if_print(u_char *, const struct pcap_pkthdr *, const u_char*);
|
||||
extern void ppp_if_print(u_char *, const struct pcap_pkthdr *, const u_char *);
|
||||
extern void sl_if_print(u_char *, const struct pcap_pkthdr *, const u_char *);
|
||||
|
||||
extern void arp_print(const u_char *, int, int);
|
||||
extern void ip_print(const u_char *, int);
|
||||
extern void tcp_print(const u_char *, int, const u_char *);
|
||||
extern void udp_print(const u_char *, int, const u_char *);
|
||||
extern void icmp_print(const u_char *, const u_char *);
|
||||
extern void default_print(const u_char *, int);
|
||||
extern void default_print_unaligned(const u_char *, int);
|
||||
|
||||
extern void aarp_print(const u_char *, int);
|
||||
extern void atalk_print(const u_char *, int);
|
||||
extern void bootp_print(const u_char *, int, u_short, u_short);
|
||||
extern void decnet_print(const u_char *, int, int);
|
||||
extern void egp_print(const u_char *, int, const u_char *);
|
||||
extern int ether_encap_print(u_short, const u_char *, int, int);
|
||||
extern void ipx_print(const u_char *, int length);
|
||||
extern void isoclns_print(const u_char *, int, int,
|
||||
const u_char *, const u_char *);
|
||||
extern int llc_print(const u_char *, int, int, const u_char *, const u_char *);
|
||||
extern void nfsreply_print(const u_char *, int, const u_char *);
|
||||
extern void nfsreq_print(const u_char *, int, const u_char *);
|
||||
extern void ns_print(const u_char *, int);
|
||||
extern void ntp_print(const u_char *, int);
|
||||
extern void ospf_print(const u_char *, int, const u_char *);
|
||||
extern void rip_print(const u_char *, int);
|
||||
extern void snmp_print(const u_char *, int);
|
||||
extern void sunrpcrequest_print(const u_char *, int, const u_char *);
|
||||
extern void tftp_print(const u_char *, int);
|
||||
extern void wb_print(const void *, int);
|
||||
|
||||
#define min(a,b) ((a)>(b)?(b):(a))
|
||||
#define max(a,b) ((b)>(a)?(b):(a))
|
||||
|
||||
/*
|
||||
* The default snapshot length. This value allows most printers to print
|
||||
* useful information while keeping the amount of unwanted data down.
|
||||
* In particular, it allows for an ethernet header, tcp/ip header, and
|
||||
* 14 bytes of data (assuming no ip options).
|
||||
*/
|
||||
#define DEFAULT_SNAPLEN 68
|
||||
|
||||
#ifndef BIG_ENDIAN
|
||||
#define BIG_ENDIAN 4321
|
||||
#define LITTLE_ENDIAN 1234
|
||||
#endif
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* IPX protocol formats
|
||||
*
|
||||
* @(#) $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/ipx.h,v 1.1 1995/03/08 12:52:15 olah Exp $
|
||||
*/
|
||||
|
||||
/* well-known sockets */
|
||||
#define IPX_SKT_NCP 0x0451
|
||||
#define IPX_SKT_SAP 0x0452
|
||||
#define IPX_SKT_RIP 0x0453
|
||||
#define IPX_SKT_NETBIOS 0x0455
|
||||
#define IPX_SKT_DIAGNOSTICS 0x0456
|
||||
|
||||
/* IPX transport header */
|
||||
struct ipxHdr {
|
||||
u_short cksum; /* Checksum */
|
||||
u_short length; /* Length, in bytes, including header */
|
||||
u_char tCtl; /* Transport Control (i.e. hop count) */
|
||||
u_char pType; /* Packet Type (i.e. level 2 protocol) */
|
||||
u_short dstNet[2]; /* destination net */
|
||||
u_char dstNode[6]; /* destination node */
|
||||
u_short dstSkt; /* destination socket */
|
||||
u_short srcNet[2]; /* source net */
|
||||
u_char srcNode[6]; /* source node */
|
||||
u_short srcSkt; /* source socket */
|
||||
} ipx_hdr_t;
|
||||
|
||||
#define ipxSize 30
|
||||
|
@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* @(#) $Header: llc.h,v 1.4 94/06/14 20:11:46 leres Exp $ (LBL)
|
||||
*/
|
||||
|
||||
/*
|
||||
* This stuff should come from a system header file, but there's no
|
||||
* obviously portable way to do that and it's not really going
|
||||
* to change from system to system.
|
||||
*/
|
||||
|
||||
/*
|
||||
* A somewhat abstracted view of the LLC header
|
||||
*/
|
||||
|
||||
struct llc {
|
||||
u_char dsap;
|
||||
u_char ssap;
|
||||
union {
|
||||
u_char u_ctl;
|
||||
u_short is_ctl;
|
||||
struct {
|
||||
u_char snap_ui;
|
||||
u_char snap_pi[5];
|
||||
} snap;
|
||||
struct {
|
||||
u_char snap_ui;
|
||||
u_char snap_orgcode[3];
|
||||
u_char snap_ethertype[2];
|
||||
} snap_ether;
|
||||
} ctl;
|
||||
};
|
||||
|
||||
#define llcui ctl.snap.snap_ui
|
||||
#define llcpi ctl.snap.snap_pi
|
||||
#define orgcode ctl.snap_ether.snap_orgcode
|
||||
#define ethertype ctl.snap_ether.snap_ethertype
|
||||
#define llcis ctl.is_ctl
|
||||
#define llcu ctl.u_ctl
|
||||
|
||||
#define LLC_U_FMT 3
|
||||
#define LLC_GSAP 1
|
||||
#define LLC_S_FMT 1
|
||||
|
||||
#define LLC_U_POLL 0x10
|
||||
#define LLC_IS_POLL 0x0001
|
||||
#define LLC_XID_FI 0x81
|
||||
|
||||
#define LLC_U_CMD(u) ((u) & 0xef)
|
||||
#define LLC_UI 0x03
|
||||
#define LLC_UA 0x63
|
||||
#define LLC_DISC 0x43
|
||||
#define LLC_DM 0x0f
|
||||
#define LLC_SABME 0x6f
|
||||
#define LLC_TEST 0xe3
|
||||
#define LLC_XID 0xaf
|
||||
#define LLC_FRMR 0x87
|
||||
|
||||
#define LLC_S_CMD(is) (((is) >> 10) & 0x03)
|
||||
#define LLC_RR 0x0100
|
||||
#define LLC_RNR 0x0500
|
||||
#define LLC_REJ 0x0900
|
||||
|
||||
#define LLC_IS_NR(is) (((is) >> 9) & 0x7f)
|
||||
#define LLC_I_NS(is) (((is) >> 1) & 0x7f)
|
||||
|
||||
#ifndef LLCSAP_NULL
|
||||
#define LLCSAP_NULL 0x00
|
||||
#endif
|
||||
#ifndef LLCSAP_GLOBAL
|
||||
#define LLCSAP_GLOBAL 0xff
|
||||
#endif
|
||||
#ifndef LLCSAP_8021B
|
||||
#define LLCSAP_8021B_I 0x02
|
||||
#endif
|
||||
#ifndef LLCSAP_8021B
|
||||
#define LLCSAP_8021B_G 0x03
|
||||
#endif
|
||||
#ifndef LLCSAP_IP
|
||||
#define LLCSAP_IP 0x06
|
||||
#endif
|
||||
#ifndef LLCSAP_PROWAYNM
|
||||
#define LLCSAP_PROWAYNM 0x0e
|
||||
#endif
|
||||
#ifndef LLCSAP_8021D
|
||||
#define LLCSAP_8021D 0x42
|
||||
#endif
|
||||
#ifndef LLCSAP_RS511
|
||||
#define LLCSAP_RS511 0x4e
|
||||
#endif
|
||||
#ifndef LLCSAP_ISO8208
|
||||
#define LLCSAP_ISO8208 0x7e
|
||||
#endif
|
||||
#ifndef LLCSAP_PROWAY
|
||||
#define LLCSAP_PROWAY 0x8e
|
||||
#endif
|
||||
#ifndef LLCSAP_SNAP
|
||||
#define LLCSAP_SNAP 0xaa
|
||||
#endif
|
||||
#ifndef LLCSAP_ISONS
|
||||
#define LLCSAP_ISONS 0xfe
|
||||
#endif
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* @(#) $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/md.h,v 1.2 1995/03/08 12:52:17 olah Exp $ (LBL)
|
||||
*/
|
||||
|
||||
#define TCPDUMP_ALIGN
|
||||
|
||||
#include <machine/endian.h>
|
||||
|
||||
/* 32-bit data types */
|
||||
/* N.B.: this doesn't address printf()'s %d vs. %ld formats */
|
||||
typedef int32_t int32; /* signed 32-bit integer */
|
||||
typedef u_int32_t u_int32; /* unsigned 32-bit integer */
|
File diff suppressed because it is too large
Load Diff
@ -1,446 +0,0 @@
|
||||
/* $NetBSD: nfs.h,v 1.1 1996/05/23 22:49:53 fvdl Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Rick Macklem at The University of Guelph.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. 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 BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)nfsproto.h 8.2 (Berkeley) 3/30/95
|
||||
*/
|
||||
|
||||
/*
|
||||
* nfs definitions as per the Version 2 and 3 specs
|
||||
*/
|
||||
|
||||
/*
|
||||
* Constants as defined in the Sun NFS Version 2 and 3 specs.
|
||||
* "NFS: Network File System Protocol Specification" RFC1094
|
||||
* and in the "NFS: Network File System Version 3 Protocol
|
||||
* Specification"
|
||||
*/
|
||||
|
||||
#define NFS_PORT 2049
|
||||
#define NFS_PROG 100003
|
||||
#define NFS_VER2 2
|
||||
#define NFS_VER3 3
|
||||
#define NFS_V2MAXDATA 8192
|
||||
#define NFS_MAXDGRAMDATA 16384
|
||||
#define NFS_MAXDATA 32768
|
||||
#define NFS_MAXPATHLEN 1024
|
||||
#define NFS_MAXNAMLEN 255
|
||||
#define NFS_MAXPKTHDR 404
|
||||
#define NFS_MAXPACKET (NFS_MAXPKTHDR + NFS_MAXDATA)
|
||||
#define NFS_MINPACKET 20
|
||||
#define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */
|
||||
|
||||
/* Stat numbers for rpc returns (version 2 and 3) */
|
||||
#define NFS_OK 0
|
||||
#define NFSERR_PERM 1
|
||||
#define NFSERR_NOENT 2
|
||||
#define NFSERR_IO 5
|
||||
#define NFSERR_NXIO 6
|
||||
#define NFSERR_ACCES 13
|
||||
#define NFSERR_EXIST 17
|
||||
#define NFSERR_XDEV 18 /* Version 3 only */
|
||||
#define NFSERR_NODEV 19
|
||||
#define NFSERR_NOTDIR 20
|
||||
#define NFSERR_ISDIR 21
|
||||
#define NFSERR_INVAL 22 /* Version 3 only */
|
||||
#define NFSERR_FBIG 27
|
||||
#define NFSERR_NOSPC 28
|
||||
#define NFSERR_ROFS 30
|
||||
#define NFSERR_MLINK 31 /* Version 3 only */
|
||||
#define NFSERR_NAMETOL 63
|
||||
#define NFSERR_NOTEMPTY 66
|
||||
#define NFSERR_DQUOT 69
|
||||
#define NFSERR_STALE 70
|
||||
#define NFSERR_REMOTE 71 /* Version 3 only */
|
||||
#define NFSERR_WFLUSH 99 /* Version 2 only */
|
||||
#define NFSERR_BADHANDLE 10001 /* The rest Version 3 only */
|
||||
#define NFSERR_NOT_SYNC 10002
|
||||
#define NFSERR_BAD_COOKIE 10003
|
||||
#define NFSERR_NOTSUPP 10004
|
||||
#define NFSERR_TOOSMALL 10005
|
||||
#define NFSERR_SERVERFAULT 10006
|
||||
#define NFSERR_BADTYPE 10007
|
||||
#define NFSERR_JUKEBOX 10008
|
||||
#define NFSERR_TRYLATER NFSERR_JUKEBOX
|
||||
#define NFSERR_STALEWRITEVERF 30001 /* Fake return for nfs_commit() */
|
||||
|
||||
#define NFSERR_RETVOID 0x20000000 /* Return void, not error */
|
||||
#define NFSERR_AUTHERR 0x40000000 /* Mark an authentication error */
|
||||
#define NFSERR_RETERR 0x80000000 /* Mark an error return for V3 */
|
||||
|
||||
/* Sizes in bytes of various nfs rpc components */
|
||||
#define NFSX_UNSIGNED 4
|
||||
|
||||
/* specific to NFS Version 2 */
|
||||
#define NFSX_V2FH 32
|
||||
#define NFSX_V2FATTR 68
|
||||
#define NFSX_V2SATTR 32
|
||||
#define NFSX_V2COOKIE 4
|
||||
#define NFSX_V2STATFS 20
|
||||
|
||||
/* specific to NFS Version 3 */
|
||||
#if 0
|
||||
#define NFSX_V3FH (sizeof (fhandle_t)) /* size this server uses */
|
||||
#endif
|
||||
#define NFSX_V3FHMAX 64 /* max. allowed by protocol */
|
||||
#define NFSX_V3FATTR 84
|
||||
#define NFSX_V3SATTR 60 /* max. all fields filled in */
|
||||
#define NFSX_V3SRVSATTR (sizeof (struct nfsv3_sattr))
|
||||
#define NFSX_V3POSTOPATTR (NFSX_V3FATTR + NFSX_UNSIGNED)
|
||||
#define NFSX_V3WCCDATA (NFSX_V3POSTOPATTR + 8 * NFSX_UNSIGNED)
|
||||
#define NFSX_V3COOKIEVERF 8
|
||||
#define NFSX_V3WRITEVERF 8
|
||||
#define NFSX_V3CREATEVERF 8
|
||||
#define NFSX_V3STATFS 52
|
||||
#define NFSX_V3FSINFO 48
|
||||
#define NFSX_V3PATHCONF 24
|
||||
|
||||
/* variants for both versions */
|
||||
#define NFSX_FH(v3) ((v3) ? (NFSX_V3FHMAX + NFSX_UNSIGNED) : \
|
||||
NFSX_V2FH)
|
||||
#define NFSX_SRVFH(v3) ((v3) ? NFSX_V3FH : NFSX_V2FH)
|
||||
#define NFSX_FATTR(v3) ((v3) ? NFSX_V3FATTR : NFSX_V2FATTR)
|
||||
#define NFSX_PREOPATTR(v3) ((v3) ? (7 * NFSX_UNSIGNED) : 0)
|
||||
#define NFSX_POSTOPATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : 0)
|
||||
#define NFSX_POSTOPORFATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : \
|
||||
NFSX_V2FATTR)
|
||||
#define NFSX_WCCDATA(v3) ((v3) ? NFSX_V3WCCDATA : 0)
|
||||
#define NFSX_WCCORFATTR(v3) ((v3) ? NFSX_V3WCCDATA : NFSX_V2FATTR)
|
||||
#define NFSX_SATTR(v3) ((v3) ? NFSX_V3SATTR : NFSX_V2SATTR)
|
||||
#define NFSX_COOKIEVERF(v3) ((v3) ? NFSX_V3COOKIEVERF : 0)
|
||||
#define NFSX_WRITEVERF(v3) ((v3) ? NFSX_V3WRITEVERF : 0)
|
||||
#define NFSX_READDIR(v3) ((v3) ? (5 * NFSX_UNSIGNED) : \
|
||||
(2 * NFSX_UNSIGNED))
|
||||
#define NFSX_STATFS(v3) ((v3) ? NFSX_V3STATFS : NFSX_V2STATFS)
|
||||
|
||||
/* nfs rpc procedure numbers (before version mapping) */
|
||||
#define NFSPROC_NULL 0
|
||||
#define NFSPROC_GETATTR 1
|
||||
#define NFSPROC_SETATTR 2
|
||||
#define NFSPROC_LOOKUP 3
|
||||
#define NFSPROC_ACCESS 4
|
||||
#define NFSPROC_READLINK 5
|
||||
#define NFSPROC_READ 6
|
||||
#define NFSPROC_WRITE 7
|
||||
#define NFSPROC_CREATE 8
|
||||
#define NFSPROC_MKDIR 9
|
||||
#define NFSPROC_SYMLINK 10
|
||||
#define NFSPROC_MKNOD 11
|
||||
#define NFSPROC_REMOVE 12
|
||||
#define NFSPROC_RMDIR 13
|
||||
#define NFSPROC_RENAME 14
|
||||
#define NFSPROC_LINK 15
|
||||
#define NFSPROC_READDIR 16
|
||||
#define NFSPROC_READDIRPLUS 17
|
||||
#define NFSPROC_FSSTAT 18
|
||||
#define NFSPROC_FSINFO 19
|
||||
#define NFSPROC_PATHCONF 20
|
||||
#define NFSPROC_COMMIT 21
|
||||
|
||||
/* And leasing (nqnfs) procedure numbers (must be last) */
|
||||
#define NQNFSPROC_GETLEASE 22
|
||||
#define NQNFSPROC_VACATED 23
|
||||
#define NQNFSPROC_EVICTED 24
|
||||
|
||||
#define NFSPROC_NOOP 25
|
||||
#define NFS_NPROCS 26
|
||||
|
||||
/* Actual Version 2 procedure numbers */
|
||||
#define NFSV2PROC_NULL 0
|
||||
#define NFSV2PROC_GETATTR 1
|
||||
#define NFSV2PROC_SETATTR 2
|
||||
#define NFSV2PROC_NOOP 3
|
||||
#define NFSV2PROC_ROOT NFSV2PROC_NOOP /* Obsolete */
|
||||
#define NFSV2PROC_LOOKUP 4
|
||||
#define NFSV2PROC_READLINK 5
|
||||
#define NFSV2PROC_READ 6
|
||||
#define NFSV2PROC_WRITECACHE NFSV2PROC_NOOP /* Obsolete */
|
||||
#define NFSV2PROC_WRITE 8
|
||||
#define NFSV2PROC_CREATE 9
|
||||
#define NFSV2PROC_REMOVE 10
|
||||
#define NFSV2PROC_RENAME 11
|
||||
#define NFSV2PROC_LINK 12
|
||||
#define NFSV2PROC_SYMLINK 13
|
||||
#define NFSV2PROC_MKDIR 14
|
||||
#define NFSV2PROC_RMDIR 15
|
||||
#define NFSV2PROC_READDIR 16
|
||||
#define NFSV2PROC_STATFS 17
|
||||
|
||||
/*
|
||||
* Constants used by the Version 3 protocol for various RPCs
|
||||
*/
|
||||
#define NFSV3SATTRTIME_DONTCHANGE 0
|
||||
#define NFSV3SATTRTIME_TOSERVER 1
|
||||
#define NFSV3SATTRTIME_TOCLIENT 2
|
||||
|
||||
#define NFSV3ATTRTIME_NMODES 3
|
||||
|
||||
#define NFSV3ACCESS_READ 0x01
|
||||
#define NFSV3ACCESS_LOOKUP 0x02
|
||||
#define NFSV3ACCESS_MODIFY 0x04
|
||||
#define NFSV3ACCESS_EXTEND 0x08
|
||||
#define NFSV3ACCESS_DELETE 0x10
|
||||
#define NFSV3ACCESS_EXECUTE 0x20
|
||||
|
||||
#define NFSV3WRITE_UNSTABLE 0
|
||||
#define NFSV3WRITE_DATASYNC 1
|
||||
#define NFSV3WRITE_FILESYNC 2
|
||||
|
||||
#define NFSV3WRITE_NMODES 3
|
||||
|
||||
#define NFSV3CREATE_UNCHECKED 0
|
||||
#define NFSV3CREATE_GUARDED 1
|
||||
#define NFSV3CREATE_EXCLUSIVE 2
|
||||
|
||||
#define NFSV3CREATE_NMODES 3
|
||||
|
||||
#define NFSV3FSINFO_LINK 0x01
|
||||
#define NFSV3FSINFO_SYMLINK 0x02
|
||||
#define NFSV3FSINFO_HOMOGENEOUS 0x08
|
||||
#define NFSV3FSINFO_CANSETTIME 0x10
|
||||
|
||||
/* Conversion macros */
|
||||
#define vtonfsv2_mode(t,m) \
|
||||
txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : \
|
||||
MAKEIMODE((t), (m)))
|
||||
#define vtonfsv3_mode(m) txdr_unsigned((m) & 07777)
|
||||
#define nfstov_mode(a) (fxdr_unsigned(u_int16_t, (a))&07777)
|
||||
#define vtonfsv2_type(a) txdr_unsigned(nfsv2_type[((int32_t)(a))])
|
||||
#define vtonfsv3_type(a) txdr_unsigned(nfsv3_type[((int32_t)(a))])
|
||||
#define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(u_int32,(a))&0x7]
|
||||
#define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(u_int32,(a))&0x7]
|
||||
|
||||
/* File types */
|
||||
typedef enum { NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5,
|
||||
NFSOCK=6, NFFIFO=7 } nfstype;
|
||||
|
||||
/* Structs for common parts of the rpc's */
|
||||
/*
|
||||
* File Handle (32 bytes for version 2), variable up to 64 for version 3.
|
||||
* File Handles of up to NFS_SMALLFH in size are stored directly in the
|
||||
* nfs node, whereas larger ones are malloc'd. (This never happens when
|
||||
* NFS_SMALLFH is set to 64.)
|
||||
* NFS_SMALLFH should be in the range of 32 to 64 and be divisible by 4.
|
||||
*/
|
||||
#ifndef NFS_SMALLFH
|
||||
#define NFS_SMALLFH 64
|
||||
#endif
|
||||
union nfsfh {
|
||||
/* fhandle_t fh_generic; */
|
||||
u_char fh_bytes[NFS_SMALLFH];
|
||||
};
|
||||
typedef union nfsfh nfsfh_t;
|
||||
|
||||
struct nfsv2_time {
|
||||
u_int32 nfsv2_sec;
|
||||
u_int32 nfsv2_usec;
|
||||
};
|
||||
typedef struct nfsv2_time nfstime2;
|
||||
|
||||
struct nfsv3_time {
|
||||
u_int32 nfsv3_sec;
|
||||
u_int32 nfsv3_nsec;
|
||||
};
|
||||
typedef struct nfsv3_time nfstime3;
|
||||
|
||||
/*
|
||||
* Quads are defined as arrays of 2 longs to ensure dense packing for the
|
||||
* protocol and to facilitate xdr conversion.
|
||||
*/
|
||||
struct nfs_uquad {
|
||||
u_int32 nfsuquad[2];
|
||||
};
|
||||
typedef struct nfs_uquad nfsuint64;
|
||||
|
||||
/*
|
||||
* Used to convert between two u_longs and a u_quad_t.
|
||||
*/
|
||||
union nfs_quadconvert {
|
||||
u_int32 lval[2];
|
||||
u_quad_t qval;
|
||||
};
|
||||
typedef union nfs_quadconvert nfsquad_t;
|
||||
|
||||
/*
|
||||
* NFS Version 3 special file number.
|
||||
*/
|
||||
struct nfsv3_spec {
|
||||
u_int32 specdata1;
|
||||
u_int32 specdata2;
|
||||
};
|
||||
typedef struct nfsv3_spec nfsv3spec;
|
||||
|
||||
/*
|
||||
* File attributes and setable attributes. These structures cover both
|
||||
* NFS version 2 and the version 3 protocol. Note that the union is only
|
||||
* used so that one pointer can refer to both variants. These structures
|
||||
* go out on the wire and must be densely packed, so no quad data types
|
||||
* are used. (all fields are longs or u_longs or structures of same)
|
||||
* NB: You can't do sizeof(struct nfs_fattr), you must use the
|
||||
* NFSX_FATTR(v3) macro.
|
||||
*/
|
||||
struct nfs_fattr {
|
||||
u_int32 fa_type;
|
||||
u_int32 fa_mode;
|
||||
u_int32 fa_nlink;
|
||||
u_int32 fa_uid;
|
||||
u_int32 fa_gid;
|
||||
union {
|
||||
struct {
|
||||
u_int32 nfsv2fa_size;
|
||||
u_int32 nfsv2fa_blocksize;
|
||||
u_int32 nfsv2fa_rdev;
|
||||
u_int32 nfsv2fa_blocks;
|
||||
u_int32 nfsv2fa_fsid;
|
||||
u_int32 nfsv2fa_fileid;
|
||||
nfstime2 nfsv2fa_atime;
|
||||
nfstime2 nfsv2fa_mtime;
|
||||
nfstime2 nfsv2fa_ctime;
|
||||
} fa_nfsv2;
|
||||
struct {
|
||||
nfsuint64 nfsv3fa_size;
|
||||
nfsuint64 nfsv3fa_used;
|
||||
nfsv3spec nfsv3fa_rdev;
|
||||
nfsuint64 nfsv3fa_fsid;
|
||||
nfsuint64 nfsv3fa_fileid;
|
||||
nfstime3 nfsv3fa_atime;
|
||||
nfstime3 nfsv3fa_mtime;
|
||||
nfstime3 nfsv3fa_ctime;
|
||||
} fa_nfsv3;
|
||||
} fa_un;
|
||||
};
|
||||
|
||||
/* and some ugly defines for accessing union components */
|
||||
#define fa2_size fa_un.fa_nfsv2.nfsv2fa_size
|
||||
#define fa2_blocksize fa_un.fa_nfsv2.nfsv2fa_blocksize
|
||||
#define fa2_rdev fa_un.fa_nfsv2.nfsv2fa_rdev
|
||||
#define fa2_blocks fa_un.fa_nfsv2.nfsv2fa_blocks
|
||||
#define fa2_fsid fa_un.fa_nfsv2.nfsv2fa_fsid
|
||||
#define fa2_fileid fa_un.fa_nfsv2.nfsv2fa_fileid
|
||||
#define fa2_atime fa_un.fa_nfsv2.nfsv2fa_atime
|
||||
#define fa2_mtime fa_un.fa_nfsv2.nfsv2fa_mtime
|
||||
#define fa2_ctime fa_un.fa_nfsv2.nfsv2fa_ctime
|
||||
#define fa3_size fa_un.fa_nfsv3.nfsv3fa_size
|
||||
#define fa3_used fa_un.fa_nfsv3.nfsv3fa_used
|
||||
#define fa3_rdev fa_un.fa_nfsv3.nfsv3fa_rdev
|
||||
#define fa3_fsid fa_un.fa_nfsv3.nfsv3fa_fsid
|
||||
#define fa3_fileid fa_un.fa_nfsv3.nfsv3fa_fileid
|
||||
#define fa3_atime fa_un.fa_nfsv3.nfsv3fa_atime
|
||||
#define fa3_mtime fa_un.fa_nfsv3.nfsv3fa_mtime
|
||||
#define fa3_ctime fa_un.fa_nfsv3.nfsv3fa_ctime
|
||||
|
||||
struct nfsv2_sattr {
|
||||
u_int32 sa_mode;
|
||||
u_int32 sa_uid;
|
||||
u_int32 sa_gid;
|
||||
u_int32 sa_size;
|
||||
nfstime2 sa_atime;
|
||||
nfstime2 sa_mtime;
|
||||
};
|
||||
|
||||
/*
|
||||
* NFS Version 3 sattr structure for the new node creation case.
|
||||
*/
|
||||
struct nfsv3_sattr {
|
||||
u_int32 sa_modeset;
|
||||
u_int32 sa_mode;
|
||||
u_int32 sa_uidset;
|
||||
u_int32 sa_uid;
|
||||
u_int32 sa_gidset;
|
||||
u_int32 sa_gid;
|
||||
u_int32 sa_sizeset;
|
||||
u_int32 sa_size;
|
||||
u_int32 sa_atimetype;
|
||||
nfstime3 sa_atime;
|
||||
u_int32 sa_mtimetype;
|
||||
nfstime3 sa_mtime;
|
||||
};
|
||||
|
||||
struct nfs_statfs {
|
||||
union {
|
||||
struct {
|
||||
u_int32 nfsv2sf_tsize;
|
||||
u_int32 nfsv2sf_bsize;
|
||||
u_int32 nfsv2sf_blocks;
|
||||
u_int32 nfsv2sf_bfree;
|
||||
u_int32 nfsv2sf_bavail;
|
||||
} sf_nfsv2;
|
||||
struct {
|
||||
nfsuint64 nfsv3sf_tbytes;
|
||||
nfsuint64 nfsv3sf_fbytes;
|
||||
nfsuint64 nfsv3sf_abytes;
|
||||
nfsuint64 nfsv3sf_tfiles;
|
||||
nfsuint64 nfsv3sf_ffiles;
|
||||
nfsuint64 nfsv3sf_afiles;
|
||||
u_int32 nfsv3sf_invarsec;
|
||||
} sf_nfsv3;
|
||||
} sf_un;
|
||||
};
|
||||
|
||||
#define sf_tsize sf_un.sf_nfsv2.nfsv2sf_tsize
|
||||
#define sf_bsize sf_un.sf_nfsv2.nfsv2sf_bsize
|
||||
#define sf_blocks sf_un.sf_nfsv2.nfsv2sf_blocks
|
||||
#define sf_bfree sf_un.sf_nfsv2.nfsv2sf_bfree
|
||||
#define sf_bavail sf_un.sf_nfsv2.nfsv2sf_bavail
|
||||
#define sf_tbytes sf_un.sf_nfsv3.nfsv3sf_tbytes
|
||||
#define sf_fbytes sf_un.sf_nfsv3.nfsv3sf_fbytes
|
||||
#define sf_abytes sf_un.sf_nfsv3.nfsv3sf_abytes
|
||||
#define sf_tfiles sf_un.sf_nfsv3.nfsv3sf_tfiles
|
||||
#define sf_ffiles sf_un.sf_nfsv3.nfsv3sf_ffiles
|
||||
#define sf_afiles sf_un.sf_nfsv3.nfsv3sf_afiles
|
||||
#define sf_invarsec sf_un.sf_nfsv3.nfsv3sf_invarsec
|
||||
|
||||
struct nfsv3_fsinfo {
|
||||
u_int32 fs_rtmax;
|
||||
u_int32 fs_rtpref;
|
||||
u_int32 fs_rtmult;
|
||||
u_int32 fs_wtmax;
|
||||
u_int32 fs_wtpref;
|
||||
u_int32 fs_wtmult;
|
||||
u_int32 fs_dtpref;
|
||||
nfsuint64 fs_maxfilesize;
|
||||
nfstime3 fs_timedelta;
|
||||
u_int32 fs_properties;
|
||||
};
|
||||
|
||||
struct nfsv3_pathconf {
|
||||
u_int32 pc_linkmax;
|
||||
u_int32 pc_namemax;
|
||||
u_int32 pc_notrunc;
|
||||
u_int32 pc_chownrestricted;
|
||||
u_int32 pc_caseinsensitive;
|
||||
u_int32 pc_casepreserving;
|
||||
};
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/nfsfh.h,v 1.1 1995/03/08 12:52:19 olah Exp $
|
||||
*
|
||||
* nfsfh.h - NFS file handle definitions (for portable use)
|
||||
*
|
||||
* Jeffrey C. Mogul
|
||||
* Digital Equipment Corporation
|
||||
* Western Research Laboratory
|
||||
*/
|
||||
|
||||
/*
|
||||
* Internal representation of dev_t, because different NFS servers
|
||||
* that we might be spying upon use different external representations.
|
||||
*/
|
||||
typedef struct {
|
||||
u_long Minor; /* upper case to avoid clashing with macro names */
|
||||
u_long Major;
|
||||
} my_devt;
|
||||
|
||||
#define dev_eq(a,b) ((a.Minor == b.Minor) && (a.Major == b.Major))
|
||||
|
||||
/*
|
||||
* Many file servers now use a large file system ID. This is
|
||||
* our internal representation of that.
|
||||
*/
|
||||
typedef struct {
|
||||
my_devt fsid_dev;
|
||||
u_long fsid_code;
|
||||
} my_fsid;
|
||||
|
||||
#define fsid_eq(a,b) ((a.fsid_code == b.fsid_code) &&\
|
||||
dev_eq(a.fsid_dev, b.fsid_dev))
|
||||
|
||||
extern void Parse_fh(caddr_t *, int, my_fsid *, ino_t *, char **, char **, int);
|
@ -1,117 +0,0 @@
|
||||
/* $Header: ntp.h,v 1.2 93/11/12 21:43:36 mccanne Exp $ */
|
||||
|
||||
/*
|
||||
* Based on ntp.h from the U of MD implementation
|
||||
* This file is based on Version 2 of the NTP spec (RFC1119).
|
||||
*/
|
||||
|
||||
/*
|
||||
* Definitions for the masses
|
||||
*/
|
||||
#define JAN_1970 2208988800 /* 1970 - 1900 in seconds */
|
||||
|
||||
/*
|
||||
* Structure definitions for NTP fixed point values
|
||||
*
|
||||
* 0 1 2 3
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Integer Part |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Fraction Part |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*
|
||||
* 0 1 2 3
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Integer Part | Fraction Part |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
struct l_fixedpt {
|
||||
u_int32 int_part;
|
||||
u_int32 fraction;
|
||||
};
|
||||
|
||||
struct s_fixedpt {
|
||||
u_short int_part;
|
||||
u_short fraction;
|
||||
};
|
||||
|
||||
/* ================= Table 3.3. Packet Variables ================= */
|
||||
/*
|
||||
* 0 1 2 3
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* |LI | VN | Mode| Stratum | Poll | Precision |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Synchronizing Distance |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Synchronizing Dispersion |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Reference Clock Identifier |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | |
|
||||
* | Reference Timestamp (64 bits) |
|
||||
* | |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | |
|
||||
* | Originate Timestamp (64 bits) |
|
||||
* | |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | |
|
||||
* | Receive Timestamp (64 bits) |
|
||||
* | |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | |
|
||||
* | Transmit Timestamp (64 bits) |
|
||||
* | |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
struct ntpdata {
|
||||
u_char status; /* status of local clock and leap info */
|
||||
u_char stratum; /* Stratum level */
|
||||
u_char ppoll; /* poll value */
|
||||
int precision:8;
|
||||
struct s_fixedpt distance;
|
||||
struct s_fixedpt dispersion;
|
||||
u_int32 refid;
|
||||
struct l_fixedpt reftime;
|
||||
struct l_fixedpt org;
|
||||
struct l_fixedpt rec;
|
||||
struct l_fixedpt xmt;
|
||||
};
|
||||
/*
|
||||
* Leap Second Codes (high order two bits)
|
||||
*/
|
||||
#define NO_WARNING 0x00 /* no warning */
|
||||
#define PLUS_SEC 0x40 /* add a second (61 seconds) */
|
||||
#define MINUS_SEC 0x80 /* minus a second (59 seconds) */
|
||||
#define ALARM 0xc0 /* alarm condition (clock unsynchronized) */
|
||||
|
||||
/*
|
||||
* Clock Status Bits that Encode Version
|
||||
*/
|
||||
#define NTPVERSION_1 0x08
|
||||
#define VERSIONMASK 0x38
|
||||
#define LEAPMASK 0xc0
|
||||
#define MODEMASK 0x07
|
||||
|
||||
/*
|
||||
* Code values
|
||||
*/
|
||||
#define MODE_UNSPEC 0 /* unspecified */
|
||||
#define MODE_SYM_ACT 1 /* symmetric active */
|
||||
#define MODE_SYM_PAS 2 /* symmetric passive */
|
||||
#define MODE_CLIENT 3 /* client */
|
||||
#define MODE_SERVER 4 /* server */
|
||||
#define MODE_BROADCAST 5 /* broadcast */
|
||||
#define MODE_RES1 6 /* reserved */
|
||||
#define MODE_RES2 7 /* reserved */
|
||||
|
||||
/*
|
||||
* Stratum Definitions
|
||||
*/
|
||||
#define UNSPECIFIED 0
|
||||
#define PRIM_REF 1 /* radio clock */
|
||||
#define INFO_QUERY 62 /* **** THIS implementation dependent **** */
|
||||
#define INFO_REPLY 63 /* **** THIS implementation dependent **** */
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* @(#) $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/os.h,v 1.2 1995/03/08 12:52:21 olah Exp $ (LBL)
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#ifndef BSD
|
||||
#define BSD
|
||||
#endif
|
||||
|
||||
#define SHA(ap) ((ap)->arp_sha)
|
||||
#define SPA(ap) ((ap)->arp_spa)
|
||||
#define THA(ap) ((ap)->arp_tha)
|
||||
#define TPA(ap) ((ap)->arp_tpa)
|
||||
|
||||
#define EDST(ep) ((ep)->ether_dhost)
|
||||
#define ESRC(ep) ((ep)->ether_shost)
|
||||
|
||||
#ifndef ETHERTYPE_REVARP
|
||||
#define ETHERTYPE_REVARP 0x8035
|
||||
#endif
|
||||
|
||||
#ifndef IPPROTO_ND
|
||||
/* From <netinet/in.h> on a Sun somewhere. */
|
||||
#define IPPROTO_ND 77
|
||||
#endif
|
||||
|
||||
#ifndef REVARP_REQUEST
|
||||
#define REVARP_REQUEST 3
|
||||
#endif
|
||||
#ifndef REVARP_REPLY
|
||||
#define REVARP_REPLY 4
|
||||
#endif
|
||||
|
||||
/* newish RIP commands */
|
||||
#ifndef RIPCMD_POLL
|
||||
#define RIPCMD_POLL 5
|
||||
#endif
|
||||
#ifndef RIPCMD_POLLENTRY
|
||||
#define RIPCMD_POLLENTRY 6
|
||||
#endif
|
||||
|
||||
typedef int64_t int64;
|
||||
typedef u_int64_t u_int64;
|
||||
|
||||
#define INT64_FORMAT "%qd"
|
||||
#define U_INT64_FORMAT "%qu"
|
||||
#define HEX_INT64_FORMAT "%qx"
|
@ -1,223 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
|
||||
*/
|
||||
#define OSPF_TYPE_UMD 0 /* UMd's special monitoring packets */
|
||||
#define OSPF_TYPE_HELLO 1 /* Hello */
|
||||
#define OSPF_TYPE_DB 2 /* Database Description */
|
||||
#define OSPF_TYPE_LSR 3 /* Link State Request */
|
||||
#define OSPF_TYPE_LSU 4 /* Link State Update */
|
||||
#define OSPF_TYPE_LSA 5 /* Link State Ack */
|
||||
#define OSPF_TYPE_MAX 6
|
||||
|
||||
/* Options *_options */
|
||||
#define OSPF_OPTION_T 0x01 /* T bit: TOS support */
|
||||
#define OSPF_OPTION_E 0x02 /* E bit: External routes advertised */
|
||||
#define OSPF_OPTION_MC 0x04 /* MC bit: Multicast capable */
|
||||
|
||||
/* ospf_authtype */
|
||||
#define OSPF_AUTH_NONE 0 /* No auth-data */
|
||||
#define OSPF_AUTH_SIMPLE 1 /* Simple password */
|
||||
|
||||
/* db_flags */
|
||||
#define OSPF_DB_INIT 0x04 /* */
|
||||
#define OSPF_DB_MORE 0x02
|
||||
#define OSPF_DB_MASTER 0x01
|
||||
|
||||
/* ls_type */
|
||||
#define LS_TYPE_ROUTER 1 /* router link */
|
||||
#define LS_TYPE_NETWORK 2 /* network link */
|
||||
#define LS_TYPE_SUM_IP 3 /* summary link */
|
||||
#define LS_TYPE_SUM_ABR 4 /* summary area link */
|
||||
#define LS_TYPE_ASE 5 /* ASE */
|
||||
#define LS_TYPE_GROUP 6 /* Group membership (multicast */
|
||||
/* extensions 23 July 1991) */
|
||||
#define LS_TYPE_MAX 7
|
||||
|
||||
/*************************************************
|
||||
*
|
||||
* is the above a bug in the documentation?
|
||||
*
|
||||
*************************************************/
|
||||
|
||||
|
||||
/* rla_link.link_type */
|
||||
#define RLA_TYPE_ROUTER 1 /* point-to-point to another router */
|
||||
#define RLA_TYPE_TRANSIT 2 /* connection to transit network */
|
||||
#define RLA_TYPE_STUB 3 /* connection to stub network */
|
||||
#define RLA_TYPE_VIRTUAL 4 /* virtual link */
|
||||
|
||||
/* rla_flags */
|
||||
#define RLA_FLAG_B 0x01
|
||||
#define RLA_FLAG_E 0x02
|
||||
#define RLA_FLAG_W1 0x04
|
||||
#define RLA_FLAG_W2 0x08
|
||||
|
||||
/* sla_tosmetric breakdown */
|
||||
#define SLA_MASK_TOS 0x7f000000
|
||||
#define SLA_MASK_METRIC 0x00ffffff
|
||||
#define SLA_SHIFT_TOS 24
|
||||
|
||||
/* asla_tosmetric breakdown */
|
||||
#define ASLA_FLAG_EXTERNAL 0x80000000
|
||||
#define ASLA_MASK_TOS 0x7f000000
|
||||
#define ASLA_SHIFT_TOS 24
|
||||
#define ASLA_MASK_METRIC 0x00ffffff
|
||||
|
||||
/* multicast vertex type */
|
||||
#define MCLA_VERTEX_ROUTER 1
|
||||
#define MCLA_VERTEX_NETWORK 2
|
||||
|
||||
/* link state advertisement header */
|
||||
struct lsa_hdr {
|
||||
u_short ls_age;
|
||||
u_char ls_options;
|
||||
u_char ls_type;
|
||||
struct in_addr ls_stateid;
|
||||
struct in_addr ls_router;
|
||||
u_int32 ls_seq;
|
||||
u_short ls_chksum;
|
||||
u_short ls_length;
|
||||
} ;
|
||||
|
||||
/* link state advertisement */
|
||||
struct lsa {
|
||||
struct lsa_hdr ls_hdr;
|
||||
|
||||
/* Link state types */
|
||||
union {
|
||||
/* Router links advertisements */
|
||||
struct {
|
||||
u_char rla_flags;
|
||||
u_char rla_zero[1];
|
||||
u_short rla_count;
|
||||
struct rlalink {
|
||||
struct in_addr link_id;
|
||||
struct in_addr link_data;
|
||||
u_char link_type;
|
||||
u_char link_toscount;
|
||||
u_short link_tos0metric;
|
||||
} rla_link[1]; /* may repeat */
|
||||
} un_rla;
|
||||
|
||||
/* Network links advertisements */
|
||||
struct {
|
||||
struct in_addr nla_mask;
|
||||
struct in_addr nla_router[1]; /* may repeat */
|
||||
} un_nla;
|
||||
|
||||
/* Summary links advertisements */
|
||||
struct {
|
||||
struct in_addr sla_mask;
|
||||
u_int32 sla_tosmetric[1]; /* may repeat */
|
||||
} un_sla;
|
||||
|
||||
/* AS external links advertisements */
|
||||
struct {
|
||||
struct in_addr asla_mask;
|
||||
struct aslametric {
|
||||
u_int32 asla_tosmetric;
|
||||
struct in_addr asla_forward;
|
||||
struct in_addr asla_tag;
|
||||
} asla_metric[1]; /* may repeat */
|
||||
} un_asla;
|
||||
|
||||
/* Multicast group membership */
|
||||
struct mcla {
|
||||
u_int32 mcla_vtype;
|
||||
struct in_addr mcla_vid;
|
||||
} un_mcla[1];
|
||||
} lsa_un;
|
||||
} ;
|
||||
|
||||
|
||||
/*
|
||||
* TOS metric struct (will be 0 or more in router links update)
|
||||
*/
|
||||
struct tos_metric {
|
||||
u_char tos_type;
|
||||
u_char tos_zero;
|
||||
u_short tos_metric;
|
||||
} ;
|
||||
|
||||
#define OSPF_AUTH_SIZE 8
|
||||
|
||||
/*
|
||||
* the main header
|
||||
*/
|
||||
struct ospfhdr {
|
||||
u_char ospf_version;
|
||||
u_char ospf_type;
|
||||
u_short ospf_len;
|
||||
struct in_addr ospf_routerid;
|
||||
struct in_addr ospf_areaid;
|
||||
u_short ospf_chksum;
|
||||
u_short ospf_authtype;
|
||||
u_char ospf_authdata[OSPF_AUTH_SIZE];
|
||||
union {
|
||||
|
||||
/* Hello packet */
|
||||
struct {
|
||||
struct in_addr hello_mask;
|
||||
u_short hello_helloint;
|
||||
u_char hello_options;
|
||||
u_char hello_priority;
|
||||
u_int32 hello_deadint;
|
||||
struct in_addr hello_dr;
|
||||
struct in_addr hello_bdr;
|
||||
struct in_addr hello_neighbor[1]; /* may repeat */
|
||||
} un_hello;
|
||||
|
||||
/* Database Description packet */
|
||||
struct {
|
||||
u_char db_zero[2];
|
||||
u_char db_options;
|
||||
u_char db_flags;
|
||||
u_int32 db_seq;
|
||||
struct lsa_hdr db_lshdr[1]; /* may repeat */
|
||||
} un_db;
|
||||
|
||||
/* Link State Request */
|
||||
struct lsr {
|
||||
u_int32 ls_type;
|
||||
struct in_addr ls_stateid;
|
||||
struct in_addr ls_router;
|
||||
} un_lsr[1]; /* may repeat */
|
||||
|
||||
/* Link State Update */
|
||||
struct {
|
||||
u_int32 lsu_count;
|
||||
struct lsa lsu_lsa[1]; /* may repeat */
|
||||
} un_lsu;
|
||||
|
||||
/* Link State Acknowledment */
|
||||
struct {
|
||||
struct lsa_hdr lsa_lshdr[1]; /* may repeat */
|
||||
} un_lsa ;
|
||||
} ospf_un ;
|
||||
} ;
|
||||
|
||||
#define ospf_hello ospf_un.un_hello
|
||||
#define ospf_db ospf_un.un_db
|
||||
#define ospf_lsr ospf_un.un_lsr
|
||||
#define ospf_lsu ospf_un.un_lsu
|
||||
#define ospf_lsa ospf_un.un_lsa
|
||||
|
@ -1,426 +0,0 @@
|
||||
#ifndef lint
|
||||
static char *RCSid = "$Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/parsenfsfh.c,v 1.1 1995/03/08 12:52:23 olah Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* parsenfsfh.c - portable parser for NFS file handles
|
||||
* uses all sorts of heuristics
|
||||
*
|
||||
* Jeffrey C. Mogul
|
||||
* Digital Equipment Corporation
|
||||
* Western Research Laboratory
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "nfsfh.h"
|
||||
|
||||
/*
|
||||
* Make sure that we use 32-bit integers when necessary. The "x"
|
||||
* suffix is to avoid possible identifier conflicts.
|
||||
*/
|
||||
|
||||
typedef int int32x;
|
||||
typedef unsigned int u_int32x;
|
||||
|
||||
/*
|
||||
* This routine attempts to parse a file handle (in network byte order),
|
||||
* using heuristics to guess what kind of format it is in. See the
|
||||
* file "fhandle_layouts" for a detailed description of the various
|
||||
* patterns we know about.
|
||||
*
|
||||
* The file handle is parsed into our internal representation of a
|
||||
* file-system id, and an internal representation of an inode-number.
|
||||
*/
|
||||
|
||||
#define FHT_UNKNOWN 0
|
||||
#define FHT_AUSPEX 1
|
||||
#define FHT_DECOSF 2
|
||||
#define FHT_IRIX4 3
|
||||
#define FHT_IRIX5 4
|
||||
#define FHT_SUNOS3 5
|
||||
#define FHT_SUNOS4 6
|
||||
#define FHT_ULTRIX 7
|
||||
#define FHT_VMSUCX 8
|
||||
#define FHT_SUNOS5 9
|
||||
#define FHT_AIX32 10
|
||||
#define FHT_HPUX9 11
|
||||
|
||||
#ifdef ultrix
|
||||
/* Nasty hack to keep the Ultrix C compiler from emitting bogus warnings */
|
||||
#define XFF(x) ((unsigned long)(x))
|
||||
#else
|
||||
#define XFF(x) (x)
|
||||
#endif
|
||||
|
||||
#define make_uint32(msb,b,c,lsb)\
|
||||
(XFF(lsb) + (XFF(c)<<8) + (XFF(b)<<16) + (XFF(msb)<<24))
|
||||
|
||||
#define make_uint24(msb,b, lsb)\
|
||||
(XFF(lsb) + (XFF(b)<<8) + (XFF(msb)<<16))
|
||||
|
||||
#define make_uint16(msb,lsb)\
|
||||
(XFF(lsb) + (XFF(msb)<<8))
|
||||
|
||||
#ifdef __alpha
|
||||
/* or other 64-bit systems */
|
||||
#define make_uint48(msb,b,c,d,e,lsb)\
|
||||
((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24) + ((b)<<32) + ((msb)<<40))
|
||||
#else
|
||||
/* on 32-bit systems ignore high-order bits */
|
||||
#define make_uint48(msb,b,c,d,e,lsb)\
|
||||
((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24))
|
||||
#endif
|
||||
|
||||
static int is_UCX(unsigned char *);
|
||||
|
||||
void
|
||||
Parse_fh(fh, len, fsidp, inop, osnamep, fsnamep, ourself)
|
||||
register caddr_t *fh;
|
||||
int len;
|
||||
my_fsid *fsidp;
|
||||
ino_t *inop;
|
||||
char **osnamep; /* if non-NULL, return OS name here */
|
||||
char **fsnamep; /* if non-NULL, return server fs name here (for VMS) */
|
||||
int ourself; /* true if file handle was generated on this host */
|
||||
{
|
||||
register unsigned char *fhp = (unsigned char *)fh;
|
||||
u_int32x temp;
|
||||
int fhtype = FHT_UNKNOWN;
|
||||
|
||||
if (ourself) {
|
||||
/* File handle generated on this host, no need for guessing */
|
||||
#if defined(IRIX40)
|
||||
fhtype = FHT_IRIX4;
|
||||
#endif
|
||||
#if defined(IRIX50)
|
||||
fhtype = FHT_IRIX5;
|
||||
#endif
|
||||
#if defined(IRIX51)
|
||||
fhtype = FHT_IRIX5;
|
||||
#endif
|
||||
#if defined(SUNOS4)
|
||||
fhtype = FHT_SUNOS4;
|
||||
#endif
|
||||
#if defined(SUNOS5)
|
||||
fhtype = FHT_SUNOS5;
|
||||
#endif
|
||||
#if defined(ultrix)
|
||||
fhtype = FHT_ULTRIX;
|
||||
#endif
|
||||
#if defined(__osf__)
|
||||
fhtype = FHT_DECOSF;
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
* This is basically a big decision tree
|
||||
*/
|
||||
else if ((fhp[0] == 0) && (fhp[1] == 0)) {
|
||||
/* bytes[0,1] == (0,0); rules out Ultrix, IRIX5, SUNOS5 */
|
||||
/* probably rules out HP-UX, AIX unless they allow major=0 */
|
||||
if ((fhp[2] == 0) && (fhp[3] == 0)) {
|
||||
/* bytes[2,3] == (0,0); must be Auspex */
|
||||
/* XXX or could be Ultrix+MASSBUS "hp" disk? */
|
||||
fhtype = FHT_AUSPEX;
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* bytes[2,3] != (0,0); rules out Auspex, could be
|
||||
* DECOSF, SUNOS4, or IRIX4
|
||||
*/
|
||||
if ((fhp[4] != 0) && (fhp[5] == 0) &&
|
||||
(fhp[8] == 12) && (fhp[9] == 0)) {
|
||||
/* seems to be DECOSF, with minor == 0 */
|
||||
fhtype = FHT_DECOSF;
|
||||
}
|
||||
else {
|
||||
/* could be SUNOS4 or IRIX4 */
|
||||
/* XXX the test of fhp[5] == 8 could be wrong */
|
||||
if ((fhp[4] == 0) && (fhp[5] == 8) && (fhp[6] == 0) &&
|
||||
(fhp[7] == 0)) {
|
||||
/* looks like a length, not a file system typecode */
|
||||
fhtype = FHT_IRIX4;
|
||||
}
|
||||
else {
|
||||
/* by elimination */
|
||||
fhtype = FHT_SUNOS4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* bytes[0,1] != (0,0); rules out Auspex, IRIX4, SUNOS4
|
||||
* could be IRIX5, DECOSF, UCX, Ultrix, SUNOS5
|
||||
* could be AIX, HP-UX
|
||||
*/
|
||||
if ((fhp[2] == 0) && (fhp[3] == 0)) {
|
||||
/*
|
||||
* bytes[2,3] == (0,0); rules out OSF, probably not UCX
|
||||
* (unless the exported device name is just one letter!),
|
||||
* could be Ultrix, IRIX5, AIX, or SUNOS5
|
||||
* might be HP-UX (depends on their values for minor devs)
|
||||
*/
|
||||
/*XXX we probably only need to test of these two bytes */
|
||||
if ((fhp[21] == 0) && (fhp[23] == 0)) {
|
||||
fhtype = FHT_ULTRIX;
|
||||
}
|
||||
else {
|
||||
/* Could be SUNOS5/IRIX5, maybe AIX */
|
||||
/* XXX no obvious difference between SUNOS5 and IRIX5 */
|
||||
if (fhp[9] == 10)
|
||||
fhtype = FHT_SUNOS5;
|
||||
/* XXX what about AIX? */
|
||||
}
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* bytes[2,3] != (0,0); rules out Ultrix, could be
|
||||
* DECOSF, SUNOS5, IRIX5, AIX, HP-UX, or UCX
|
||||
*/
|
||||
if ((fhp[8] == 12) && (fhp[9] == 0)) {
|
||||
fhtype = FHT_DECOSF;
|
||||
}
|
||||
else if ((fhp[8] == 0) && (fhp[9] == 10)) {
|
||||
/* could be SUNOS5/IRIX5, AIX, HP-UX */
|
||||
if ((fhp[7] == 0) && (fhp[6] == 0) &&
|
||||
(fhp[5] == 0) && (fhp[4] == 0)) {
|
||||
/* XXX is this always true of HP-UX? */
|
||||
fhtype = FHT_HPUX9;
|
||||
}
|
||||
else if (fhp[7] == 2) {
|
||||
/* This would be MNT_NFS on AIX, which is impossible */
|
||||
fhtype = FHT_SUNOS5; /* or maybe IRIX5 */
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* XXX Could be SUNOS5/IRIX5 or AIX. I don't
|
||||
* XXX see any way to disambiguate these, so
|
||||
* XXX I'm going with the more likely guess.
|
||||
* XXX Sorry, Big Blue.
|
||||
*/
|
||||
fhtype = FHT_SUNOS5; /* or maybe IRIX5 */
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (is_UCX(fhp)) {
|
||||
fhtype = FHT_VMSUCX;
|
||||
}
|
||||
else {
|
||||
fhtype = FHT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* XXX still needs to handle SUNOS3 */
|
||||
|
||||
switch (fhtype) {
|
||||
case FHT_AUSPEX:
|
||||
fsidp->fsid_dev.Minor = fhp[7];
|
||||
fsidp->fsid_dev.Major = fhp[6];
|
||||
fsidp->fsid_code = 0;
|
||||
|
||||
temp = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]);
|
||||
*inop = temp;
|
||||
|
||||
if (osnamep)
|
||||
*osnamep = "Auspex";
|
||||
break;
|
||||
|
||||
case FHT_DECOSF:
|
||||
fsidp->fsid_code = make_uint32(fhp[7], fhp[6], fhp[5], fhp[4]);
|
||||
/* XXX could ignore 3 high-order bytes */
|
||||
|
||||
temp = make_uint32(fhp[3], fhp[2], fhp[1], fhp[0]);
|
||||
fsidp->fsid_dev.Minor = temp & 0xFFFFF;
|
||||
fsidp->fsid_dev.Major = (temp>>20) & 0xFFF;
|
||||
|
||||
temp = make_uint32(fhp[15], fhp[14], fhp[13], fhp[12]);
|
||||
*inop = temp;
|
||||
if (osnamep)
|
||||
*osnamep = "OSF";
|
||||
break;
|
||||
|
||||
case FHT_IRIX4:
|
||||
fsidp->fsid_dev.Minor = fhp[3];
|
||||
fsidp->fsid_dev.Major = fhp[2];
|
||||
fsidp->fsid_code = 0;
|
||||
|
||||
temp = make_uint32(fhp[8], fhp[9], fhp[10], fhp[11]);
|
||||
*inop = temp;
|
||||
|
||||
if (osnamep)
|
||||
*osnamep = "IRIX4";
|
||||
break;
|
||||
|
||||
case FHT_IRIX5:
|
||||
fsidp->fsid_dev.Minor = make_uint16(fhp[2], fhp[3]);
|
||||
fsidp->fsid_dev.Major = make_uint16(fhp[0], fhp[1]);
|
||||
fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]);
|
||||
|
||||
temp = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]);
|
||||
*inop = temp;
|
||||
|
||||
if (osnamep)
|
||||
*osnamep = "IRIX5";
|
||||
break;
|
||||
|
||||
case FHT_SUNOS3:
|
||||
if (osnamep)
|
||||
*osnamep = "SUNOS3";
|
||||
break;
|
||||
|
||||
case FHT_SUNOS4:
|
||||
fsidp->fsid_dev.Minor = fhp[3];
|
||||
fsidp->fsid_dev.Major = fhp[2];
|
||||
fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]);
|
||||
|
||||
temp = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]);
|
||||
*inop = temp;
|
||||
|
||||
if (osnamep)
|
||||
*osnamep = "SUNOS4";
|
||||
break;
|
||||
|
||||
case FHT_SUNOS5:
|
||||
temp = make_uint16(fhp[0], fhp[1]);
|
||||
fsidp->fsid_dev.Major = (temp>>2) & 0x3FFF;
|
||||
temp = make_uint24(fhp[1], fhp[2], fhp[3]);
|
||||
fsidp->fsid_dev.Minor = temp & 0x3FFFF;
|
||||
fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]);
|
||||
|
||||
temp = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]);
|
||||
*inop = temp;
|
||||
|
||||
if (osnamep)
|
||||
*osnamep = "SUNOS5";
|
||||
break;
|
||||
|
||||
case FHT_ULTRIX:
|
||||
fsidp->fsid_code = 0;
|
||||
fsidp->fsid_dev.Minor = fhp[0];
|
||||
fsidp->fsid_dev.Major = fhp[1];
|
||||
|
||||
temp = make_uint32(fhp[7], fhp[6], fhp[5], fhp[4]);
|
||||
*inop = temp;
|
||||
if (osnamep)
|
||||
*osnamep = "Ultrix";
|
||||
break;
|
||||
|
||||
case FHT_VMSUCX:
|
||||
/* No numeric file system ID, so hash on the device-name */
|
||||
if (sizeof(*fsidp) >= 14) {
|
||||
if (sizeof(*fsidp) > 14)
|
||||
bzero((char *)fsidp, sizeof(*fsidp));
|
||||
bcopy(fh, (char *)fsidp, 14); /* just use the whole thing */
|
||||
}
|
||||
else {
|
||||
u_long tempa[4]; /* at least 16 bytes, maybe more */
|
||||
|
||||
bzero((char *)tempa, sizeof(tempa));
|
||||
bcopy(fh, (char *)tempa, 14); /* ensure alignment */
|
||||
fsidp->fsid_dev.Minor = tempa[0] + (tempa[1]<<1);
|
||||
fsidp->fsid_dev.Major = tempa[2] + (tempa[3]<<1);
|
||||
fsidp->fsid_code = 0;
|
||||
}
|
||||
|
||||
/* VMS file ID is: (RVN, FidHi, FidLo) */
|
||||
*inop = make_uint32(fhp[26], fhp[27], fhp[23], fhp[22]);
|
||||
|
||||
/* Caller must save (and null-terminate?) this value */
|
||||
if (fsnamep)
|
||||
*fsnamep = (char *)&(fhp[1]);
|
||||
|
||||
if (osnamep)
|
||||
*osnamep = "VMS";
|
||||
break;
|
||||
|
||||
case FHT_AIX32:
|
||||
fsidp->fsid_dev.Minor = make_uint16(fhp[2], fhp[3]);
|
||||
fsidp->fsid_dev.Major = make_uint16(fhp[0], fhp[1]);
|
||||
fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]);
|
||||
|
||||
temp = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]);
|
||||
*inop = temp;
|
||||
|
||||
if (osnamep)
|
||||
*osnamep = "AIX32";
|
||||
break;
|
||||
|
||||
case FHT_HPUX9:
|
||||
fsidp->fsid_dev.Major = fhp[0];
|
||||
temp = make_uint24(fhp[1], fhp[2], fhp[3]);
|
||||
fsidp->fsid_dev.Minor = temp;
|
||||
fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]);
|
||||
|
||||
temp = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]);
|
||||
*inop = temp;
|
||||
|
||||
if (osnamep)
|
||||
*osnamep = "HPUX9";
|
||||
break;
|
||||
|
||||
case FHT_UNKNOWN:
|
||||
#ifdef DEBUG
|
||||
{
|
||||
/* XXX debugging */
|
||||
int i;
|
||||
for (i=0; i<32;i++) fprintf(stderr, "%x.", fhp[i]);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
#endif
|
||||
/* XXX for now, give "bogus" values to aid debugging */
|
||||
fsidp->fsid_code = 0;
|
||||
fsidp->fsid_dev.Minor = 257;
|
||||
fsidp->fsid_dev.Major = 257;
|
||||
*inop = 1;
|
||||
|
||||
/* display will show this string instead of (257,257) */
|
||||
if (fsnamep)
|
||||
*fsnamep = "Unknown";
|
||||
|
||||
if (osnamep)
|
||||
*osnamep = "Unknown";
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Is this a VMS UCX file handle?
|
||||
* Check for:
|
||||
* (1) leading code byte [XXX not yet]
|
||||
* (2) followed by string of printing chars & spaces
|
||||
* (3) followed by string of nulls
|
||||
*/
|
||||
static int
|
||||
is_UCX(fhp)
|
||||
unsigned char *fhp;
|
||||
{
|
||||
register int i;
|
||||
int seen_null = 0;
|
||||
|
||||
for (i = 1; i < 14; i++) {
|
||||
if (isprint(fhp[i])) {
|
||||
if (seen_null)
|
||||
return(0);
|
||||
else
|
||||
continue;
|
||||
}
|
||||
else if (fhp[i] == 0) {
|
||||
seen_null = 1;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
return(0);
|
||||
}
|
||||
|
||||
return(1);
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: print-arp.c,v 1.28 94/06/14 20:17:36 leres Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
static u_char ezero[6];
|
||||
|
||||
void
|
||||
arp_print(register const u_char *bp, int length, int caplen)
|
||||
{
|
||||
register const struct ether_arp *ap;
|
||||
register const struct ether_header *eh;
|
||||
const u_char *p;
|
||||
int pro, hrd, op;
|
||||
|
||||
ap = (struct ether_arp *)bp;
|
||||
if ((u_char *)(ap + 1) > snapend) {
|
||||
printf("[|arp]");
|
||||
return;
|
||||
}
|
||||
if (length < sizeof(struct ether_arp)) {
|
||||
(void)printf("truncated-arp");
|
||||
default_print((u_char *)ap, length);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Don't assume alignment.
|
||||
*/
|
||||
p = (u_char*)&ap->arp_pro;
|
||||
pro = (p[0] << 8) | p[1];
|
||||
p = (u_char*)&ap->arp_hrd;
|
||||
hrd = (p[0] << 8) | p[1];
|
||||
p = (u_char*)&ap->arp_op;
|
||||
op = (p[0] << 8) | p[1];
|
||||
|
||||
if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL)
|
||||
|| ap->arp_hln != sizeof(SHA(ap))
|
||||
|| ap->arp_pln != sizeof(SPA(ap))) {
|
||||
(void)printf("arp-#%d for proto #%d (%d) hardware #%d (%d)",
|
||||
op, pro, ap->arp_pln,
|
||||
hrd, ap->arp_hln);
|
||||
return;
|
||||
}
|
||||
if (pro == ETHERTYPE_TRAIL)
|
||||
(void)printf("trailer-");
|
||||
eh = (struct ether_header *)packetp;
|
||||
switch (op) {
|
||||
|
||||
case ARPOP_REQUEST:
|
||||
(void)printf("arp who-has %s", ipaddr_string(TPA(ap)));
|
||||
if (bcmp((char *)ezero, (char *)THA(ap), 6) != 0)
|
||||
(void)printf(" (%s)", etheraddr_string(THA(ap)));
|
||||
(void)printf(" tell %s", ipaddr_string(SPA(ap)));
|
||||
if (bcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0)
|
||||
(void)printf(" (%s)", etheraddr_string(SHA(ap)));
|
||||
break;
|
||||
|
||||
case ARPOP_REPLY:
|
||||
(void)printf("arp reply %s", ipaddr_string(SPA(ap)));
|
||||
if (bcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0)
|
||||
(void)printf(" (%s)", etheraddr_string(SHA(ap)));
|
||||
(void)printf(" is-at %s", etheraddr_string(SHA(ap)));
|
||||
if (bcmp((char *)EDST(eh), (char *)THA(ap), 6) != 0)
|
||||
(void)printf(" (%s)", etheraddr_string(THA(ap)));
|
||||
break;
|
||||
|
||||
case REVARP_REQUEST:
|
||||
(void)printf("rarp who-is %s tell %s",
|
||||
etheraddr_string(THA(ap)),
|
||||
etheraddr_string(SHA(ap)));
|
||||
break;
|
||||
|
||||
case REVARP_REPLY:
|
||||
(void)printf("rarp reply %s at %s",
|
||||
etheraddr_string(THA(ap)),
|
||||
ipaddr_string(TPA(ap)));
|
||||
break;
|
||||
|
||||
default:
|
||||
(void)printf("arp-#%d", op);
|
||||
default_print((u_char *)ap, caplen);
|
||||
return;
|
||||
}
|
||||
if (hrd != ARPHRD_ETHER)
|
||||
printf(" hardware #%d", ap->arp_hrd);
|
||||
}
|
@ -1,578 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 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.
|
||||
*
|
||||
* Format and print AppleTalk packets.
|
||||
*/
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#)$Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/print-atalk.c,v 1.2 1995/03/08 12:52:25 olah Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
#include "ethertype.h"
|
||||
#include "extract.h" /* must come after interface.h */
|
||||
#include "appletalk.h"
|
||||
|
||||
static struct token type2str[] = {
|
||||
{ ddpRTMP, "rtmp" },
|
||||
{ ddpRTMPrequest, "rtmpReq" },
|
||||
{ ddpECHO, "echo" },
|
||||
{ ddpIP, "IP" },
|
||||
{ ddpARP, "ARP" },
|
||||
{ ddpKLAP, "KLAP" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
struct aarp {
|
||||
u_short htype, ptype;
|
||||
u_char halen, palen;
|
||||
u_short op;
|
||||
u_char hsaddr[6];
|
||||
u_char psaddr[4];
|
||||
u_char hdaddr[6];
|
||||
u_char pdaddr[4];
|
||||
};
|
||||
|
||||
static char tstr[] = "[|atalk]";
|
||||
|
||||
static void atp_print(const struct atATP *, int);
|
||||
static void atp_bitmap_print(u_char);
|
||||
static void nbp_print(const struct atNBP *, int, u_short, u_char, u_char);
|
||||
static const char *print_cstring(const char *, const u_char *);
|
||||
static const struct atNBPtuple *nbp_tuple_print(const struct atNBPtuple *,
|
||||
const u_char *,
|
||||
u_short, u_char, u_char);
|
||||
static const struct atNBPtuple *nbp_name_print(const struct atNBPtuple *,
|
||||
const u_char *);
|
||||
static const char *ataddr_string(u_short, u_char);
|
||||
static void ddp_print(const u_char *, int, int, u_short, u_char, u_char);
|
||||
static const char *ddpskt_string(int);
|
||||
|
||||
/*
|
||||
* Print AppleTalk Datagram Delivery Protocol packets.
|
||||
*/
|
||||
void
|
||||
atalk_print(register const u_char *bp, int length)
|
||||
{
|
||||
register const struct LAP *lp;
|
||||
register const struct atDDP *dp;
|
||||
register const struct atShortDDP *sdp;
|
||||
u_short snet;
|
||||
|
||||
#if 0
|
||||
lp = (struct LAP *)bp;
|
||||
bp += sizeof(*lp);
|
||||
length -= sizeof(*lp);
|
||||
#else
|
||||
{
|
||||
static struct LAP lp_ = {0, 0, lapDDP};
|
||||
lp = &lp_;
|
||||
}
|
||||
#endif
|
||||
switch (lp->type) {
|
||||
|
||||
case lapShortDDP:
|
||||
if (length < ddpSSize) {
|
||||
(void)printf(" [|sddp %d]", length);
|
||||
return;
|
||||
}
|
||||
sdp = (const struct atShortDDP *)bp;
|
||||
printf("%s.%s",
|
||||
ataddr_string(0, lp->src), ddpskt_string(sdp->srcSkt));
|
||||
printf(" > %s.%s:",
|
||||
ataddr_string(0, lp->dst), ddpskt_string(sdp->dstSkt));
|
||||
bp += ddpSSize;
|
||||
length -= ddpSSize;
|
||||
ddp_print(bp, length, sdp->type, 0, lp->src, sdp->srcSkt);
|
||||
break;
|
||||
|
||||
case lapDDP:
|
||||
if (length < ddpSize) {
|
||||
(void)printf(" [|ddp %d]", length);
|
||||
return;
|
||||
}
|
||||
dp = (const struct atDDP *)bp;
|
||||
snet = EXTRACT_SHORT(&dp->srcNet);
|
||||
printf("%s.%s", ataddr_string(snet, dp->srcNode),
|
||||
ddpskt_string(dp->srcSkt));
|
||||
printf(" > %s.%s:",
|
||||
ataddr_string(EXTRACT_SHORT(&dp->dstNet), dp->dstNode),
|
||||
ddpskt_string(dp->dstSkt));
|
||||
bp += ddpSize;
|
||||
length -= ddpSize;
|
||||
ddp_print(bp, length, dp->type, snet, dp->srcNode, dp->srcSkt);
|
||||
break;
|
||||
|
||||
#ifdef notdef
|
||||
case lapKLAP:
|
||||
klap_print(bp, length);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
printf("%d > %d at-lap#%d %d",
|
||||
lp->src, lp->dst, lp->type, length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* XXX should probably pass in the snap header and do checks like arp_print() */
|
||||
void
|
||||
aarp_print(register const u_char *bp, int length)
|
||||
{
|
||||
register const struct aarp *ap;
|
||||
|
||||
#define AT(member) ataddr_string((ap->member[1]<<8)|ap->member[2],ap->member[3])
|
||||
|
||||
printf("aarp ");
|
||||
ap = (const struct aarp *)bp;
|
||||
if (ap->htype == 1 && ap->ptype == ETHERTYPE_ATALK &&
|
||||
ap->halen == 6 && ap->palen == 4 )
|
||||
switch (ap->op) {
|
||||
|
||||
case 1: /* request */
|
||||
(void)printf("who-has %s tell %s",
|
||||
AT(pdaddr), AT(psaddr));
|
||||
return;
|
||||
|
||||
case 2: /* response */
|
||||
(void)printf("reply %s is-at %s",
|
||||
AT(pdaddr), etheraddr_string(ap->hdaddr));
|
||||
return;
|
||||
|
||||
case 3: /* probe (oy!) */
|
||||
(void)printf("probe %s tell %s",
|
||||
AT(pdaddr), AT(psaddr));
|
||||
return;
|
||||
}
|
||||
(void)printf("len %d op %d htype %d ptype %#x halen %d palen %d",
|
||||
length, ap->op, ap->htype, ap->ptype, ap->halen, ap->palen );
|
||||
}
|
||||
|
||||
static void
|
||||
ddp_print(register const u_char *bp, register int length, register int t,
|
||||
register u_short snet, register u_char snode, u_char skt)
|
||||
{
|
||||
|
||||
switch (t) {
|
||||
|
||||
case ddpNBP:
|
||||
nbp_print((const struct atNBP *)bp, length, snet, snode, skt);
|
||||
break;
|
||||
|
||||
case ddpATP:
|
||||
atp_print((const struct atATP *)bp, length);
|
||||
break;
|
||||
|
||||
default:
|
||||
(void)printf(" at-%s %d", tok2str(type2str, NULL, t), length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
atp_print(register const struct atATP *ap, int length)
|
||||
{
|
||||
char c;
|
||||
u_int32 data;
|
||||
|
||||
if ((const u_char *)(ap + 1) > snapend) {
|
||||
/* Just bail if we don't have the whole chunk. */
|
||||
fputs(tstr, stdout);
|
||||
return;
|
||||
}
|
||||
length -= sizeof(*ap);
|
||||
switch (ap->control & 0xc0) {
|
||||
|
||||
case atpReqCode:
|
||||
(void)printf(" atp-req%s %d",
|
||||
ap->control & atpXO? " " : "*",
|
||||
EXTRACT_SHORT(&ap->transID));
|
||||
|
||||
atp_bitmap_print(ap->bitmap);
|
||||
|
||||
if (length != 0)
|
||||
(void)printf(" [len=%d]", length);
|
||||
|
||||
switch (ap->control & (atpEOM|atpSTS)) {
|
||||
case atpEOM:
|
||||
(void)printf(" [EOM]");
|
||||
break;
|
||||
case atpSTS:
|
||||
(void)printf(" [STS]");
|
||||
break;
|
||||
case atpEOM|atpSTS:
|
||||
(void)printf(" [EOM,STS]");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case atpRspCode:
|
||||
(void)printf(" atp-resp%s%d:%d (%d)",
|
||||
ap->control & atpEOM? "*" : " ",
|
||||
EXTRACT_SHORT(&ap->transID), ap->bitmap, length);
|
||||
switch (ap->control & (atpXO|atpSTS)) {
|
||||
case atpXO:
|
||||
(void)printf(" [XO]");
|
||||
break;
|
||||
case atpSTS:
|
||||
(void)printf(" [STS]");
|
||||
break;
|
||||
case atpXO|atpSTS:
|
||||
(void)printf(" [XO,STS]");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case atpRelCode:
|
||||
(void)printf(" atp-rel %d", EXTRACT_SHORT(&ap->transID));
|
||||
|
||||
atp_bitmap_print(ap->bitmap);
|
||||
|
||||
/* length should be zero */
|
||||
if (length)
|
||||
(void)printf(" [len=%d]", length);
|
||||
|
||||
/* there shouldn't be any control flags */
|
||||
if (ap->control & (atpXO|atpEOM|atpSTS)) {
|
||||
c = '[';
|
||||
if (ap->control & atpXO) {
|
||||
(void)printf("%cXO", c);
|
||||
c = ',';
|
||||
}
|
||||
if (ap->control & atpEOM) {
|
||||
(void)printf("%cEOM", c);
|
||||
c = ',';
|
||||
}
|
||||
if (ap->control & atpSTS) {
|
||||
(void)printf("%cSTS", c);
|
||||
c = ',';
|
||||
}
|
||||
(void)printf("]");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
(void)printf(" atp-0x%x %d (%d)", ap->control,
|
||||
EXTRACT_SHORT(&ap->transID), length);
|
||||
break;
|
||||
}
|
||||
data = EXTRACT_LONG(&ap->userData);
|
||||
if (data != 0)
|
||||
(void)printf(" 0x%x", data);
|
||||
}
|
||||
|
||||
static void
|
||||
atp_bitmap_print(register u_char bm)
|
||||
{
|
||||
register char c;
|
||||
register int i;
|
||||
|
||||
/*
|
||||
* The '& 0xff' below is needed for compilers that want to sign
|
||||
* extend a u_char, which is the case with the Ultrix compiler.
|
||||
* (gcc is smart enough to eliminate it, at least on the Sparc).
|
||||
*/
|
||||
if ((bm + 1) & (bm & 0xff)) {
|
||||
c = '<';
|
||||
for (i = 0; bm; ++i) {
|
||||
if (bm & 1) {
|
||||
(void)printf("%c%d", c, i);
|
||||
c = ',';
|
||||
}
|
||||
bm >>= 1;
|
||||
}
|
||||
(void)printf(">");
|
||||
} else {
|
||||
for (i = 0; bm; ++i)
|
||||
bm >>= 1;
|
||||
if (i > 1)
|
||||
(void)printf("<0-%d>", i - 1);
|
||||
else
|
||||
(void)printf("<0>");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nbp_print(register const struct atNBP *np, int length, register u_short snet,
|
||||
register u_char snode, register u_char skt)
|
||||
{
|
||||
register const struct atNBPtuple *tp =
|
||||
(struct atNBPtuple *)((u_char *)np + nbpHeaderSize);
|
||||
int i = length;
|
||||
const u_char *ep;
|
||||
|
||||
length -= nbpHeaderSize;
|
||||
if (length < 8) {
|
||||
/* must be room for at least one tuple */
|
||||
(void)printf(" truncated-nbp %d", length + nbpHeaderSize);
|
||||
return;
|
||||
}
|
||||
/* ep points to end of available data */
|
||||
ep = snapend;
|
||||
if ((const u_char *)tp > ep) {
|
||||
fputs(tstr, stdout);
|
||||
return;
|
||||
}
|
||||
switch (i = np->control & 0xf0) {
|
||||
|
||||
case nbpBrRq:
|
||||
case nbpLkUp:
|
||||
(void)printf(i == nbpLkUp? " nbp-lkup %d:":" nbp-brRq %d:",
|
||||
np->id);
|
||||
if ((const u_char *)(tp + 1) > ep) {
|
||||
fputs(tstr, stdout);
|
||||
return;
|
||||
}
|
||||
(void)nbp_name_print(tp, ep);
|
||||
/*
|
||||
* look for anomalies: the spec says there can only
|
||||
* be one tuple, the address must match the source
|
||||
* address and the enumerator should be zero.
|
||||
*/
|
||||
if ((np->control & 0xf) != 1)
|
||||
(void)printf(" [ntup=%d]", np->control & 0xf);
|
||||
if (tp->enumerator)
|
||||
(void)printf(" [enum=%d]", tp->enumerator);
|
||||
if (EXTRACT_SHORT(&tp->net) != snet ||
|
||||
tp->node != snode || tp->skt != skt)
|
||||
(void)printf(" [addr=%s.%d]",
|
||||
ataddr_string(EXTRACT_SHORT(&tp->net),
|
||||
tp->node), tp->skt);
|
||||
break;
|
||||
|
||||
case nbpLkUpReply:
|
||||
(void)printf(" nbp-reply %d:", np->id);
|
||||
|
||||
/* print each of the tuples in the reply */
|
||||
for (i = np->control & 0xf; --i >= 0 && tp; )
|
||||
tp = nbp_tuple_print(tp, ep, snet, snode, skt);
|
||||
break;
|
||||
|
||||
default:
|
||||
(void)printf(" nbp-0x%x %d (%d)", np->control, np->id,
|
||||
length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* print a counted string */
|
||||
static const char *
|
||||
print_cstring(register const char *cp, register const u_char *ep)
|
||||
{
|
||||
register int length;
|
||||
|
||||
if (cp >= (const char *)ep) {
|
||||
fputs(tstr, stdout);
|
||||
return (0);
|
||||
}
|
||||
length = *cp++;
|
||||
|
||||
/* Spec says string can be at most 32 bytes long */
|
||||
if (length < 0 || length > 32) {
|
||||
(void)printf("[len=%d]", length);
|
||||
return (0);
|
||||
}
|
||||
while (--length >= 0) {
|
||||
if (cp >= (char *)ep) {
|
||||
fputs(tstr, stdout);
|
||||
return (0);
|
||||
}
|
||||
putchar(*cp++);
|
||||
}
|
||||
return (cp);
|
||||
}
|
||||
|
||||
static const struct atNBPtuple *
|
||||
nbp_tuple_print(register const struct atNBPtuple *tp,
|
||||
register const u_char *ep,
|
||||
register u_short snet, register u_char snode,
|
||||
register u_char skt)
|
||||
{
|
||||
register const struct atNBPtuple *tpn;
|
||||
|
||||
if ((const u_char *)(tp + 1) > ep) {
|
||||
fputs(tstr, stdout);
|
||||
return 0;
|
||||
}
|
||||
tpn = nbp_name_print(tp, ep);
|
||||
|
||||
/* if the enumerator isn't 1, print it */
|
||||
if (tp->enumerator != 1)
|
||||
(void)printf("(%d)", tp->enumerator);
|
||||
|
||||
/* if the socket doesn't match the src socket, print it */
|
||||
if (tp->skt != skt)
|
||||
(void)printf(" %d", tp->skt);
|
||||
|
||||
/* if the address doesn't match the src address, it's an anomaly */
|
||||
if (EXTRACT_SHORT(&tp->net) != snet || tp->node != snode)
|
||||
(void)printf(" [addr=%s]",
|
||||
ataddr_string(EXTRACT_SHORT(&tp->net), tp->node));
|
||||
|
||||
return (tpn);
|
||||
}
|
||||
|
||||
static const struct atNBPtuple *
|
||||
nbp_name_print(const struct atNBPtuple *tp, register const u_char *ep)
|
||||
{
|
||||
register const char *cp = (const char *)tp + nbpTupleSize;
|
||||
|
||||
putchar(' ');
|
||||
|
||||
/* Object */
|
||||
putchar('"');
|
||||
if ((cp = print_cstring(cp, ep)) != NULL) {
|
||||
/* Type */
|
||||
putchar(':');
|
||||
if ((cp = print_cstring(cp, ep)) != NULL) {
|
||||
/* Zone */
|
||||
putchar('@');
|
||||
if ((cp = print_cstring(cp, ep)) != NULL)
|
||||
putchar('"');
|
||||
}
|
||||
}
|
||||
return ((const struct atNBPtuple *)cp);
|
||||
}
|
||||
|
||||
|
||||
#define HASHNAMESIZE 4096
|
||||
|
||||
struct hnamemem {
|
||||
int addr;
|
||||
char *name;
|
||||
struct hnamemem *nxt;
|
||||
};
|
||||
|
||||
static struct hnamemem hnametable[HASHNAMESIZE];
|
||||
|
||||
static const char *
|
||||
ataddr_string(u_short atnet, u_char athost)
|
||||
{
|
||||
register struct hnamemem *tp, *tp2;
|
||||
register int i = (atnet << 8) | athost;
|
||||
char nambuf[256];
|
||||
static int first = 1;
|
||||
FILE *fp;
|
||||
|
||||
/*
|
||||
* if this is the first call, see if there's an AppleTalk
|
||||
* number to name map file.
|
||||
*/
|
||||
if (first && (first = 0, !nflag)
|
||||
&& (fp = fopen("/etc/atalk.names", "r"))) {
|
||||
char line[256];
|
||||
int i1, i2, i3;
|
||||
|
||||
while (fgets(line, sizeof(line), fp)) {
|
||||
if (line[0] == '\n' || line[0] == 0 || line[0] == '#')
|
||||
continue;
|
||||
if (sscanf(line, "%d.%d.%d %s", &i1, &i2, &i3,
|
||||
nambuf) == 4)
|
||||
/* got a hostname. */
|
||||
i3 |= ((i1 << 8) | i2) << 8;
|
||||
else if (sscanf(line, "%d.%d %s", &i1, &i2,
|
||||
nambuf) == 3)
|
||||
/* got a net name */
|
||||
i3 = (((i1 << 8) | i2) << 8) | 255;
|
||||
else
|
||||
continue;
|
||||
|
||||
for (tp = &hnametable[i3 & (HASHNAMESIZE-1)];
|
||||
tp->nxt; tp = tp->nxt)
|
||||
;
|
||||
tp->addr = i3;
|
||||
tp->nxt = (struct hnamemem *)calloc(1, sizeof(*tp));
|
||||
tp->name = savestr(nambuf);
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
for (tp = &hnametable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
|
||||
if (tp->addr == i)
|
||||
return (tp->name);
|
||||
|
||||
/* didn't have the node name -- see if we've got the net name */
|
||||
i |= 255;
|
||||
for (tp2 = &hnametable[i & (HASHNAMESIZE-1)]; tp2->nxt; tp2 = tp2->nxt)
|
||||
if (tp2->addr == i) {
|
||||
tp->addr = (atnet << 8) | athost;
|
||||
tp->nxt = (struct hnamemem *)calloc(1, sizeof(*tp));
|
||||
(void)sprintf(nambuf, "%s.%02x", tp2->name, athost);
|
||||
tp->name = savestr(nambuf);
|
||||
return (tp->name);
|
||||
}
|
||||
|
||||
tp->addr = (atnet << 8) | athost;
|
||||
tp->nxt = (struct hnamemem *)calloc(1, sizeof(*tp));
|
||||
if (athost != 255)
|
||||
(void)sprintf(nambuf, "%02x.%02x.%02x",
|
||||
atnet >> 8, atnet & 0xff, athost);
|
||||
else
|
||||
(void)sprintf(nambuf, "%02x.%02x", atnet >> 8, atnet & 0xff);
|
||||
i = strlen(nambuf) + 1;
|
||||
tp->name = strcpy(malloc((u_int) i), nambuf);
|
||||
|
||||
return (tp->name);
|
||||
}
|
||||
|
||||
static struct token skt2str[] = {
|
||||
{ rtmpSkt, "rtmp" }, /* routing table maintenance */
|
||||
{ nbpSkt, "nis" }, /* name info socket */
|
||||
{ echoSkt, "echo" }, /* AppleTalk echo protocol */
|
||||
{ zipSkt, "zip" }, /* zone info protocol */
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static const char *
|
||||
ddpskt_string(register int skt)
|
||||
{
|
||||
static char buf[8];
|
||||
|
||||
if (nflag) {
|
||||
(void)sprintf(buf, "%02x", skt);
|
||||
return (buf);
|
||||
}
|
||||
return (tok2str(skt2str, "%02x", skt));
|
||||
}
|
@ -1,357 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* Format and print bootp packets.
|
||||
*/
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: print-bootp.c,v 1.30 94/06/14 20:17:37 leres Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
#include "bootp.h"
|
||||
|
||||
static void rfc1048_print(const u_char *, int);
|
||||
static void cmu_print(const u_char *, int);
|
||||
|
||||
static char tstr[] = " [|bootp]";
|
||||
|
||||
/*
|
||||
* Print bootp requests
|
||||
*/
|
||||
void
|
||||
bootp_print(register const u_char *cp, int length,
|
||||
u_short sport, u_short dport)
|
||||
{
|
||||
register const struct bootp *bp;
|
||||
static u_char vm_cmu[4] = VM_CMU;
|
||||
static u_char vm_rfc1048[4] = VM_RFC1048;
|
||||
const u_char *ep;
|
||||
|
||||
#define TCHECK(var, l) if ((u_char *)&(var) > ep - l) goto trunc
|
||||
|
||||
bp = (struct bootp *)cp;
|
||||
/* 'ep' points to the end of avaible data. */
|
||||
ep = snapend;
|
||||
|
||||
TCHECK(bp->bp_op, sizeof(bp->bp_op));
|
||||
switch (bp->bp_op) {
|
||||
|
||||
case BOOTREQUEST:
|
||||
/* Usually, a request goes from a client to a server */
|
||||
if (sport != IPPORT_BOOTPC || dport != IPPORT_BOOTPS)
|
||||
printf(" (request)");
|
||||
break;
|
||||
|
||||
case BOOTREPLY:
|
||||
/* Usually, a reply goes from a server to a client */
|
||||
if (sport != IPPORT_BOOTPS || dport != IPPORT_BOOTPC)
|
||||
printf(" (reply)");
|
||||
break;
|
||||
|
||||
default:
|
||||
printf(" bootp-#%d", bp->bp_op);
|
||||
}
|
||||
|
||||
TCHECK(bp->bp_secs, sizeof(bp->bp_secs));
|
||||
|
||||
/* The usual hardware address type is 1 (10Mb Ethernet) */
|
||||
if (bp->bp_htype != 1)
|
||||
printf(" htype-#%d", bp->bp_htype);
|
||||
|
||||
/* The usual length for 10Mb Ethernet address is 6 bytes */
|
||||
if (bp->bp_htype != 1 || bp->bp_hlen != 6)
|
||||
printf(" hlen:%d", bp->bp_hlen);
|
||||
|
||||
/* Only print interesting fields */
|
||||
if (bp->bp_hops)
|
||||
printf(" hops:%d", bp->bp_hops);
|
||||
if (bp->bp_xid)
|
||||
printf(" xid:0x%x", ntohl(bp->bp_xid));
|
||||
if (bp->bp_secs)
|
||||
printf(" secs:%d", ntohs(bp->bp_secs));
|
||||
|
||||
/* Client's ip address */
|
||||
TCHECK(bp->bp_ciaddr, sizeof(bp->bp_ciaddr));
|
||||
if (bp->bp_ciaddr.s_addr)
|
||||
printf(" C:%s", ipaddr_string(&bp->bp_ciaddr));
|
||||
|
||||
/* 'your' ip address (bootp client) */
|
||||
TCHECK(bp->bp_yiaddr, sizeof(bp->bp_yiaddr));
|
||||
if (bp->bp_yiaddr.s_addr)
|
||||
printf(" Y:%s", ipaddr_string(&bp->bp_yiaddr));
|
||||
|
||||
/* Server's ip address */
|
||||
TCHECK(bp->bp_siaddr, sizeof(bp->bp_siaddr));
|
||||
if (bp->bp_siaddr.s_addr)
|
||||
printf(" S:%s", ipaddr_string(&bp->bp_siaddr));
|
||||
|
||||
/* Gateway's ip address */
|
||||
TCHECK(bp->bp_giaddr, sizeof(bp->bp_giaddr));
|
||||
if (bp->bp_giaddr.s_addr)
|
||||
printf(" G:%s", ipaddr_string(&bp->bp_giaddr));
|
||||
|
||||
/* Client's Ethernet address */
|
||||
if (bp->bp_htype == 1 && bp->bp_hlen == 6) {
|
||||
register const struct ether_header *eh;
|
||||
register const char *e;
|
||||
|
||||
TCHECK(bp->bp_chaddr[0], 6);
|
||||
eh = (struct ether_header *)packetp;
|
||||
if (bp->bp_op == BOOTREQUEST)
|
||||
e = (const char *)ESRC(eh);
|
||||
else if (bp->bp_op == BOOTREPLY)
|
||||
e = (const char *)EDST(eh);
|
||||
else
|
||||
e = 0;
|
||||
if (e == 0 || bcmp((char *)bp->bp_chaddr, e, 6) != 0)
|
||||
printf(" ether %s", etheraddr_string(bp->bp_chaddr));
|
||||
}
|
||||
|
||||
TCHECK(bp->bp_sname[0], 1); /* check first char only */
|
||||
if (*bp->bp_sname) {
|
||||
printf(" sname ");
|
||||
if (fn_print(bp->bp_sname, ep)) {
|
||||
fputs(tstr + 1, stdout);
|
||||
return;
|
||||
}
|
||||
}
|
||||
TCHECK(bp->bp_sname[0], 1); /* check first char only */
|
||||
if (*bp->bp_file) {
|
||||
printf(" file ");
|
||||
if (fn_print(bp->bp_file, ep)) {
|
||||
fputs(tstr + 1, stdout);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Decode the vendor buffer */
|
||||
TCHECK(bp->bp_vend[0], sizeof(bp->bp_vend));
|
||||
length -= sizeof(*bp) - sizeof(bp->bp_vend);
|
||||
if (bcmp((char *)bp->bp_vend, (char *)vm_rfc1048,
|
||||
sizeof(u_int32)) == 0)
|
||||
rfc1048_print(bp->bp_vend, length);
|
||||
else if (bcmp((char *)bp->bp_vend, (char *)vm_cmu,
|
||||
sizeof(u_int32)) == 0)
|
||||
cmu_print(bp->bp_vend, length);
|
||||
else {
|
||||
u_int32 ul;
|
||||
|
||||
bcopy((char *)bp->bp_vend, (char *)&ul, sizeof(ul));
|
||||
if (ul != 0)
|
||||
printf("vend-#0x%x", ul);
|
||||
}
|
||||
|
||||
return;
|
||||
trunc:
|
||||
fputs(tstr, stdout);
|
||||
#undef TCHECK
|
||||
}
|
||||
|
||||
/* The first character specifies the format to print */
|
||||
static struct token tag2str[] = {
|
||||
/* RFC1048 tags */
|
||||
{ TAG_PAD, " PAD" },
|
||||
{ TAG_SUBNET_MASK, "iSM" }, /* subnet mask (RFC950) */
|
||||
{ TAG_TIME_OFFSET, "lTZ" }, /* seconds from UTC */
|
||||
{ TAG_GATEWAY, "iDG" }, /* default gateway */
|
||||
{ TAG_TIME_SERVER, "iTS" }, /* time servers (RFC868) */
|
||||
{ TAG_NAME_SERVER, "iIEN" }, /* IEN name servers (IEN116) */
|
||||
{ TAG_DOMAIN_SERVER, "iNS" }, /* domain name (RFC1035) */
|
||||
{ TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */
|
||||
{ TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */
|
||||
{ TAG_LPR_SERVER, "iLPR" }, /* lpr server (RFC1179) */
|
||||
{ TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */
|
||||
{ TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */
|
||||
{ TAG_HOSTNAME, "aHN" }, /* ascii hostname */
|
||||
{ TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */
|
||||
{ TAG_END, " END" },
|
||||
/* RFC1497 tags */
|
||||
{ TAG_DUMPPATH, "aDP" },
|
||||
{ TAG_DOMAINNAME, "aDN" },
|
||||
{ TAG_SWAP_SERVER, "iSS" },
|
||||
{ TAG_ROOTPATH, "aRP" },
|
||||
{ TAG_EXTPATH, "aEP" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static void
|
||||
rfc1048_print(register const u_char *bp, register int length)
|
||||
{
|
||||
register u_char tag;
|
||||
register const u_char *ep;
|
||||
register u_int len, size;
|
||||
register const char *cp;
|
||||
register char c;
|
||||
int first;
|
||||
u_int32 ul;
|
||||
u_short us;
|
||||
|
||||
printf(" vend-rfc1048");
|
||||
|
||||
/* Setup end pointer */
|
||||
ep = bp + length;
|
||||
|
||||
/* Step over magic cookie */
|
||||
bp += sizeof(int32);
|
||||
|
||||
/* Loop while we there is a tag left in the buffer */
|
||||
while (bp + 1 < ep) {
|
||||
tag = *bp++;
|
||||
if (tag == TAG_PAD)
|
||||
continue;
|
||||
if (tag == TAG_END)
|
||||
return;
|
||||
cp = tok2str(tag2str, "?T%d", tag);
|
||||
c = *cp++;
|
||||
printf(" %s:", cp);
|
||||
|
||||
/* Get the length; check for truncation */
|
||||
if (bp + 1 >= ep) {
|
||||
fputs(tstr, stdout);
|
||||
return;
|
||||
}
|
||||
len = *bp++;
|
||||
if (bp + len >= ep) {
|
||||
fputs(tstr, stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Print data */
|
||||
size = len;
|
||||
if (c == '?') {
|
||||
/* Base default formats for unknown tags on data size */
|
||||
if (size & 1)
|
||||
c = 'b';
|
||||
else if (size & 2)
|
||||
c = 's';
|
||||
else
|
||||
c = 'l';
|
||||
}
|
||||
first = 1;
|
||||
switch (c) {
|
||||
|
||||
case 'a':
|
||||
/* ascii strings */
|
||||
(void)fn_printn(bp, size, NULL);
|
||||
bp += size;
|
||||
size = 0;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
case 'l':
|
||||
/* ip addresses/32-bit words */
|
||||
while (size >= sizeof(ul)) {
|
||||
if (!first)
|
||||
putchar(',');
|
||||
bcopy((char *)bp, (char *)&ul, sizeof(ul));
|
||||
if (c == 'i')
|
||||
printf("%s", ipaddr_string(&ul));
|
||||
else
|
||||
printf("%lu", ul);
|
||||
bp += sizeof(ul);
|
||||
size -= sizeof(ul);
|
||||
first = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 's':
|
||||
/* shorts */
|
||||
while (size >= sizeof(us)) {
|
||||
if (!first)
|
||||
putchar(',');
|
||||
bcopy((char *)bp, (char *)&us, sizeof(us));
|
||||
printf("%d", us);
|
||||
bp += sizeof(us);
|
||||
size -= sizeof(us);
|
||||
first = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
default:
|
||||
/* Bytes */
|
||||
while (size > 0) {
|
||||
if (!first)
|
||||
putchar('.');
|
||||
printf("%d", *bp);
|
||||
++bp;
|
||||
--size;
|
||||
first = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* Data left over? */
|
||||
if (size)
|
||||
printf("[len %d]", len);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
cmu_print(register const u_char *bp, register int length)
|
||||
{
|
||||
register const struct cmu_vend *cmu;
|
||||
register const u_char *ep;
|
||||
char *fmt = " %s:%s";
|
||||
|
||||
#define TCHECK(var, l) if ((u_char *)&(var) > ep - l) goto trunc
|
||||
#define PRINTCMUADDR(m, s) { TCHECK(cmu->m, sizeof(cmu->m)); \
|
||||
if (cmu->m.s_addr != 0) \
|
||||
printf(fmt, s, ipaddr_string(&cmu->m.s_addr)); }
|
||||
|
||||
/* Setup end pointer */
|
||||
ep = bp + length;
|
||||
|
||||
printf(" vend-cmu");
|
||||
cmu = (struct cmu_vend *)bp;
|
||||
|
||||
/* Only print if there are unknown bits */
|
||||
TCHECK(cmu->v_flags, sizeof(cmu->v_flags));
|
||||
if ((cmu->v_flags & ~(VF_SMASK)) != 0)
|
||||
printf(" F:0x%x", cmu->v_flags);
|
||||
PRINTCMUADDR(v_dgate, "DG");
|
||||
PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
|
||||
PRINTCMUADDR(v_dns1, "NS1");
|
||||
PRINTCMUADDR(v_dns2, "NS2");
|
||||
PRINTCMUADDR(v_ins1, "IEN1");
|
||||
PRINTCMUADDR(v_ins2, "IEN2");
|
||||
PRINTCMUADDR(v_ts1, "TS1");
|
||||
PRINTCMUADDR(v_ts2, "TS2");
|
||||
return;
|
||||
|
||||
trunc:
|
||||
fputs(tstr, stdout);
|
||||
#undef TCHECK
|
||||
#undef PRINTCMUADDR
|
||||
}
|
@ -1,763 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1992, 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: print-decnet.c,v 1.15 94/06/20 19:44:38 leres Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#ifdef DECNETLIB
|
||||
#include <netdnet/dnetdb.h>
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
#include "decnet.h"
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
/* Forwards */
|
||||
static void print_decnet_ctlmsg(const union routehdr *, int);
|
||||
static void print_t_info(int);
|
||||
static void print_l1_routes(const char *, int);
|
||||
static void print_l2_routes(const char *, int);
|
||||
static void print_i_info(int);
|
||||
static void print_elist(const char *, int);
|
||||
static void print_nsp(const u_char *, int);
|
||||
static void print_reason(int);
|
||||
#ifdef PRINT_NSPDATA
|
||||
static void pdata(u_char *, int);
|
||||
#endif
|
||||
|
||||
#ifdef DECNETLIB
|
||||
extern char *dnet_htoa(struct dn_naddr *);
|
||||
#endif
|
||||
|
||||
void
|
||||
decnet_print(register const u_char *ap, register int length,
|
||||
register int caplen)
|
||||
{
|
||||
static union routehdr rhcopy;
|
||||
register union routehdr *rhp = &rhcopy;
|
||||
register int mflags;
|
||||
int dst, src, hops;
|
||||
int rhlen;
|
||||
const u_char *nspp;
|
||||
int nsplen;
|
||||
int pktlen;
|
||||
|
||||
if (length < sizeof(struct shorthdr)) {
|
||||
(void)printf("[|decnet]");
|
||||
return;
|
||||
}
|
||||
|
||||
pktlen = EXTRACT_16BITS(ap);
|
||||
|
||||
rhlen = min(length, caplen);
|
||||
rhlen = min(rhlen, sizeof(*rhp));
|
||||
bcopy(&(ap[sizeof(short)]), rhp, rhlen);
|
||||
|
||||
mflags = EXTRACT_8BITS(rhp->rh_short.sh_flags);
|
||||
|
||||
if (mflags & RMF_PAD) {
|
||||
/* pad bytes of some sort in front of message */
|
||||
int padlen = mflags & RMF_PADMASK;
|
||||
if (vflag)
|
||||
(void) printf("[pad:%d] ", padlen);
|
||||
ap += padlen;
|
||||
length -= padlen;
|
||||
caplen -= padlen;
|
||||
rhlen = min(length, caplen);
|
||||
rhlen = min(rhlen, sizeof(*rhp));
|
||||
bcopy(&(ap[sizeof(short)]), rhp, rhlen);
|
||||
mflags = EXTRACT_8BITS(rhp->rh_short.sh_flags);
|
||||
}
|
||||
|
||||
if (mflags & RMF_FVER) {
|
||||
(void) printf("future-version-decnet");
|
||||
default_print(ap, length);
|
||||
return;
|
||||
}
|
||||
|
||||
/* is it a control message? */
|
||||
if (mflags & RMF_CTLMSG) {
|
||||
print_decnet_ctlmsg(rhp, min(length, caplen));
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mflags & RMF_MASK) {
|
||||
case RMF_LONG:
|
||||
dst = EXTRACT_16BITS(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr);
|
||||
src = EXTRACT_16BITS(rhp->rh_long.lg_src.dne_remote.dne_nodeaddr);
|
||||
hops = EXTRACT_8BITS(rhp->rh_long.lg_visits);
|
||||
nspp = &(ap[sizeof(short) + sizeof(struct longhdr)]);
|
||||
nsplen = min((length - sizeof(struct longhdr)),
|
||||
(caplen - sizeof(struct longhdr)));
|
||||
break;
|
||||
case RMF_SHORT:
|
||||
dst = EXTRACT_16BITS(rhp->rh_short.sh_dst);
|
||||
src = EXTRACT_16BITS(rhp->rh_short.sh_src);
|
||||
hops = (EXTRACT_8BITS(rhp->rh_short.sh_visits) & VIS_MASK)+1;
|
||||
nspp = &(ap[sizeof(short) + sizeof(struct shorthdr)]);
|
||||
nsplen = min((length - sizeof(struct shorthdr)),
|
||||
(caplen - sizeof(struct shorthdr)));
|
||||
break;
|
||||
default:
|
||||
(void) printf("unknown message flags under mask");
|
||||
default_print((u_char *)ap, length);
|
||||
return;
|
||||
}
|
||||
|
||||
(void)printf("%s > %s %d ",
|
||||
dnaddr_string(src), dnaddr_string(dst), pktlen);
|
||||
if (vflag) {
|
||||
if (mflags & RMF_RQR)
|
||||
(void)printf("RQR ");
|
||||
if (mflags & RMF_RTS)
|
||||
(void)printf("RTS ");
|
||||
if (mflags & RMF_IE)
|
||||
(void)printf("IE ");
|
||||
(void)printf("%d hops ", hops);
|
||||
}
|
||||
|
||||
print_nsp(nspp, nsplen);
|
||||
}
|
||||
|
||||
static void
|
||||
print_decnet_ctlmsg(register const union routehdr *rhp, int length)
|
||||
{
|
||||
int mflags = EXTRACT_8BITS(rhp->rh_short.sh_flags);
|
||||
register union controlmsg *cmp = (union controlmsg *)rhp;
|
||||
int src, dst, info, blksize, eco, ueco, hello, other, vers;
|
||||
etheraddr srcea, rtea;
|
||||
int priority;
|
||||
char *rhpx = (char *)rhp;
|
||||
|
||||
switch (mflags & RMF_CTLMASK) {
|
||||
case RMF_INIT:
|
||||
(void)printf("init ");
|
||||
src = EXTRACT_16BITS(cmp->cm_init.in_src);
|
||||
info = EXTRACT_8BITS(cmp->cm_init.in_info);
|
||||
blksize = EXTRACT_16BITS(cmp->cm_init.in_blksize);
|
||||
vers = EXTRACT_8BITS(cmp->cm_init.in_vers);
|
||||
eco = EXTRACT_8BITS(cmp->cm_init.in_eco);
|
||||
ueco = EXTRACT_8BITS(cmp->cm_init.in_ueco);
|
||||
hello = EXTRACT_16BITS(cmp->cm_init.in_hello);
|
||||
print_t_info(info);
|
||||
(void)printf(
|
||||
"src %sblksize %d vers %d eco %d ueco %d hello %d",
|
||||
dnaddr_string(src), blksize, vers, eco, ueco,
|
||||
hello);
|
||||
break;
|
||||
case RMF_VER:
|
||||
(void)printf("verification ");
|
||||
src = EXTRACT_16BITS(cmp->cm_ver.ve_src);
|
||||
other = EXTRACT_8BITS(cmp->cm_ver.ve_fcnval);
|
||||
(void)printf("src %s fcnval %o", dnaddr_string(src), other);
|
||||
break;
|
||||
case RMF_TEST:
|
||||
(void)printf("test ");
|
||||
src = EXTRACT_16BITS(cmp->cm_test.te_src);
|
||||
other = EXTRACT_8BITS(cmp->cm_test.te_data);
|
||||
(void)printf("src %s data %o", dnaddr_string(src), other);
|
||||
break;
|
||||
case RMF_L1ROUT:
|
||||
(void)printf("lev-1-routing ");
|
||||
src = EXTRACT_16BITS(cmp->cm_l1rou.r1_src);
|
||||
(void)printf("src %s ", dnaddr_string(src));
|
||||
print_l1_routes(&(rhpx[sizeof(struct l1rout)]),
|
||||
length - sizeof(struct l1rout));
|
||||
break;
|
||||
case RMF_L2ROUT:
|
||||
(void)printf("lev-2-routing ");
|
||||
src = EXTRACT_16BITS(cmp->cm_l2rout.r2_src);
|
||||
(void)printf("src %s ", dnaddr_string(src));
|
||||
print_l2_routes(&(rhpx[sizeof(struct l2rout)]),
|
||||
length - sizeof(struct l2rout));
|
||||
break;
|
||||
case RMF_RHELLO:
|
||||
(void)printf("router-hello ");
|
||||
vers = EXTRACT_8BITS(cmp->cm_rhello.rh_vers);
|
||||
eco = EXTRACT_8BITS(cmp->cm_rhello.rh_eco);
|
||||
ueco = EXTRACT_8BITS(cmp->cm_rhello.rh_ueco);
|
||||
bcopy(&(cmp->cm_rhello.rh_src), &srcea, sizeof(srcea));
|
||||
src = EXTRACT_16BITS(srcea.dne_remote.dne_nodeaddr);
|
||||
info = EXTRACT_8BITS(cmp->cm_rhello.rh_info);
|
||||
blksize = EXTRACT_16BITS(cmp->cm_rhello.rh_blksize);
|
||||
priority = EXTRACT_8BITS(cmp->cm_rhello.rh_priority);
|
||||
hello = EXTRACT_16BITS(cmp->cm_rhello.rh_hello);
|
||||
print_i_info(info);
|
||||
(void)printf(
|
||||
"vers %d eco %d ueco %d src %s blksize %d pri %d hello %d",
|
||||
vers, eco, ueco, dnaddr_string(src),
|
||||
blksize, priority, hello);
|
||||
print_elist(&(rhpx[sizeof(struct rhellomsg)]),
|
||||
length - sizeof(struct rhellomsg));
|
||||
break;
|
||||
case RMF_EHELLO:
|
||||
(void)printf("endnode-hello ");
|
||||
vers = EXTRACT_8BITS(cmp->cm_ehello.eh_vers);
|
||||
eco = EXTRACT_8BITS(cmp->cm_ehello.eh_eco);
|
||||
ueco = EXTRACT_8BITS(cmp->cm_ehello.eh_ueco);
|
||||
bcopy(&(cmp->cm_ehello.eh_src), &srcea, sizeof(srcea));
|
||||
src = EXTRACT_16BITS(srcea.dne_remote.dne_nodeaddr);
|
||||
info = EXTRACT_8BITS(cmp->cm_ehello.eh_info);
|
||||
blksize = EXTRACT_16BITS(cmp->cm_ehello.eh_blksize);
|
||||
/*seed*/
|
||||
bcopy(&(cmp->cm_ehello.eh_router), &rtea, sizeof(rtea));
|
||||
dst = EXTRACT_16BITS(rtea.dne_remote.dne_nodeaddr);
|
||||
hello = EXTRACT_16BITS(cmp->cm_ehello.eh_hello);
|
||||
other = EXTRACT_8BITS(cmp->cm_ehello.eh_data);
|
||||
print_i_info(info);
|
||||
(void)printf(
|
||||
"vers %d eco %d ueco %d src %s blksize %d rtr %s hello %d data %o",
|
||||
vers, eco, ueco, dnaddr_string(src),
|
||||
blksize, dnaddr_string(dst), hello, other);
|
||||
break;
|
||||
|
||||
default:
|
||||
(void)printf("unknown control message");
|
||||
default_print((u_char *)rhp, length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_t_info(int info)
|
||||
{
|
||||
int ntype = info & 3;
|
||||
switch (ntype) {
|
||||
case 0: (void)printf("reserved-ntype? "); break;
|
||||
case TI_L2ROUT: (void)printf("l2rout "); break;
|
||||
case TI_L1ROUT: (void)printf("l1rout "); break;
|
||||
case TI_ENDNODE: (void)printf("endnode "); break;
|
||||
}
|
||||
if (info & TI_VERIF)
|
||||
(void)printf("verif ");
|
||||
if (info & TI_BLOCK)
|
||||
(void)printf("blo ");
|
||||
}
|
||||
|
||||
static void
|
||||
print_l1_routes(const char *rp, int len)
|
||||
{
|
||||
int count;
|
||||
int id;
|
||||
int info;
|
||||
|
||||
/* The last short is a checksum */
|
||||
while (len > (3 * sizeof(short))) {
|
||||
count = EXTRACT_16BITS(rp);
|
||||
if (count > 1024)
|
||||
return; /* seems to be bogus from here on */
|
||||
rp += sizeof(short);
|
||||
len -= sizeof(short);
|
||||
id = EXTRACT_16BITS(rp);
|
||||
rp += sizeof(short);
|
||||
len -= sizeof(short);
|
||||
info = EXTRACT_16BITS(rp);
|
||||
rp += sizeof(short);
|
||||
len -= sizeof(short);
|
||||
(void)printf("{ids %d-%d cost %d hops %d} ", id, id + count,
|
||||
RI_COST(info), RI_HOPS(info));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_l2_routes(const char *rp, int len)
|
||||
{
|
||||
int count;
|
||||
int area;
|
||||
int info;
|
||||
|
||||
/* The last short is a checksum */
|
||||
while (len > (3 * sizeof(short))) {
|
||||
count = EXTRACT_16BITS(rp);
|
||||
if (count > 1024)
|
||||
return; /* seems to be bogus from here on */
|
||||
rp += sizeof(short);
|
||||
len -= sizeof(short);
|
||||
area = EXTRACT_16BITS(rp);
|
||||
rp += sizeof(short);
|
||||
len -= sizeof(short);
|
||||
info = EXTRACT_16BITS(rp);
|
||||
rp += sizeof(short);
|
||||
len -= sizeof(short);
|
||||
(void)printf("{areas %d-%d cost %d hops %d} ", area, area + count,
|
||||
RI_COST(info), RI_HOPS(info));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_i_info(int info)
|
||||
{
|
||||
int ntype = info & II_TYPEMASK;
|
||||
switch (ntype) {
|
||||
case 0: (void)printf("reserved-ntype? "); break;
|
||||
case II_L2ROUT: (void)printf("l2rout "); break;
|
||||
case II_L1ROUT: (void)printf("l1rout "); break;
|
||||
case II_ENDNODE: (void)printf("endnode "); break;
|
||||
}
|
||||
if (info & II_VERIF)
|
||||
(void)printf("verif ");
|
||||
if (info & II_NOMCAST)
|
||||
(void)printf("nomcast ");
|
||||
if (info & II_BLOCK)
|
||||
(void)printf("blo ");
|
||||
}
|
||||
|
||||
static void
|
||||
print_elist(const char *elp, int len)
|
||||
{
|
||||
/* Not enough examples available for me to debug this */
|
||||
}
|
||||
|
||||
static void
|
||||
print_nsp(const u_char *nspp, int nsplen)
|
||||
{
|
||||
const struct nsphdr *nsphp = (struct nsphdr *)nspp;
|
||||
int dst, src, flags;
|
||||
|
||||
flags = EXTRACT_8BITS(nsphp->nh_flags);
|
||||
dst = EXTRACT_16BITS(nsphp->nh_dst);
|
||||
src = EXTRACT_16BITS(nsphp->nh_src);
|
||||
|
||||
switch (flags & NSP_TYPEMASK) {
|
||||
case MFT_DATA:
|
||||
switch (flags & NSP_SUBMASK) {
|
||||
case MFS_BOM:
|
||||
case MFS_MOM:
|
||||
case MFS_EOM:
|
||||
case MFS_BOM+MFS_EOM:
|
||||
printf("data %d>%d ", src, dst);
|
||||
{
|
||||
struct seghdr *shp = (struct seghdr *)nspp;
|
||||
int ack;
|
||||
#ifdef PRINT_NSPDATA
|
||||
u_char *dp;
|
||||
#endif
|
||||
int data_off = sizeof(struct minseghdr);
|
||||
|
||||
ack = EXTRACT_16BITS(shp->sh_seq[0]);
|
||||
if (ack & SGQ_ACK) { /* acknum field */
|
||||
if ((ack & SGQ_NAK) == SGQ_NAK)
|
||||
(void)printf("nak %d ", ack & SGQ_MASK);
|
||||
else
|
||||
(void)printf("ack %d ", ack & SGQ_MASK);
|
||||
ack = EXTRACT_16BITS(shp->sh_seq[1]);
|
||||
data_off += sizeof(short);
|
||||
if (ack & SGQ_OACK) { /* ackoth field */
|
||||
if ((ack & SGQ_ONAK) == SGQ_ONAK)
|
||||
(void)printf("onak %d ", ack & SGQ_MASK);
|
||||
else
|
||||
(void)printf("oack %d ", ack & SGQ_MASK);
|
||||
ack = EXTRACT_16BITS(shp->sh_seq[2]);
|
||||
data_off += sizeof(short);
|
||||
}
|
||||
}
|
||||
(void)printf("seg %d ", ack & SGQ_MASK);
|
||||
#ifdef PRINT_NSPDATA
|
||||
dp = &(nspp[data_off]);
|
||||
pdata(dp, 10);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case MFS_ILS+MFS_INT:
|
||||
printf("intr ");
|
||||
{
|
||||
struct seghdr *shp = (struct seghdr *)nspp;
|
||||
int ack;
|
||||
#ifdef PRINT_NSPDATA
|
||||
u_char *dp;
|
||||
#endif
|
||||
int data_off = sizeof(struct minseghdr);
|
||||
|
||||
ack = EXTRACT_16BITS(shp->sh_seq[0]);
|
||||
if (ack & SGQ_ACK) { /* acknum field */
|
||||
if ((ack & SGQ_NAK) == SGQ_NAK)
|
||||
(void)printf("nak %d ", ack & SGQ_MASK);
|
||||
else
|
||||
(void)printf("ack %d ", ack & SGQ_MASK);
|
||||
ack = EXTRACT_16BITS(shp->sh_seq[1]);
|
||||
data_off += sizeof(short);
|
||||
if (ack & SGQ_OACK) { /* ackdat field */
|
||||
if ((ack & SGQ_ONAK) == SGQ_ONAK)
|
||||
(void)printf("nakdat %d ", ack & SGQ_MASK);
|
||||
else
|
||||
(void)printf("ackdat %d ", ack & SGQ_MASK);
|
||||
ack = EXTRACT_16BITS(shp->sh_seq[2]);
|
||||
data_off += sizeof(short);
|
||||
}
|
||||
}
|
||||
(void)printf("seg %d ", ack & SGQ_MASK);
|
||||
#ifdef PRINT_NSPDATA
|
||||
dp = &(nspp[data_off]);
|
||||
pdata(dp, 10);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case MFS_ILS:
|
||||
(void)printf("link-service %d>%d ", src, dst);
|
||||
{
|
||||
struct seghdr *shp = (struct seghdr *)nspp;
|
||||
struct lsmsg *lsmp =
|
||||
(struct lsmsg *)&(nspp[sizeof(struct seghdr)]);
|
||||
int ack;
|
||||
int lsflags, fcval;
|
||||
|
||||
ack = EXTRACT_16BITS(shp->sh_seq[0]);
|
||||
if (ack & SGQ_ACK) { /* acknum field */
|
||||
if ((ack & SGQ_NAK) == SGQ_NAK)
|
||||
(void)printf("nak %d ", ack & SGQ_MASK);
|
||||
else
|
||||
(void)printf("ack %d ", ack & SGQ_MASK);
|
||||
ack = EXTRACT_16BITS(shp->sh_seq[1]);
|
||||
if (ack & SGQ_OACK) { /* ackdat field */
|
||||
if ((ack & SGQ_ONAK) == SGQ_ONAK)
|
||||
(void)printf("nakdat %d ", ack & SGQ_MASK);
|
||||
else
|
||||
(void)printf("ackdat %d ", ack & SGQ_MASK);
|
||||
ack = EXTRACT_16BITS(shp->sh_seq[2]);
|
||||
}
|
||||
}
|
||||
(void)printf("seg %d ", ack & SGQ_MASK);
|
||||
lsflags = EXTRACT_8BITS(lsmp->ls_lsflags);
|
||||
fcval = EXTRACT_8BITS(lsmp->ls_fcval);
|
||||
switch (lsflags & LSI_MASK) {
|
||||
case LSI_DATA:
|
||||
(void)printf("dat seg count %d ", fcval);
|
||||
switch (lsflags & LSM_MASK) {
|
||||
case LSM_NOCHANGE:
|
||||
break;
|
||||
case LSM_DONOTSEND:
|
||||
(void)printf("donotsend-data ");
|
||||
break;
|
||||
case LSM_SEND:
|
||||
(void)printf("send-data ");
|
||||
break;
|
||||
default:
|
||||
(void)printf("reserved-fcmod? %x", lsflags);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case LSI_INTR:
|
||||
(void)printf("intr req count %d ", fcval);
|
||||
break;
|
||||
default:
|
||||
(void)printf("reserved-fcval-int? %x", lsflags);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
(void)printf("reserved-subtype? %x %d > %d", flags, src, dst);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case MFT_ACK:
|
||||
switch (flags & NSP_SUBMASK) {
|
||||
case MFS_DACK:
|
||||
(void)printf("data-ack %d>%d ", src, dst);
|
||||
{
|
||||
struct ackmsg *amp = (struct ackmsg *)nspp;
|
||||
int ack;
|
||||
|
||||
ack = EXTRACT_16BITS(amp->ak_acknum[0]);
|
||||
if (ack & SGQ_ACK) { /* acknum field */
|
||||
if ((ack & SGQ_NAK) == SGQ_NAK)
|
||||
(void)printf("nak %d ", ack & SGQ_MASK);
|
||||
else
|
||||
(void)printf("ack %d ", ack & SGQ_MASK);
|
||||
ack = EXTRACT_16BITS(amp->ak_acknum[1]);
|
||||
if (ack & SGQ_OACK) { /* ackoth field */
|
||||
if ((ack & SGQ_ONAK) == SGQ_ONAK)
|
||||
(void)printf("onak %d ", ack & SGQ_MASK);
|
||||
else
|
||||
(void)printf("oack %d ", ack & SGQ_MASK);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MFS_IACK:
|
||||
(void)printf("ils-ack %d>%d ", src, dst);
|
||||
{
|
||||
struct ackmsg *amp = (struct ackmsg *)nspp;
|
||||
int ack;
|
||||
|
||||
ack = EXTRACT_16BITS(amp->ak_acknum[0]);
|
||||
if (ack & SGQ_ACK) { /* acknum field */
|
||||
if ((ack & SGQ_NAK) == SGQ_NAK)
|
||||
(void)printf("nak %d ", ack & SGQ_MASK);
|
||||
else
|
||||
(void)printf("ack %d ", ack & SGQ_MASK);
|
||||
ack = EXTRACT_16BITS(amp->ak_acknum[1]);
|
||||
if (ack & SGQ_OACK) { /* ackdat field */
|
||||
if ((ack & SGQ_ONAK) == SGQ_ONAK)
|
||||
(void)printf("nakdat %d ", ack & SGQ_MASK);
|
||||
else
|
||||
(void)printf("ackdat %d ", ack & SGQ_MASK);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MFS_CACK:
|
||||
(void)printf("conn-ack %d", dst);
|
||||
break;
|
||||
default:
|
||||
(void)printf("reserved-acktype? %x %d > %d", flags, src, dst);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case MFT_CTL:
|
||||
switch (flags & NSP_SUBMASK) {
|
||||
case MFS_CI:
|
||||
case MFS_RCI:
|
||||
if ((flags & NSP_SUBMASK) == MFS_CI)
|
||||
(void)printf("conn-initiate ");
|
||||
else
|
||||
(void)printf("retrans-conn-initiate ");
|
||||
(void)printf("%d>%d ", src, dst);
|
||||
{
|
||||
struct cimsg *cimp = (struct cimsg *)nspp;
|
||||
int services, info, segsize;
|
||||
#ifdef PRINT_NSPDATA
|
||||
u_char *dp;
|
||||
#endif
|
||||
|
||||
services = EXTRACT_8BITS(cimp->ci_services);
|
||||
info = EXTRACT_8BITS(cimp->ci_info);
|
||||
segsize = EXTRACT_16BITS(cimp->ci_segsize);
|
||||
|
||||
switch (services & COS_MASK) {
|
||||
case COS_NONE:
|
||||
break;
|
||||
case COS_SEGMENT:
|
||||
(void)printf("seg ");
|
||||
break;
|
||||
case COS_MESSAGE:
|
||||
(void)printf("msg ");
|
||||
break;
|
||||
case COS_CRYPTSER:
|
||||
(void)printf("crypt ");
|
||||
break;
|
||||
}
|
||||
switch (info & COI_MASK) {
|
||||
case COI_32:
|
||||
(void)printf("ver 3.2 ");
|
||||
break;
|
||||
case COI_31:
|
||||
(void)printf("ver 3.1 ");
|
||||
break;
|
||||
case COI_40:
|
||||
(void)printf("ver 4.0 ");
|
||||
break;
|
||||
case COI_41:
|
||||
(void)printf("ver 4.1 ");
|
||||
break;
|
||||
}
|
||||
(void)printf("segsize %d ", segsize);
|
||||
#ifdef PRINT_NSPDATA
|
||||
dp = &(nspp[sizeof(struct cimsg)]);
|
||||
pdata(dp, nsplen - sizeof(struct cimsg));
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case MFS_CC:
|
||||
(void)printf("conn-confirm %d>%d ", src, dst);
|
||||
{
|
||||
struct ccmsg *ccmp = (struct ccmsg *)nspp;
|
||||
int services, info, segsize, optlen;
|
||||
#ifdef PRINT_NSPDATA
|
||||
u_char *dp;
|
||||
#endif
|
||||
|
||||
services = EXTRACT_8BITS(ccmp->cc_services);
|
||||
info = EXTRACT_8BITS(ccmp->cc_info);
|
||||
segsize = EXTRACT_16BITS(ccmp->cc_segsize);
|
||||
optlen = EXTRACT_8BITS(ccmp->cc_optlen);
|
||||
|
||||
switch (services & COS_MASK) {
|
||||
case COS_NONE:
|
||||
break;
|
||||
case COS_SEGMENT:
|
||||
(void)printf("seg ");
|
||||
break;
|
||||
case COS_MESSAGE:
|
||||
(void)printf("msg ");
|
||||
break;
|
||||
case COS_CRYPTSER:
|
||||
(void)printf("crypt ");
|
||||
break;
|
||||
}
|
||||
switch (info & COI_MASK) {
|
||||
case COI_32:
|
||||
(void)printf("ver 3.2 ");
|
||||
break;
|
||||
case COI_31:
|
||||
(void)printf("ver 3.1 ");
|
||||
break;
|
||||
case COI_40:
|
||||
(void)printf("ver 4.0 ");
|
||||
break;
|
||||
case COI_41:
|
||||
(void)printf("ver 4.1 ");
|
||||
break;
|
||||
}
|
||||
(void)printf("segsize %d ", segsize);
|
||||
if (optlen) {
|
||||
(void)printf("optlen %d ", optlen);
|
||||
#ifdef PRINT_NSPDATA
|
||||
optlen = min(optlen, nsplen - sizeof(struct ccmsg));
|
||||
dp = &(nspp[sizeof(struct ccmsg)]);
|
||||
pdata(dp, optlen);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MFS_DI:
|
||||
(void)printf("disconn-initiate %d>%d ", src, dst);
|
||||
{
|
||||
struct dimsg *dimp = (struct dimsg *)nspp;
|
||||
int reason, optlen;
|
||||
#ifdef PRINT_NSPDATA
|
||||
u_char *dp;
|
||||
#endif
|
||||
|
||||
reason = EXTRACT_16BITS(dimp->di_reason);
|
||||
optlen = EXTRACT_8BITS(dimp->di_optlen);
|
||||
|
||||
print_reason(reason);
|
||||
if (optlen) {
|
||||
(void)printf("optlen %d ", optlen);
|
||||
#ifdef PRINT_NSPDATA
|
||||
optlen = min(optlen, nsplen - sizeof(struct dimsg));
|
||||
dp = &(nspp[sizeof(struct dimsg)]);
|
||||
pdata(dp, optlen);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MFS_DC:
|
||||
(void)printf("disconn-confirm %d>%d ", src, dst);
|
||||
{
|
||||
struct dcmsg *dcmp = (struct dcmsg *)nspp;
|
||||
int reason;
|
||||
|
||||
reason = EXTRACT_16BITS(dcmp->dc_reason);
|
||||
|
||||
print_reason(reason);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
(void)printf("reserved-ctltype? %x %d > %d", flags, src, dst);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
(void)printf("reserved-type? %x %d > %d", flags, src, dst);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct token reason2str[] = {
|
||||
{ UC_OBJREJECT, "object rejected connect" },
|
||||
{ UC_RESOURCES, "insufficient resources" },
|
||||
{ UC_NOSUCHNODE, "unrecognized node name" },
|
||||
{ DI_SHUT, "node is shutting down" },
|
||||
{ UC_NOSUCHOBJ, "unrecognized object" },
|
||||
{ UC_INVOBJFORMAT, "invalid object name format" },
|
||||
{ UC_OBJTOOBUSY, "object too busy" },
|
||||
{ DI_PROTOCOL, "protocol error discovered" },
|
||||
{ DI_TPA, "third party abort" },
|
||||
{ UC_USERABORT, "user abort" },
|
||||
{ UC_INVNODEFORMAT, "invalid node name format" },
|
||||
{ UC_LOCALSHUT, "local node shutting down" },
|
||||
{ DI_LOCALRESRC, "insufficient local resources" },
|
||||
{ DI_REMUSERRESRC, "insufficient remote user resources" },
|
||||
{ UC_ACCESSREJECT, "invalid access control information" },
|
||||
{ DI_BADACCNT, "bad ACCOUNT information" },
|
||||
{ UC_NORESPONSE, "no response from object" },
|
||||
{ UC_UNREACHABLE, "node unreachable" },
|
||||
{ DC_NOLINK, "no link terminate" },
|
||||
{ DC_COMPLETE, "disconnect complete" },
|
||||
{ DI_BADIMAGE, "bad image data in connect" },
|
||||
{ DI_SERVMISMATCH, "cryptographic service mismatch" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static void
|
||||
print_reason(register int reason)
|
||||
{
|
||||
printf("%s ", tok2str(reason2str, "reason-%d", reason));
|
||||
}
|
||||
|
||||
char *
|
||||
dnnum_string(u_short dnaddr)
|
||||
{
|
||||
char *str;
|
||||
int area = (dnaddr & AREAMASK) >> AREASHIFT;
|
||||
int node = dnaddr & NODEMASK;
|
||||
|
||||
str = (char *)malloc(sizeof("00.0000"));
|
||||
sprintf(str, "%d.%d", area, node);
|
||||
return(str);
|
||||
}
|
||||
|
||||
char *
|
||||
dnname_string(u_short dnaddr)
|
||||
{
|
||||
#ifdef DECNETLIB
|
||||
struct dn_naddr dna;
|
||||
|
||||
dna.a_len = sizeof(short);
|
||||
bcopy((char *)&dnaddr, dna.a_addr, sizeof(short));
|
||||
return (savestr(dnet_htoa(&dna)));
|
||||
#else
|
||||
return(dnnum_string(dnaddr)); /* punt */
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef PRINT_NSPDATA
|
||||
static void
|
||||
pdata(u_char *dp, int maxlen)
|
||||
{
|
||||
char c;
|
||||
int x = maxlen;
|
||||
|
||||
while (x-- > 0) {
|
||||
c = *dp++;
|
||||
if (isprint(c))
|
||||
putchar(c);
|
||||
else
|
||||
printf("\\%o", c & 0xFF);
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,276 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: print-domain.c,v 1.23 94/06/14 20:17:38 leres Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
|
||||
#undef NOERROR /* Solaris sucks */
|
||||
#include <arpa/nameser.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
static char *ns_ops[] = {
|
||||
"", " inv_q", " stat", " op3", " op4", " op5", " op6", " op7",
|
||||
" op8", " updataA", " updateD", " updateDA",
|
||||
" updateM", " updateMA", " zoneInit", " zoneRef",
|
||||
};
|
||||
|
||||
static char *ns_resp[] = {
|
||||
"", " FormErr", " ServFail", " NXDomain",
|
||||
" NotImp", " Refused", " Resp6", " Resp7",
|
||||
" Resp8", " Resp9", " Resp10", " Resp11",
|
||||
" Resp12", " Resp13", " Resp14", " NoChange",
|
||||
};
|
||||
|
||||
/* skip over a domain name */
|
||||
static const u_char *
|
||||
ns_nskip(register const u_char *cp)
|
||||
{
|
||||
register u_char i;
|
||||
|
||||
if (((i = *cp++) & 0xc0) == 0xc0)
|
||||
return (cp + 1);
|
||||
while (i) {
|
||||
cp += i;
|
||||
i = *cp++;
|
||||
}
|
||||
return (cp);
|
||||
}
|
||||
|
||||
/* print a domain name */
|
||||
static void
|
||||
ns_nprint(register const u_char *cp, register const u_char *bp,
|
||||
register const u_char *ep)
|
||||
{
|
||||
register u_int i;
|
||||
|
||||
putchar(' ');
|
||||
if ((i = *cp++) != 0)
|
||||
while (i && cp < ep) {
|
||||
if ((i & 0xc0) == 0xc0) {
|
||||
cp = bp + (((i << 8) | *cp) & 0x3fff);
|
||||
i = *cp++;
|
||||
continue;
|
||||
}
|
||||
do {
|
||||
putchar(*cp++);
|
||||
} while (--i);
|
||||
putchar('.');
|
||||
i = *cp++;
|
||||
}
|
||||
else
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
static struct token type2str[] = {
|
||||
{ T_A, "A" },
|
||||
{ T_NS, "NS" },
|
||||
{ T_MD, "MD" },
|
||||
{ T_MF, "MF" },
|
||||
{ T_CNAME, "CNAME" },
|
||||
{ T_SOA, "SOA" },
|
||||
{ T_MB, "MB" },
|
||||
{ T_MG, "MG" },
|
||||
{ T_MR, "MR" },
|
||||
{ T_NULL, "NULL" },
|
||||
{ T_WKS, "WKS" },
|
||||
{ T_PTR, "PTR" },
|
||||
{ T_HINFO, "HINFO" },
|
||||
{ T_MINFO, "MINFO" },
|
||||
{ T_MX, "MX" },
|
||||
{ T_UINFO, "UINFO" },
|
||||
{ T_UID, "UID" },
|
||||
{ T_GID, "GID" },
|
||||
#ifdef T_UNSPEC
|
||||
{ T_UNSPEC, "UNSPEC" },
|
||||
#endif
|
||||
{ T_AXFR, "AXFR" },
|
||||
{ T_MAILB, "MAILB" },
|
||||
{ T_MAILA, "MAILA" },
|
||||
{ T_ANY, "ANY" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* print a query */
|
||||
static void
|
||||
ns_qprint(register const u_char *cp, register const u_char *bp,
|
||||
register const u_char *ep)
|
||||
{
|
||||
const u_char *np = cp;
|
||||
register u_int i;
|
||||
|
||||
cp = ns_nskip(cp);
|
||||
|
||||
if (cp + 4 > ep)
|
||||
return;
|
||||
|
||||
/* print the qtype and qclass (if it's not IN) */
|
||||
i = *cp++ << 8;
|
||||
i |= *cp++;
|
||||
printf(" %s", tok2str(type2str, "Type%d", i));
|
||||
i = *cp++ << 8;
|
||||
if ((i |= *cp++) != C_IN)
|
||||
if (i == C_ANY)
|
||||
printf("(c_any)");
|
||||
else
|
||||
printf("(Class %d)", i);
|
||||
|
||||
putchar('?');
|
||||
ns_nprint(np, bp, ep);
|
||||
}
|
||||
|
||||
|
||||
/* print a reply */
|
||||
static void
|
||||
ns_rprint(register const u_char *cp, register const u_char *bp,
|
||||
register const u_char *ep)
|
||||
{
|
||||
register u_int i;
|
||||
u_short typ;
|
||||
|
||||
cp = ns_nskip(cp);
|
||||
|
||||
if (cp + 10 > ep)
|
||||
return;
|
||||
|
||||
/* print the type/qtype and class (if it's not IN) */
|
||||
typ = *cp++ << 8;
|
||||
typ |= *cp++;
|
||||
i = *cp++ << 8;
|
||||
if ((i |= *cp++) != C_IN)
|
||||
if (i == C_ANY)
|
||||
printf("(c_any)");
|
||||
else
|
||||
printf("(Class %d)", i);
|
||||
|
||||
/* ignore ttl & len */
|
||||
cp += 6;
|
||||
printf(" %s", tok2str(type2str, "Type%d", typ));
|
||||
switch (typ) {
|
||||
|
||||
case T_A:
|
||||
printf(" %s", ipaddr_string(cp));
|
||||
break;
|
||||
|
||||
case T_NS:
|
||||
case T_CNAME:
|
||||
case T_PTR:
|
||||
ns_nprint(cp, bp, ep);
|
||||
break;
|
||||
|
||||
case T_MX:
|
||||
ns_nprint(cp+2, bp, ep);
|
||||
#ifndef TCPDUMP_ALIGN
|
||||
printf(" %d", *(short *)cp);
|
||||
#else
|
||||
{
|
||||
u_short x = *cp | cp[1] << 8;
|
||||
printf(" %d", ntohs(x));
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ns_print(register const u_char *bp, int length)
|
||||
{
|
||||
register const HEADER *np;
|
||||
int qdcount, ancount, nscount, arcount;
|
||||
const u_char *ep = snapend;
|
||||
|
||||
np = (const HEADER *)bp;
|
||||
/* get the byte-order right */
|
||||
qdcount = ntohs(np->qdcount);
|
||||
ancount = ntohs(np->ancount);
|
||||
nscount = ntohs(np->nscount);
|
||||
arcount = ntohs(np->arcount);
|
||||
|
||||
if (np->qr) {
|
||||
/* this is a response */
|
||||
printf(" %d%s%s%s%s%s",
|
||||
ntohs(np->id),
|
||||
ns_ops[np->opcode],
|
||||
ns_resp[np->rcode],
|
||||
np->aa? "*" : "",
|
||||
np->ra? "" : "-",
|
||||
np->tc? "|" : "");
|
||||
if (qdcount != 1)
|
||||
printf(" [%dq]", qdcount);
|
||||
printf(" %d/%d/%d", ancount, nscount, arcount);
|
||||
if (ancount)
|
||||
ns_rprint(ns_nskip((const u_char *)(np + 1)) + 4,
|
||||
(const u_char *)np, ep);
|
||||
}
|
||||
else {
|
||||
/* this is a request */
|
||||
printf(" %d%s%s",
|
||||
ntohs(np->id),
|
||||
ns_ops[np->opcode],
|
||||
np->rd? "+" : "");
|
||||
|
||||
/* any weirdness? */
|
||||
if (*(((u_short *)np)+1) & htons(0x6ff))
|
||||
printf(" [b2&3=0x%x]", ntohs(*(((u_short *)np)+1)));
|
||||
|
||||
if (np->opcode == IQUERY) {
|
||||
if (qdcount)
|
||||
printf(" [%dq]", qdcount);
|
||||
if (ancount != 1)
|
||||
printf(" [%da]", ancount);
|
||||
}
|
||||
else {
|
||||
if (ancount)
|
||||
printf(" [%da]", ancount);
|
||||
if (qdcount != 1)
|
||||
printf(" [%dq]", qdcount);
|
||||
}
|
||||
if (nscount)
|
||||
printf(" [%dn]", nscount);
|
||||
if (arcount)
|
||||
printf(" [%dau]", arcount);
|
||||
|
||||
ns_qprint((const u_char *)(np + 1), (const u_char *)np, ep);
|
||||
}
|
||||
printf(" (%d)", length);
|
||||
}
|
@ -1,356 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1991, 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Lawrence Berkeley Laboratory,
|
||||
* Berkeley, CA. The name of the University may not 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* Initial contribution from Jeff Honig (jch@MITCHELL.CIT.CORNELL.EDU).
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: print-egp.c,v 1.14 94/06/20 19:44:38 leres Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
struct egp_packet {
|
||||
u_char egp_version;
|
||||
#define EGP_VERSION 2
|
||||
u_char egp_type;
|
||||
#define EGPT_ACQUIRE 3
|
||||
#define EGPT_REACH 5
|
||||
#define EGPT_POLL 2
|
||||
#define EGPT_UPDATE 1
|
||||
#define EGPT_ERROR 8
|
||||
u_char egp_code;
|
||||
#define EGPC_REQUEST 0
|
||||
#define EGPC_CONFIRM 1
|
||||
#define EGPC_REFUSE 2
|
||||
#define EGPC_CEASE 3
|
||||
#define EGPC_CEASEACK 4
|
||||
#define EGPC_HELLO 0
|
||||
#define EGPC_HEARDU 1
|
||||
u_char egp_status;
|
||||
#define EGPS_UNSPEC 0
|
||||
#define EGPS_ACTIVE 1
|
||||
#define EGPS_PASSIVE 2
|
||||
#define EGPS_NORES 3
|
||||
#define EGPS_ADMIN 4
|
||||
#define EGPS_GODOWN 5
|
||||
#define EGPS_PARAM 6
|
||||
#define EGPS_PROTO 7
|
||||
#define EGPS_INDET 0
|
||||
#define EGPS_UP 1
|
||||
#define EGPS_DOWN 2
|
||||
#define EGPS_UNSOL 0x80
|
||||
u_short egp_checksum;
|
||||
u_short egp_as;
|
||||
u_short egp_sequence;
|
||||
union {
|
||||
u_short egpu_hello;
|
||||
u_char egpu_gws[2];
|
||||
u_short egpu_reason;
|
||||
#define EGPR_UNSPEC 0
|
||||
#define EGPR_BADHEAD 1
|
||||
#define EGPR_BADDATA 2
|
||||
#define EGPR_NOREACH 3
|
||||
#define EGPR_XSPOLL 4
|
||||
#define EGPR_NORESP 5
|
||||
#define EGPR_UVERSION 6
|
||||
} egp_handg;
|
||||
#define egp_hello egp_handg.egpu_hello
|
||||
#define egp_intgw egp_handg.egpu_gws[0]
|
||||
#define egp_extgw egp_handg.egpu_gws[1]
|
||||
#define egp_reason egp_handg.egpu_reason
|
||||
union {
|
||||
u_short egpu_poll;
|
||||
u_int32 egpu_sourcenet;
|
||||
} egp_pands;
|
||||
#define egp_poll egp_pands.egpu_poll
|
||||
#define egp_sourcenet egp_pands.egpu_sourcenet
|
||||
};
|
||||
|
||||
char *egp_acquire_codes[] = {
|
||||
"request",
|
||||
"confirm",
|
||||
"refuse",
|
||||
"cease",
|
||||
"cease_ack"
|
||||
};
|
||||
|
||||
char *egp_acquire_status[] = {
|
||||
"unspecified",
|
||||
"active_mode",
|
||||
"passive_mode",
|
||||
"insufficient_resources",
|
||||
"administratively_prohibited",
|
||||
"going_down",
|
||||
"parameter_violation",
|
||||
"protocol_violation"
|
||||
};
|
||||
|
||||
char *egp_reach_codes[] = {
|
||||
"hello",
|
||||
"i-h-u"
|
||||
};
|
||||
|
||||
char *egp_status_updown[] = {
|
||||
"indeterminate",
|
||||
"up",
|
||||
"down"
|
||||
};
|
||||
|
||||
char *egp_reasons[] = {
|
||||
"unspecified",
|
||||
"bad_EGP_header_format",
|
||||
"bad_EGP_data_field_format",
|
||||
"reachability_info_unavailable",
|
||||
"excessive_polling_rate",
|
||||
"no_response",
|
||||
"unsupported_version"
|
||||
};
|
||||
|
||||
static void
|
||||
egpnrprint(register const struct egp_packet *egp, register int length)
|
||||
{
|
||||
register const u_char *cp, *ep;
|
||||
#define TCHECK(n) if (cp > ep - n) goto trunc
|
||||
register u_int32 addr;
|
||||
register u_int32 net;
|
||||
register int netlen;
|
||||
int gateways, distances, networks;
|
||||
int t_gateways;
|
||||
char *comma;
|
||||
|
||||
addr = egp->egp_sourcenet;
|
||||
if (IN_CLASSA(addr)) {
|
||||
net = addr & IN_CLASSA_NET;
|
||||
netlen = 1;
|
||||
} else if (IN_CLASSB(addr)) {
|
||||
net = addr & IN_CLASSB_NET;
|
||||
netlen = 2;
|
||||
} else if (IN_CLASSC(addr)) {
|
||||
net = addr & IN_CLASSC_NET;
|
||||
netlen = 3;
|
||||
} else {
|
||||
net = 0;
|
||||
netlen = 0;
|
||||
}
|
||||
cp = (u_char *)(egp + 1);
|
||||
ep = snapend;
|
||||
|
||||
t_gateways = egp->egp_intgw + egp->egp_extgw;
|
||||
for (gateways = 0; gateways < t_gateways; ++gateways) {
|
||||
/* Pickup host part of gateway address */
|
||||
addr = 0;
|
||||
TCHECK(4 - netlen);
|
||||
switch (netlen) {
|
||||
|
||||
case 1:
|
||||
addr = *cp++;
|
||||
/* fall through */
|
||||
case 2:
|
||||
addr = (addr << 8) | *cp++;
|
||||
/* fall through */
|
||||
case 3:
|
||||
addr = (addr << 8) | *cp++;
|
||||
}
|
||||
addr |= net;
|
||||
TCHECK(1);
|
||||
distances = *cp++;
|
||||
printf(" %s %s ",
|
||||
gateways < egp->egp_intgw ? "int" : "ext",
|
||||
intoa(addr));
|
||||
|
||||
comma = "";
|
||||
putchar('(');
|
||||
while (--distances >= 0) {
|
||||
TCHECK(2);
|
||||
printf("%sd%d:", comma, (int)*cp++);
|
||||
comma = ", ";
|
||||
networks = *cp++;
|
||||
while (--networks >= 0) {
|
||||
/* Pickup network number */
|
||||
TCHECK(1);
|
||||
addr = (u_int32)*cp++ << 24;
|
||||
if (IN_CLASSB(addr)) {
|
||||
TCHECK(1);
|
||||
addr |= (u_int32)*cp++ << 16;
|
||||
} else if (!IN_CLASSA(addr)) {
|
||||
TCHECK(2);
|
||||
addr |= (u_int32)*cp++ << 16;
|
||||
addr |= (u_int32)*cp++ << 8;
|
||||
}
|
||||
printf(" %s", intoa(addr));
|
||||
}
|
||||
}
|
||||
putchar(')');
|
||||
}
|
||||
return;
|
||||
trunc:
|
||||
fputs("[|]", stdout);
|
||||
}
|
||||
|
||||
void
|
||||
egp_print(register const u_char *bp, register int length,
|
||||
register const u_char *bp2)
|
||||
{
|
||||
register const struct egp_packet *egp;
|
||||
register const struct ip *ip;
|
||||
register int status;
|
||||
register int code;
|
||||
register int type;
|
||||
|
||||
egp = (struct egp_packet *)bp;
|
||||
ip = (struct ip *)bp2;
|
||||
(void)printf("%s > %s: egp: ",
|
||||
ipaddr_string(&ip->ip_src),
|
||||
ipaddr_string(&ip->ip_dst));
|
||||
|
||||
if (egp->egp_version != EGP_VERSION) {
|
||||
printf("[version %d]", egp->egp_version);
|
||||
return;
|
||||
}
|
||||
printf("as:%d seq:%d", ntohs(egp->egp_as), ntohs(egp->egp_sequence));
|
||||
|
||||
type = egp->egp_type;
|
||||
code = egp->egp_code;
|
||||
status = egp->egp_status;
|
||||
|
||||
switch (type) {
|
||||
case EGPT_ACQUIRE:
|
||||
printf(" acquire");
|
||||
switch (code) {
|
||||
case EGPC_REQUEST:
|
||||
case EGPC_CONFIRM:
|
||||
printf(" %s", egp_acquire_codes[code]);
|
||||
switch (status) {
|
||||
case EGPS_UNSPEC:
|
||||
case EGPS_ACTIVE:
|
||||
case EGPS_PASSIVE:
|
||||
printf(" %s", egp_acquire_status[status]);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf(" [status %d]", status);
|
||||
break;
|
||||
}
|
||||
printf(" hello:%d poll:%d",
|
||||
ntohs(egp->egp_hello),
|
||||
ntohs(egp->egp_poll));
|
||||
break;
|
||||
|
||||
case EGPC_REFUSE:
|
||||
case EGPC_CEASE:
|
||||
case EGPC_CEASEACK:
|
||||
printf(" %s", egp_acquire_codes[code]);
|
||||
switch (status ) {
|
||||
case EGPS_UNSPEC:
|
||||
case EGPS_NORES:
|
||||
case EGPS_ADMIN:
|
||||
case EGPS_GODOWN:
|
||||
case EGPS_PARAM:
|
||||
case EGPS_PROTO:
|
||||
printf(" %s", egp_acquire_status[status]);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("[status %d]", status);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("[code %d]", code);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case EGPT_REACH:
|
||||
switch (code) {
|
||||
|
||||
case EGPC_HELLO:
|
||||
case EGPC_HEARDU:
|
||||
printf(" %s", egp_reach_codes[code]);
|
||||
if (status <= EGPS_DOWN)
|
||||
printf(" state:%s", egp_status_updown[status]);
|
||||
else
|
||||
printf(" [status %d]", status);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("[reach code %d]", code);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case EGPT_POLL:
|
||||
printf(" poll");
|
||||
if (egp->egp_status <= EGPS_DOWN)
|
||||
printf(" state:%s", egp_status_updown[status]);
|
||||
else
|
||||
printf(" [status %d]", status);
|
||||
printf(" net:%s", intoa(egp->egp_sourcenet));
|
||||
break;
|
||||
|
||||
case EGPT_UPDATE:
|
||||
printf(" update");
|
||||
if (status & EGPS_UNSOL) {
|
||||
status &= ~EGPS_UNSOL;
|
||||
printf(" unsolicited");
|
||||
}
|
||||
if (status <= EGPS_DOWN)
|
||||
printf(" state:%s", egp_status_updown[status]);
|
||||
else
|
||||
printf(" [status %d]", status);
|
||||
printf(" %s int %d ext %d",
|
||||
intoa(egp->egp_sourcenet),
|
||||
egp->egp_intgw,
|
||||
egp->egp_extgw);
|
||||
if (vflag)
|
||||
egpnrprint(egp, length);
|
||||
break;
|
||||
|
||||
case EGPT_ERROR:
|
||||
printf(" error");
|
||||
if (status <= EGPS_DOWN)
|
||||
printf(" state:%s", egp_status_updown[status]);
|
||||
else
|
||||
printf(" [status %d]", status);
|
||||
|
||||
if (ntohs(egp->egp_reason) <= EGPR_UVERSION)
|
||||
printf(" %s", egp_reasons[ntohs(egp->egp_reason)]);
|
||||
else
|
||||
printf(" [reason %d]", ntohs(egp->egp_reason));
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("[type %d]", type);
|
||||
break;
|
||||
}
|
||||
}
|
@ -1,196 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 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.
|
||||
*/
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/print-ether.c,v 1.3 1995/03/08 12:52:30 olah Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <pcap.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
#include "ethertype.h"
|
||||
|
||||
const u_char *packetp;
|
||||
const u_char *snapend;
|
||||
|
||||
static inline void
|
||||
ether_print(register const u_char *bp, int length)
|
||||
{
|
||||
register const struct ether_header *ep;
|
||||
|
||||
ep = (const struct ether_header *)bp;
|
||||
if (qflag)
|
||||
(void)printf("%s %s %d: ",
|
||||
etheraddr_string(ESRC(ep)),
|
||||
etheraddr_string(EDST(ep)),
|
||||
length);
|
||||
else
|
||||
(void)printf("%s %s %s %d: ",
|
||||
etheraddr_string(ESRC(ep)),
|
||||
etheraddr_string(EDST(ep)),
|
||||
etherproto_string(ep->ether_type),
|
||||
length);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the top level routine of the printer. 'p' is the points
|
||||
* to the ether header of the packet, 'tvp' is the timestamp,
|
||||
* 'length' is the length of the packet off the wire, and 'caplen'
|
||||
* is the number of bytes actually captured.
|
||||
*/
|
||||
void
|
||||
ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
|
||||
{
|
||||
int caplen = h->caplen;
|
||||
int length = h->len;
|
||||
struct ether_header *ep;
|
||||
u_short ether_type;
|
||||
extern u_short extracted_ethertype;
|
||||
|
||||
ts_print(&h->ts);
|
||||
|
||||
if (caplen < sizeof(struct ether_header)) {
|
||||
printf("[|ether]");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (eflag)
|
||||
ether_print(p, length);
|
||||
|
||||
/*
|
||||
* Some printers want to get back at the ethernet addresses,
|
||||
* and/or check that they're not walking off the end of the packet.
|
||||
* Rather than pass them all the way down, we set these globals.
|
||||
*/
|
||||
packetp = p;
|
||||
snapend = p + caplen;
|
||||
|
||||
length -= sizeof(struct ether_header);
|
||||
caplen -= sizeof(struct ether_header);
|
||||
ep = (struct ether_header *)p;
|
||||
p += sizeof(struct ether_header);
|
||||
|
||||
ether_type = ntohs(ep->ether_type);
|
||||
|
||||
/*
|
||||
* Is it (gag) an 802.3 encapsulation?
|
||||
*/
|
||||
extracted_ethertype = 0;
|
||||
if (ether_type < ETHERMTU) {
|
||||
/* Try to print the LLC-layer header & higher layers */
|
||||
if (llc_print(p, length, caplen, ESRC(ep), EDST(ep)) == 0) {
|
||||
/* ether_type not known, print raw packet */
|
||||
if (!eflag)
|
||||
ether_print((u_char *)ep, length);
|
||||
if (extracted_ethertype) {
|
||||
printf("(LLC %s) ",
|
||||
etherproto_string(htons(extracted_ethertype)));
|
||||
}
|
||||
if (!xflag && !qflag)
|
||||
default_print(p, caplen);
|
||||
}
|
||||
} else if (ether_encap_print(ether_type, p, length, caplen) == 0) {
|
||||
/* ether_type not known, print raw packet */
|
||||
if (!eflag)
|
||||
ether_print((u_char *)ep, length + sizeof(*ep));
|
||||
if (!xflag && !qflag)
|
||||
default_print(p, caplen);
|
||||
}
|
||||
if (xflag)
|
||||
default_print(p, caplen);
|
||||
out:
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
/*
|
||||
* Prints the packet encapsulated in an Ethernet data segment
|
||||
* (or an equivalent encapsulation), given the Ethernet type code.
|
||||
*
|
||||
* Returns non-zero if it can do so, zero if the ethertype is unknown.
|
||||
*
|
||||
* Stuffs the ether type into a global for the benefit of lower layers
|
||||
* that might want to know what it is.
|
||||
*/
|
||||
|
||||
u_short extracted_ethertype;
|
||||
|
||||
int
|
||||
ether_encap_print(u_short ethertype, const u_char *p, int length, int caplen)
|
||||
{
|
||||
extracted_ethertype = ethertype;
|
||||
|
||||
switch (ethertype) {
|
||||
|
||||
case ETHERTYPE_IP:
|
||||
ip_print(p, length);
|
||||
return (1);
|
||||
|
||||
case ETHERTYPE_ARP:
|
||||
case ETHERTYPE_REVARP:
|
||||
arp_print(p, length, caplen);
|
||||
return (1);
|
||||
|
||||
case ETHERTYPE_DN:
|
||||
decnet_print(p, length, caplen);
|
||||
return (1);
|
||||
|
||||
case ETHERTYPE_ATALK:
|
||||
if (vflag)
|
||||
fputs("et1 ", stdout);
|
||||
atalk_print(p, length);
|
||||
return (1);
|
||||
|
||||
case ETHERTYPE_AARP:
|
||||
aarp_print(p, length);
|
||||
return (1);
|
||||
|
||||
case ETHERTYPE_IPX:
|
||||
ipx_print(p, length);
|
||||
return (1);
|
||||
|
||||
case ETHERTYPE_LAT:
|
||||
case ETHERTYPE_MOPRC:
|
||||
case ETHERTYPE_MOPDL:
|
||||
/* default_print for now */
|
||||
default:
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
@ -1,351 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1991, 1992, 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#)$Header: print-fddi.c,v 1.21 94/06/10 17:01:29 mccanne Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef FDDI
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <pcap.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
#include "ethertype.h"
|
||||
|
||||
#include "fddi.h"
|
||||
|
||||
int fddipad = FDDIPAD; /* for proper alignment of header */
|
||||
|
||||
/*
|
||||
* Some FDDI interfaces use bit-swapped addresses.
|
||||
*/
|
||||
#if defined(ultrix) || defined(__alpha)
|
||||
int fddi_bitswap = 0;
|
||||
#else
|
||||
int fddi_bitswap = 1;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* FDDI support for tcpdump, by Jeffrey Mogul [DECWRL], June 1992
|
||||
*
|
||||
* Based in part on code by Van Jacobson, which bears this note:
|
||||
*
|
||||
* NOTE: This is a very preliminary hack for FDDI support.
|
||||
* There are all sorts of wired in constants & nothing (yet)
|
||||
* to print SMT packets as anything other than hex dumps.
|
||||
* Most of the necessary changes are waiting on my redoing
|
||||
* the "header" that a kernel fddi driver supplies to bpf: I
|
||||
* want it to look like one byte of 'direction' (0 or 1
|
||||
* depending on whether the packet was inbound or outbound),
|
||||
* two bytes of system/driver dependent data (anything an
|
||||
* implementor thinks would be useful to filter on and/or
|
||||
* save per-packet, then the real 21-byte FDDI header.
|
||||
* Steve McCanne & I have also talked about adding the
|
||||
* 'direction' byte to all bpf headers (e.g., in the two
|
||||
* bytes of padding on an ethernet header). It's not clear
|
||||
* we could do this in a backwards compatible way & we hate
|
||||
* the idea of an incompatible bpf change. Discussions are
|
||||
* proceeding.
|
||||
*
|
||||
* Also, to really support FDDI (and better support 802.2
|
||||
* over ethernet) we really need to re-think the rather simple
|
||||
* minded assumptions about fixed length & fixed format link
|
||||
* level headers made in gencode.c. One day...
|
||||
*
|
||||
* - vj
|
||||
*/
|
||||
|
||||
#define FDDI_HDRLEN (sizeof(struct fddi_header))
|
||||
|
||||
static u_char fddi_bit_swap[] = {
|
||||
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
|
||||
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
|
||||
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
|
||||
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
|
||||
0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
|
||||
0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
|
||||
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
|
||||
0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
|
||||
0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
|
||||
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
|
||||
0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
|
||||
0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
|
||||
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
|
||||
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
|
||||
0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
|
||||
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
|
||||
0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
|
||||
0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
|
||||
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
|
||||
0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
|
||||
0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
|
||||
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
|
||||
0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
|
||||
0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
|
||||
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
|
||||
0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
|
||||
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
|
||||
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
|
||||
0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
|
||||
0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
|
||||
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
|
||||
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
|
||||
};
|
||||
|
||||
/*
|
||||
* Print FDDI frame-control bits
|
||||
*/
|
||||
static inline void
|
||||
print_fddi_fc(u_char fc)
|
||||
{
|
||||
switch (fc) {
|
||||
|
||||
case FDDIFC_VOID: /* Void frame */
|
||||
printf("void ");
|
||||
break;
|
||||
|
||||
case FDDIFC_NRT: /* Nonrestricted token */
|
||||
printf("nrt ");
|
||||
break;
|
||||
|
||||
case FDDIFC_RT: /* Restricted token */
|
||||
printf("rt ");
|
||||
break;
|
||||
|
||||
case FDDIFC_SMT_INFO: /* SMT Info */
|
||||
printf("info ");
|
||||
break;
|
||||
|
||||
case FDDIFC_SMT_NSA: /* SMT Next station adrs */
|
||||
printf("nsa ");
|
||||
break;
|
||||
|
||||
case FDDIFC_MAC_BEACON: /* MAC Beacon frame */
|
||||
printf("beacon ");
|
||||
break;
|
||||
|
||||
case FDDIFC_MAC_CLAIM: /* MAC Claim frame */
|
||||
printf("claim ");
|
||||
break;
|
||||
|
||||
default:
|
||||
switch (fc & FDDIFC_CLFF) {
|
||||
|
||||
case FDDIFC_MAC:
|
||||
printf("mac%1x ", fc & FDDIFC_ZZZZ);
|
||||
break;
|
||||
|
||||
case FDDIFC_SMT:
|
||||
printf("smt%1x ", fc & FDDIFC_ZZZZ);
|
||||
break;
|
||||
|
||||
case FDDIFC_LLC_ASYNC:
|
||||
printf("async%1x ", fc & FDDIFC_ZZZZ);
|
||||
break;
|
||||
|
||||
case FDDIFC_LLC_SYNC:
|
||||
printf("sync%1x ", fc & FDDIFC_ZZZZ);
|
||||
break;
|
||||
|
||||
case FDDIFC_IMP_ASYNC:
|
||||
printf("imp_async%1x ", fc & FDDIFC_ZZZZ);
|
||||
break;
|
||||
|
||||
case FDDIFC_IMP_SYNC:
|
||||
printf("imp_sync%1x ", fc & FDDIFC_ZZZZ);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("%02x ", fc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Extract src, dst addresses */
|
||||
static inline void
|
||||
extract_fddi_addrs(const struct fddi_header *fddip, char *fsrc, char *fdst)
|
||||
{
|
||||
register int i;
|
||||
|
||||
if (fddi_bitswap) {
|
||||
/*
|
||||
* bit-swap the fddi addresses (isn't the IEEE standards
|
||||
* process wonderful!) then convert them to names.
|
||||
*/
|
||||
for (i = 0; i < 6; ++i)
|
||||
fdst[i] = fddi_bit_swap[fddip->fddi_dhost[i]];
|
||||
for (i = 0; i < 6; ++i)
|
||||
fsrc[i] = fddi_bit_swap[fddip->fddi_shost[i]];
|
||||
}
|
||||
else {
|
||||
bcopy(fddip->fddi_dhost, fdst, 6);
|
||||
bcopy(fddip->fddi_shost, fsrc, 6);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Print the FDDI MAC header
|
||||
*/
|
||||
static inline void
|
||||
fddi_print(register const struct fddi_header *fddip, register int length,
|
||||
register const u_char *fsrc, register const u_char *fdst)
|
||||
{
|
||||
char *srcname, *dstname;
|
||||
|
||||
srcname = etheraddr_string(fsrc);
|
||||
dstname = etheraddr_string(fdst);
|
||||
|
||||
if (vflag)
|
||||
(void) printf("%02x %s %s %d: ",
|
||||
fddip->fddi_fc,
|
||||
srcname, dstname,
|
||||
length);
|
||||
else if (qflag)
|
||||
printf("%s %s %d: ", srcname, dstname, length);
|
||||
else {
|
||||
(void) print_fddi_fc(fddip->fddi_fc);
|
||||
(void) printf("%s %s %d: ", srcname, dstname, length);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
fddi_smt_print(const u_char *p, int length)
|
||||
{
|
||||
printf("<SMT printer not yet implemented>");
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the top level routine of the printer. 'sp' is the points
|
||||
* to the FDDI header of the packet, 'tvp' is the timestamp,
|
||||
* 'length' is the length of the packet off the wire, and 'caplen'
|
||||
* is the number of bytes actually captured.
|
||||
*/
|
||||
void
|
||||
fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h,
|
||||
register const u_char *p)
|
||||
{
|
||||
int caplen = h->caplen;
|
||||
int length = h->len;
|
||||
const struct fddi_header *fddip = (struct fddi_header *)p;
|
||||
extern u_short extracted_ethertype;
|
||||
struct ether_header ehdr;
|
||||
|
||||
ts_print(&h->ts);
|
||||
|
||||
if (caplen < FDDI_HDRLEN) {
|
||||
printf("[|fddi]");
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
* Get the FDDI addresses into a canonical form
|
||||
*/
|
||||
extract_fddi_addrs(fddip, (char*)ESRC(&ehdr), (char*)EDST(&ehdr));
|
||||
/*
|
||||
* Some printers want to get back at the link level addresses,
|
||||
* and/or check that they're not walking off the end of the packet.
|
||||
* Rather than pass them all the way down, we set these globals.
|
||||
*/
|
||||
snapend = p + caplen;
|
||||
/*
|
||||
* Actually, the only printer that uses packetp is print-bootp.c,
|
||||
* and it assumes that packetp points to an Ethernet header. The
|
||||
* right thing to do is to fix print-bootp.c to know which link
|
||||
* type is in use when it excavates. XXX
|
||||
*/
|
||||
packetp = (u_char *)&ehdr;
|
||||
|
||||
if (eflag)
|
||||
fddi_print(fddip, length, ESRC(&ehdr), EDST(&ehdr));
|
||||
|
||||
/* Skip over FDDI MAC header */
|
||||
length -= FDDI_HDRLEN;
|
||||
p += FDDI_HDRLEN;
|
||||
caplen -= FDDI_HDRLEN;
|
||||
|
||||
/* Frame Control field determines interpretation of packet */
|
||||
extracted_ethertype = 0;
|
||||
if ((fddip->fddi_fc & FDDIFC_CLFF) == FDDIFC_LLC_ASYNC) {
|
||||
/* Try to print the LLC-layer header & higher layers */
|
||||
if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr))
|
||||
== 0) {
|
||||
/*
|
||||
* Some kinds of LLC packet we cannot
|
||||
* handle intelligently
|
||||
*/
|
||||
if (!eflag)
|
||||
fddi_print(fddip, length,
|
||||
ESRC(&ehdr), EDST(&ehdr));
|
||||
if (extracted_ethertype) {
|
||||
printf("(LLC %s) ",
|
||||
etherproto_string(htons(extracted_ethertype)));
|
||||
}
|
||||
if (!xflag && !qflag)
|
||||
default_print(p, caplen);
|
||||
}
|
||||
} else if ((fddip->fddi_fc & FDDIFC_CLFF) == FDDIFC_SMT)
|
||||
fddi_smt_print(p, caplen);
|
||||
else {
|
||||
/* Some kinds of FDDI packet we cannot handle intelligently */
|
||||
if (!eflag)
|
||||
fddi_print(fddip, length, ESRC(&ehdr), EDST(&ehdr));
|
||||
if (!xflag && !qflag)
|
||||
default_print(p, caplen);
|
||||
}
|
||||
if (xflag)
|
||||
default_print(p, caplen);
|
||||
out:
|
||||
putchar('\n');
|
||||
}
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
void
|
||||
fddi_if_print(u_char *pcap, struct pcap_pkthdr *h, register u_char *p)
|
||||
{
|
||||
|
||||
error("not configured for fddi");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
#endif
|
@ -1,222 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 1.2 1995/03/08 12:52:32 olah Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
void
|
||||
icmp_print(register const u_char *bp, register const u_char *bp2)
|
||||
{
|
||||
register const struct icmp *dp;
|
||||
register const struct ip *ip;
|
||||
register const char *str;
|
||||
register const struct ip *oip;
|
||||
register const struct udphdr *ouh;
|
||||
register int hlen, dport;
|
||||
register const u_char *ep;
|
||||
char buf[256];
|
||||
|
||||
#define TCHECK(var, l) if ((u_char *)&(var) > ep - l) goto trunc
|
||||
|
||||
dp = (struct icmp *)bp;
|
||||
ip = (struct ip *)bp2;
|
||||
str = buf;
|
||||
/* 'ep' points to the end of avaible data. */
|
||||
ep = snapend;
|
||||
|
||||
(void)printf("%s > %s: ",
|
||||
ipaddr_string(&ip->ip_src),
|
||||
ipaddr_string(&ip->ip_dst));
|
||||
|
||||
TCHECK(dp->icmp_code, sizeof(dp->icmp_code));
|
||||
switch (dp->icmp_type) {
|
||||
case ICMP_ECHOREPLY:
|
||||
str = "echo reply";
|
||||
break;
|
||||
case ICMP_UNREACH:
|
||||
TCHECK(dp->icmp_ip.ip_dst, sizeof(dp->icmp_ip.ip_dst));
|
||||
switch (dp->icmp_code) {
|
||||
case ICMP_UNREACH_NET:
|
||||
(void)sprintf(buf, "net %s unreachable",
|
||||
ipaddr_string(&dp->icmp_ip.ip_dst));
|
||||
break;
|
||||
case ICMP_UNREACH_HOST:
|
||||
(void)sprintf(buf, "host %s unreachable",
|
||||
ipaddr_string(&dp->icmp_ip.ip_dst));
|
||||
break;
|
||||
case ICMP_UNREACH_PROTOCOL:
|
||||
TCHECK(dp->icmp_ip.ip_p, sizeof(dp->icmp_ip.ip_p));
|
||||
(void)sprintf(buf, "%s protocol %d unreachable",
|
||||
ipaddr_string(&dp->icmp_ip.ip_dst),
|
||||
dp->icmp_ip.ip_p);
|
||||
break;
|
||||
case ICMP_UNREACH_PORT:
|
||||
TCHECK(dp->icmp_ip.ip_p, sizeof(dp->icmp_ip.ip_p));
|
||||
oip = &dp->icmp_ip;
|
||||
hlen = oip->ip_hl * 4;
|
||||
ouh = (struct udphdr *)(((u_char *)oip) + hlen);
|
||||
dport = ntohs(ouh->uh_dport);
|
||||
switch (oip->ip_p) {
|
||||
case IPPROTO_TCP:
|
||||
(void)sprintf(buf,
|
||||
"%s tcp port %s unreachable",
|
||||
ipaddr_string(&oip->ip_dst),
|
||||
tcpport_string(dport));
|
||||
break;
|
||||
case IPPROTO_UDP:
|
||||
(void)sprintf(buf,
|
||||
"%s udp port %s unreachable",
|
||||
ipaddr_string(&oip->ip_dst),
|
||||
udpport_string(dport));
|
||||
break;
|
||||
default:
|
||||
(void)sprintf(buf,
|
||||
"%s protocol %d port %d unreachable",
|
||||
ipaddr_string(&oip->ip_dst),
|
||||
oip->ip_p, dport);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ICMP_UNREACH_NEEDFRAG:
|
||||
(void)sprintf(buf, "%s unreachable - need to frag",
|
||||
ipaddr_string(&dp->icmp_ip.ip_dst));
|
||||
break;
|
||||
case ICMP_UNREACH_SRCFAIL:
|
||||
(void)sprintf(buf,
|
||||
"%s unreachable - source route failed",
|
||||
ipaddr_string(&dp->icmp_ip.ip_dst));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ICMP_SOURCEQUENCH:
|
||||
str = "source quench";
|
||||
break;
|
||||
case ICMP_REDIRECT:
|
||||
TCHECK(dp->icmp_ip.ip_dst, sizeof(dp->icmp_ip.ip_dst));
|
||||
switch (dp->icmp_code) {
|
||||
case ICMP_REDIRECT_NET:
|
||||
(void)sprintf(buf, "redirect %s to net %s",
|
||||
ipaddr_string(&dp->icmp_ip.ip_dst),
|
||||
ipaddr_string(&dp->icmp_gwaddr));
|
||||
break;
|
||||
case ICMP_REDIRECT_HOST:
|
||||
(void)sprintf(buf, "redirect %s to host %s",
|
||||
ipaddr_string(&dp->icmp_ip.ip_dst),
|
||||
ipaddr_string(&dp->icmp_gwaddr));
|
||||
break;
|
||||
case ICMP_REDIRECT_TOSNET:
|
||||
(void)sprintf(buf, "redirect-tos %s to net %s",
|
||||
ipaddr_string(&dp->icmp_ip.ip_dst),
|
||||
ipaddr_string(&dp->icmp_gwaddr));
|
||||
break;
|
||||
case ICMP_REDIRECT_TOSHOST:
|
||||
(void)sprintf(buf, "redirect-tos %s to host %s",
|
||||
ipaddr_string(&dp->icmp_ip.ip_dst),
|
||||
ipaddr_string(&dp->icmp_gwaddr));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ICMP_ECHO:
|
||||
str = "echo request";
|
||||
break;
|
||||
case ICMP_ROUTERADVERT:
|
||||
(void)sprintf(buf, "router advert, %d rtrs, lifetime %d",
|
||||
dp->icmp_num_addrs, ntohs(dp->icmp_lifetime));
|
||||
break;
|
||||
case ICMP_ROUTERSOLICIT:
|
||||
str = "router solicitation";
|
||||
break;
|
||||
case ICMP_TIMXCEED:
|
||||
TCHECK(dp->icmp_ip.ip_dst, sizeof(dp->icmp_ip.ip_dst));
|
||||
switch (dp->icmp_code) {
|
||||
case ICMP_TIMXCEED_INTRANS:
|
||||
str = "time exceeded in-transit";
|
||||
break;
|
||||
case ICMP_TIMXCEED_REASS:
|
||||
str = "ip reassembly time exceeded";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ICMP_PARAMPROB:
|
||||
if (dp->icmp_code)
|
||||
(void)sprintf(buf, "parameter problem - code %d",
|
||||
dp->icmp_code);
|
||||
else {
|
||||
TCHECK(dp->icmp_pptr, sizeof(dp->icmp_pptr));
|
||||
(void)sprintf(buf, "parameter problem - octet %d",
|
||||
dp->icmp_pptr);
|
||||
}
|
||||
break;
|
||||
case ICMP_TSTAMP:
|
||||
str = "time stamp request";
|
||||
break;
|
||||
case ICMP_TSTAMPREPLY:
|
||||
str = "time stamp reply";
|
||||
break;
|
||||
case ICMP_IREQ:
|
||||
str = "information request";
|
||||
break;
|
||||
case ICMP_IREQREPLY:
|
||||
str = "information reply";
|
||||
break;
|
||||
case ICMP_MASKREQ:
|
||||
str = "address mask request";
|
||||
break;
|
||||
case ICMP_MASKREPLY:
|
||||
TCHECK(dp->icmp_mask, sizeof(dp->icmp_mask));
|
||||
(void)sprintf(buf, "address mask is 0x%08x",
|
||||
ntohl(dp->icmp_mask));
|
||||
break;
|
||||
default:
|
||||
(void)sprintf(buf, "type-#%d", dp->icmp_type);
|
||||
break;
|
||||
}
|
||||
(void)printf("icmp: %s", str);
|
||||
return;
|
||||
trunc:
|
||||
fputs("[|icmp]", stdout);
|
||||
#undef TCHECK
|
||||
}
|
@ -1,473 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
/* From: Header: print-ip.c,v 1.28 92/05/25 14:29:02 mccanne Exp $ (LBL) */
|
||||
static char rcsid[] =
|
||||
"$Id: print-ip.c,v 1.5 1995/06/13 17:39:23 wollman Exp $";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
static void
|
||||
igmp_print(register const u_char *bp, register int len,
|
||||
register const u_char *bp2)
|
||||
{
|
||||
register const struct ip *ip;
|
||||
register const u_char *ep;
|
||||
|
||||
ip = (const struct ip *)bp2;
|
||||
ep = (const u_char *)snapend;
|
||||
(void)printf("%s > %s: ",
|
||||
ipaddr_string(&ip->ip_src),
|
||||
ipaddr_string(&ip->ip_dst));
|
||||
|
||||
if (bp + 7 > ep) {
|
||||
(void)printf("[|igmp]");
|
||||
return;
|
||||
}
|
||||
switch (bp[0]) {
|
||||
case 0x11:
|
||||
(void)printf("igmp %s query", bp[1] ? "v2" : "v1");
|
||||
if (bp[1] && bp[1] != 100)
|
||||
(void)printf(" [intvl %d]", bp[1]);
|
||||
if (*(int *)&bp[4])
|
||||
(void)printf(" [gaddr %s]", ipaddr_string(&bp[4]));
|
||||
if (len != 8)
|
||||
(void)printf(" [len %d]", len);
|
||||
break;
|
||||
case 0x12:
|
||||
case 0x16:
|
||||
(void)printf("igmp %s report %s",
|
||||
(bp[0] & 0xf) == 6 ? "v2" : "v1",
|
||||
ipaddr_string(&bp[4]));
|
||||
if (len != 8)
|
||||
(void)printf(" [len %d]", len);
|
||||
if (bp[1])
|
||||
(void)printf(" [b1=0x%x]", bp[1]);
|
||||
break;
|
||||
case 0x17:
|
||||
(void)printf("igmp leave %s", ipaddr_string(&bp[4]));
|
||||
if (len != 8)
|
||||
(void)printf(" [len %d]", len);
|
||||
if (bp[1])
|
||||
(void)printf(" [b1=0x%x]", bp[1]);
|
||||
break;
|
||||
case 0x13:
|
||||
(void)printf("igmp dvmrp");
|
||||
switch(bp[1]) {
|
||||
case 1:
|
||||
printf(" probe");
|
||||
if (len < 8)
|
||||
(void)printf(" [len %d]", len);
|
||||
if (vflag) {
|
||||
if (len > 8)
|
||||
(void)printf(" genid 0x%08x",
|
||||
ntohl(*(int *)&bp[8]));
|
||||
(void)printf(" [nf 0x%02x]", bp[5]);
|
||||
}
|
||||
if (len > 12) {
|
||||
int i;
|
||||
for (i = 12; i + 3 < len; i += 4) {
|
||||
printf("\n\t%s",
|
||||
ipaddr_string(&bp[i]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
printf(" report");
|
||||
if (vflag)
|
||||
(void)printf(" [nf 0x%02x]", bp[5]);
|
||||
if (len < 8)
|
||||
(void)printf(" [len %d]", len);
|
||||
break;
|
||||
case 3:
|
||||
case 5:
|
||||
printf(" %sneighbor query", bp[1] == 5 ? "new " : "");
|
||||
if (len < 8)
|
||||
(void)printf(" [len %d]", len);
|
||||
break;
|
||||
case 4:
|
||||
case 6:
|
||||
printf(" %sneighbor list", bp[1] == 6 ? "new " : "");
|
||||
if (len < 8)
|
||||
(void)printf(" [len %d]", len);
|
||||
break;
|
||||
case 7:
|
||||
printf(" prune %s from ", ipaddr_string(&bp[12]));
|
||||
printf(" %s timer %d", ipaddr_string(&bp[8]),
|
||||
ntohl(*(int *)&bp[16]));
|
||||
if (len != 20)
|
||||
(void)printf(" [len %d]", len);
|
||||
break;
|
||||
case 8:
|
||||
printf(" graft %s from ", ipaddr_string(&bp[12]));
|
||||
printf(" %s", ipaddr_string(&bp[8]));
|
||||
if (len != 16)
|
||||
(void)printf(" [len %d]", len);
|
||||
break;
|
||||
case 9:
|
||||
printf(" graft ack %s from ",
|
||||
ipaddr_string(&bp[12]));
|
||||
printf(" %s", ipaddr_string(&bp[8]));
|
||||
|
||||
if (len != 16)
|
||||
(void)printf(" [len %d]", len);
|
||||
break;
|
||||
default:
|
||||
printf("-%d", bp[1]);
|
||||
if (len < 8)
|
||||
(void)printf(" [len %d]", len);
|
||||
break;
|
||||
}
|
||||
|
||||
if (bp[7] != 3
|
||||
|| (bp[7] == 3 && (bp[6] > 5 || bp[6] < 4))) {
|
||||
printf(" [v%d.%d]", bp[7], bp[6]);
|
||||
}
|
||||
|
||||
break;
|
||||
case 0x14:
|
||||
printf("igmp pim %s", ipaddr_string(&bp[4]));
|
||||
if (len < 8)
|
||||
(void)printf(" [len %d]", len);
|
||||
if (bp[1])
|
||||
(void)printf(" [b1=0x%x]", bp[1]);
|
||||
break;
|
||||
case 0x1e:
|
||||
case 0x1f:
|
||||
(void)printf("igmp mtrace%s %s",
|
||||
(bp[0] == 0x1e) ? " response" : "",
|
||||
ipaddr_string(&bp[4]));
|
||||
if (len < 24)
|
||||
(void)printf(" [len %d]", len);
|
||||
else if (vflag) {
|
||||
(void)printf(" s=%s", ipaddr_string(&bp[8]));
|
||||
(void)printf(" d=%s", ipaddr_string(&bp[12]));
|
||||
(void)printf(" qid=0x%06x",
|
||||
bp[21] << 16 + bp[22] << 8 + bp[23]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
(void)printf("igmp-%d", bp[0]);
|
||||
if (bp[1])
|
||||
(void)printf(" [b1=0x%x]", bp[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* print the recorded route in an IP RR, LSRR or SSRR option.
|
||||
*/
|
||||
static void
|
||||
ip_printroute(const char *type, register const u_char *cp, int length)
|
||||
{
|
||||
int ptr = cp[2] - 1;
|
||||
int len;
|
||||
|
||||
printf(" %s{", type);
|
||||
if ((length + 1) & 3)
|
||||
printf(" [bad length %d]", length);
|
||||
if (ptr < 3 || ((ptr + 1) & 3) || ptr > length + 1)
|
||||
printf(" [bad ptr %d]", cp[2]);
|
||||
|
||||
type = "";
|
||||
for (len = 3; len < length; len += 4) {
|
||||
if (ptr == len)
|
||||
type = "#";
|
||||
#ifdef TCPDUMP_ALIGN
|
||||
{
|
||||
struct in_addr addr;
|
||||
bcopy((char *)&cp[len], (char *)&addr, sizeof(addr));
|
||||
printf("%s%s", type, ipaddr_string(&addr));
|
||||
}
|
||||
#else
|
||||
printf("%s%s", type, ipaddr_string(&cp[len]));
|
||||
#endif
|
||||
type = " ";
|
||||
}
|
||||
printf("%s}", ptr == len? "#" : "");
|
||||
}
|
||||
|
||||
/*
|
||||
* print IP options.
|
||||
*/
|
||||
static void
|
||||
ip_optprint(register const u_char *cp, int length)
|
||||
{
|
||||
int len;
|
||||
|
||||
for (; length > 0; cp += len, length -= len) {
|
||||
int tt = *cp;
|
||||
|
||||
len = (tt == IPOPT_NOP || tt == IPOPT_EOL) ? 1 : cp[1];
|
||||
if (&cp[1] >= snapend || cp + len > snapend) {
|
||||
printf("[|ip]");
|
||||
return;
|
||||
}
|
||||
switch (tt) {
|
||||
|
||||
case IPOPT_EOL:
|
||||
printf(" EOL");
|
||||
if (length > 1)
|
||||
printf("-%d", length - 1);
|
||||
return;
|
||||
|
||||
case IPOPT_NOP:
|
||||
printf(" NOP");
|
||||
break;
|
||||
|
||||
case IPOPT_TS:
|
||||
printf(" TS{%d}", len);
|
||||
break;
|
||||
|
||||
case IPOPT_SECURITY:
|
||||
printf(" SECURITY{%d}", len);
|
||||
break;
|
||||
|
||||
case IPOPT_RR:
|
||||
printf(" RR{%d}=", len);
|
||||
ip_printroute("RR", cp, len);
|
||||
break;
|
||||
|
||||
case IPOPT_SSRR:
|
||||
ip_printroute("SSRR", cp, len);
|
||||
break;
|
||||
|
||||
case IPOPT_LSRR:
|
||||
ip_printroute("LSRR", cp, len);
|
||||
break;
|
||||
|
||||
case IPOPT_RA:
|
||||
printf(" RA");
|
||||
if (len != 4)
|
||||
printf("{%d}", len);
|
||||
if (cp[2] != 0 || cp[3] != 0)
|
||||
printf("[b23=%04x]",cp[2] << 8 + cp[3]);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf(" IPOPT-%d{%d}", cp[0], len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* compute an IP header checksum.
|
||||
* don't modifiy the packet.
|
||||
*/
|
||||
static int
|
||||
in_cksum(const struct ip *ip)
|
||||
{
|
||||
register const u_short *sp = (u_short *)ip;
|
||||
register u_int32 sum = 0;
|
||||
register int count;
|
||||
|
||||
/*
|
||||
* No need for endian conversions.
|
||||
*/
|
||||
for (count = ip->ip_hl * 2; --count >= 0; )
|
||||
sum += *sp++;
|
||||
while (sum > 0xffff)
|
||||
sum = (sum & 0xffff) + (sum >> 16);
|
||||
sum = ~sum & 0xffff;
|
||||
|
||||
return (sum);
|
||||
}
|
||||
|
||||
/*
|
||||
* print an IP datagram.
|
||||
*/
|
||||
void
|
||||
ip_print(register const u_char *bp, register int length)
|
||||
{
|
||||
register const struct ip *ip;
|
||||
register int hlen;
|
||||
register int len;
|
||||
register int off;
|
||||
register const u_char *cp;
|
||||
|
||||
ip = (const struct ip *)bp;
|
||||
#ifdef TCPDUMP_ALIGN
|
||||
/*
|
||||
* The IP header is not word aligned, so copy into abuf.
|
||||
* This will never happen with BPF. It does happen raw packet
|
||||
* dumps from -r.
|
||||
*/
|
||||
if ((int)ip & (sizeof(long)-1)) {
|
||||
static u_char *abuf;
|
||||
|
||||
if (abuf == 0)
|
||||
abuf = (u_char *)malloc(snaplen);
|
||||
bcopy((char *)ip, (char *)abuf, min(length, snaplen));
|
||||
snapend += abuf - (u_char *)ip;
|
||||
packetp = abuf;
|
||||
ip = (struct ip *)abuf;
|
||||
}
|
||||
#endif
|
||||
if ((u_char *)(ip + 1) > snapend) {
|
||||
printf("[|ip]");
|
||||
return;
|
||||
}
|
||||
if (length < sizeof (struct ip)) {
|
||||
(void)printf("truncated-ip %d", length);
|
||||
return;
|
||||
}
|
||||
hlen = ip->ip_hl * 4;
|
||||
|
||||
len = ntohs(ip->ip_len);
|
||||
if (length < len)
|
||||
(void)printf("truncated-ip - %d bytes missing!",
|
||||
len - length);
|
||||
len -= hlen;
|
||||
|
||||
/*
|
||||
* If this is fragment zero, hand it to the next higher
|
||||
* level protocol.
|
||||
*/
|
||||
off = ntohs(ip->ip_off);
|
||||
if ((off & 0x1fff) == 0) {
|
||||
cp = (const u_char *)ip + hlen;
|
||||
switch (ip->ip_p) {
|
||||
|
||||
case IPPROTO_TCP:
|
||||
tcp_print(cp, len, (const u_char *)ip);
|
||||
break;
|
||||
case IPPROTO_UDP:
|
||||
udp_print(cp, len, (const u_char *)ip);
|
||||
break;
|
||||
case IPPROTO_ICMP:
|
||||
icmp_print(cp, (const u_char *)ip);
|
||||
break;
|
||||
case IPPROTO_ND:
|
||||
(void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
|
||||
ipaddr_string(&ip->ip_dst));
|
||||
(void)printf(" nd %d", len);
|
||||
break;
|
||||
case IPPROTO_EGP:
|
||||
egp_print(cp, len, (const u_char *)ip);
|
||||
break;
|
||||
#ifndef IPPROTO_OSPF
|
||||
#define IPPROTO_OSPF 89
|
||||
#endif
|
||||
case IPPROTO_OSPF:
|
||||
ospf_print(cp, len, (const u_char *)ip);
|
||||
break;
|
||||
#ifndef IPPROTO_IGMP
|
||||
#define IPPROTO_IGMP 2
|
||||
#endif
|
||||
case IPPROTO_IGMP:
|
||||
igmp_print(cp, len, (const u_char *)ip);
|
||||
break;
|
||||
#ifndef IPPROTO_ENCAP
|
||||
#define IPPROTO_ENCAP 4
|
||||
#endif
|
||||
case IPPROTO_ENCAP:
|
||||
/* ip-in-ip encapsulation */
|
||||
if (vflag)
|
||||
(void)printf("%s > %s: ",
|
||||
ipaddr_string(&ip->ip_src),
|
||||
ipaddr_string(&ip->ip_dst));
|
||||
ip_print(cp, len);
|
||||
if (! vflag) {
|
||||
printf(" (encap)");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
(void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
|
||||
ipaddr_string(&ip->ip_dst));
|
||||
(void)printf(" ip-proto-%d %d", ip->ip_p, len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* for fragmented datagrams, print id:size@offset. On all
|
||||
* but the last stick a "+". For unfragmented datagrams, note
|
||||
* the don't fragment flag.
|
||||
*/
|
||||
if (off & 0x3fff) {
|
||||
/*
|
||||
* if this isn't the first frag, we're missing the
|
||||
* next level protocol header. print the ip addr.
|
||||
*/
|
||||
if (off & 0x1fff)
|
||||
(void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
|
||||
ipaddr_string(&ip->ip_dst));
|
||||
(void)printf(" (frag %d:%d@%d%s)", ntohs(ip->ip_id), len,
|
||||
(off & 0x1fff) * 8,
|
||||
(off & IP_MF)? "+" : "");
|
||||
} else if (off & IP_DF)
|
||||
(void)printf(" (DF)");
|
||||
|
||||
if (ip->ip_tos)
|
||||
(void)printf(" [tos 0x%x]", (int)ip->ip_tos);
|
||||
if (ip->ip_ttl <= 1)
|
||||
(void)printf(" [ttl %d]", (int)ip->ip_ttl);
|
||||
|
||||
if (vflag) {
|
||||
int sum;
|
||||
char *sep = "";
|
||||
|
||||
printf(" (");
|
||||
if (ip->ip_ttl > 1) {
|
||||
(void)printf("%sttl %d", sep, (int)ip->ip_ttl);
|
||||
sep = ", ";
|
||||
}
|
||||
if ((off & 0x3fff) == 0) {
|
||||
(void)printf("%sid %d", sep, (int)ntohs(ip->ip_id));
|
||||
sep = ", ";
|
||||
}
|
||||
sum = in_cksum(ip);
|
||||
if (sum != 0) {
|
||||
(void)printf("%sbad cksum %x!", sep,
|
||||
ntohs(ip->ip_sum));
|
||||
sep = ", ";
|
||||
}
|
||||
if ((hlen -= sizeof(struct ip)) > 0) {
|
||||
(void)printf("%soptlen=%d", sep, hlen);
|
||||
ip_optprint((u_char *)(ip + 1), hlen);
|
||||
}
|
||||
printf(")");
|
||||
}
|
||||
}
|
@ -1,212 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Format and print Novell IPX packets.
|
||||
* Contributed by Brad Parker (brad@fcr.com).
|
||||
*/
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#)$Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/print-ipx.c,v 1.1 1995/03/08 12:52:34 olah Exp $";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
#include "ipx.h"
|
||||
#include "extract.h"
|
||||
|
||||
|
||||
static const char *ipxaddr_string(u_int32 net, const u_char *node);
|
||||
void ipx_decode(const struct ipxHdr *ipx, const u_char *datap, int length);
|
||||
void ipx_sap_print(const u_short *ipx, int length);
|
||||
void ipx_rip_print(const u_short *ipx, int length);
|
||||
|
||||
/*
|
||||
* Print IPX datagram packets.
|
||||
*/
|
||||
void
|
||||
ipx_print(const u_char *p, int length)
|
||||
{
|
||||
const struct ipxHdr *ipx = (const struct ipxHdr *)p;
|
||||
|
||||
if (length < ipxSize) {
|
||||
(void)printf(" truncated-ipx %d", length);
|
||||
return;
|
||||
}
|
||||
(void)printf("%s.%x > ",
|
||||
ipxaddr_string(EXTRACT_LONG(ipx->srcNet), ipx->srcNode),
|
||||
EXTRACT_SHORT(&ipx->srcSkt));
|
||||
|
||||
(void)printf("%s.%x:",
|
||||
ipxaddr_string(EXTRACT_LONG(ipx->dstNet), ipx->dstNode),
|
||||
EXTRACT_SHORT(&ipx->dstSkt));
|
||||
|
||||
if ((u_char *)(ipx + 1) > snapend) {
|
||||
printf(" [|ipx]");
|
||||
return;
|
||||
}
|
||||
|
||||
/* take length from ipx header */
|
||||
length = EXTRACT_SHORT(&ipx->length);
|
||||
|
||||
ipx_decode(ipx, (u_char *)ipx + ipxSize, length - ipxSize);
|
||||
}
|
||||
|
||||
static const char *
|
||||
ipxaddr_string(u_int32 net, const u_char *node)
|
||||
{
|
||||
static char line[256];
|
||||
|
||||
sprintf(line, "%lx.%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
net, node[0], node[1], node[2], node[3], node[4], node[5]);
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
void
|
||||
ipx_decode(const struct ipxHdr *ipx, const u_char *datap, int length)
|
||||
{
|
||||
switch (EXTRACT_SHORT(&ipx->dstSkt)) {
|
||||
case IPX_SKT_NCP:
|
||||
(void)printf(" ipx-ncp %d", length);
|
||||
break;
|
||||
case IPX_SKT_SAP:
|
||||
ipx_sap_print((u_short *)datap, length);
|
||||
break;
|
||||
case IPX_SKT_RIP:
|
||||
ipx_rip_print((u_short *)datap, length);
|
||||
break;
|
||||
case IPX_SKT_NETBIOS:
|
||||
(void)printf(" ipx-netbios %d", length);
|
||||
break;
|
||||
case IPX_SKT_DIAGNOSTICS:
|
||||
(void)printf(" ipx-diags %d", length);
|
||||
break;
|
||||
default:
|
||||
(void)printf(" ipx-#%x %d", ipx->dstSkt, length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ipx_sap_print(const u_short *ipx, int length)
|
||||
{
|
||||
int command, i;
|
||||
|
||||
if (length < 2) {
|
||||
(void)printf(" truncated-sap %d", length);
|
||||
return;
|
||||
}
|
||||
|
||||
command = EXTRACT_SHORT(ipx);
|
||||
ipx++;
|
||||
length -= 2;
|
||||
|
||||
switch (command) {
|
||||
case 1:
|
||||
case 3:
|
||||
if (command == 1)
|
||||
(void)printf("ipx-sap-req");
|
||||
else
|
||||
(void)printf("ipx-sap-nearest-req");
|
||||
|
||||
if (length > 0)
|
||||
(void)printf(" %x '%.48s'", EXTRACT_SHORT(&ipx[0]),
|
||||
(char*)&ipx[1]);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 4:
|
||||
if (command == 2)
|
||||
(void)printf("ipx-sap-resp");
|
||||
else
|
||||
(void)printf("ipx-sap-nearest-resp");
|
||||
|
||||
for (i = 0; i < 8 && length > 0; i++) {
|
||||
(void)printf(" %x '%.48s' addr %s",
|
||||
EXTRACT_SHORT(&ipx[0]), (char *)&ipx[1],
|
||||
ipxaddr_string(EXTRACT_LONG(&ipx[25]),
|
||||
(u_char *)&ipx[27]));
|
||||
ipx += 32;
|
||||
length -= 64;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
(void)printf("ipx-sap-?%x", command);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ipx_rip_print(const u_short *ipx, int length)
|
||||
{
|
||||
int command, i;
|
||||
|
||||
if (length < 2) {
|
||||
(void)printf(" truncated-ipx %d", length);
|
||||
return;
|
||||
}
|
||||
|
||||
command = EXTRACT_SHORT(ipx);
|
||||
ipx++;
|
||||
length -= 2;
|
||||
|
||||
switch (command) {
|
||||
case 1:
|
||||
(void)printf("ipx-rip-req");
|
||||
if (length > 0)
|
||||
(void)printf(" %lx/%d.%d", EXTRACT_LONG(&ipx[0]),
|
||||
EXTRACT_SHORT(&ipx[2]), EXTRACT_SHORT(&ipx[3]));
|
||||
break;
|
||||
case 2:
|
||||
(void)printf("ipx-rip-resp");
|
||||
for (i = 0; i < 50 && length > 0; i++) {
|
||||
(void)printf(" %lx/%d.%d", EXTRACT_LONG(&ipx[0]),
|
||||
EXTRACT_SHORT(&ipx[2]), EXTRACT_SHORT(&ipx[3]));
|
||||
|
||||
ipx += 4;
|
||||
length -= 8;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
(void)printf("ipx-rip-?%x", command);
|
||||
}
|
||||
}
|
||||
|
@ -1,315 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1992, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Original code by Matt Thomas, Digital Equipment Corporation
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: print-isoclns.c,v 1.9 94/06/14 20:18:44 leres Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
#include "ethertype.h"
|
||||
|
||||
#define CLNS 129
|
||||
#define ESIS 130
|
||||
#define ISIS 131
|
||||
#define NULLNS 0
|
||||
|
||||
static int osi_cksum(const u_char *, int, const u_char *, u_char *, u_char *);
|
||||
static void esis_print(const u_char *, int);
|
||||
|
||||
void
|
||||
isoclns_print(const u_char *p, int length, int caplen,
|
||||
const u_char *esrc, const u_char *edst)
|
||||
{
|
||||
if (caplen < 1) {
|
||||
printf("[|iso-clns] ");
|
||||
if (!eflag)
|
||||
printf("%s > %s",
|
||||
etheraddr_string(esrc),
|
||||
etheraddr_string(edst));
|
||||
return;
|
||||
}
|
||||
|
||||
switch (*p) {
|
||||
|
||||
case CLNS:
|
||||
/* esis_print(&p, &length); */
|
||||
printf("iso-clns");
|
||||
if (!eflag)
|
||||
(void)printf(" %s > %s",
|
||||
etheraddr_string(esrc),
|
||||
etheraddr_string(edst));
|
||||
break;
|
||||
|
||||
case ESIS:
|
||||
printf("iso-esis");
|
||||
if (!eflag)
|
||||
(void)printf(" %s > %s",
|
||||
etheraddr_string(esrc),
|
||||
etheraddr_string(edst));
|
||||
esis_print(p, length);
|
||||
return;
|
||||
|
||||
case ISIS:
|
||||
printf("iso-isis");
|
||||
if (!eflag)
|
||||
(void)printf(" %s > %s",
|
||||
etheraddr_string(esrc),
|
||||
etheraddr_string(edst));
|
||||
/* isis_print(&p, &length); */
|
||||
(void)printf(" len=%d ", length);
|
||||
if (caplen > 1)
|
||||
default_print_unaligned(p, caplen);
|
||||
break;
|
||||
|
||||
case NULLNS:
|
||||
printf("iso-nullns");
|
||||
if (!eflag)
|
||||
(void)printf(" %s > %s",
|
||||
etheraddr_string(esrc),
|
||||
etheraddr_string(edst));
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("iso-clns %02x", p[0]);
|
||||
if (!eflag)
|
||||
(void)printf(" %s > %s",
|
||||
etheraddr_string(esrc),
|
||||
etheraddr_string(edst));
|
||||
(void)printf(" len=%d ", length);
|
||||
if (caplen > 1)
|
||||
default_print_unaligned(p, caplen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#define ESIS_REDIRECT 6
|
||||
#define ESIS_ESH 2
|
||||
#define ESIS_ISH 4
|
||||
|
||||
struct esis_hdr {
|
||||
u_char version;
|
||||
u_char reserved;
|
||||
u_char type;
|
||||
u_char tmo[2];
|
||||
u_char cksum[2];
|
||||
};
|
||||
|
||||
static void
|
||||
esis_print(const u_char *p, int length)
|
||||
{
|
||||
const u_char *ep;
|
||||
int li = p[1];
|
||||
const struct esis_hdr *eh = (const struct esis_hdr *) &p[2];
|
||||
u_char cksum[2];
|
||||
u_char off[2];
|
||||
|
||||
if (length == 2) {
|
||||
if (qflag)
|
||||
printf(" bad pkt!");
|
||||
else
|
||||
printf(" no header at all!");
|
||||
return;
|
||||
}
|
||||
ep = p + li;
|
||||
if (li > length) {
|
||||
if (qflag)
|
||||
printf(" bad pkt!");
|
||||
else
|
||||
printf(" LI(%d) > PDU size (%d)!", li, length);
|
||||
return;
|
||||
}
|
||||
if (li < sizeof(struct esis_hdr) + 2) {
|
||||
if (qflag)
|
||||
printf(" bad pkt!");
|
||||
else {
|
||||
printf(" too short for esis header %d:", li);
|
||||
while (--length >= 0)
|
||||
printf("%02X", *p++);
|
||||
}
|
||||
return;
|
||||
}
|
||||
switch (eh->type & 0x1f) {
|
||||
|
||||
case ESIS_REDIRECT:
|
||||
printf(" redirect");
|
||||
break;
|
||||
|
||||
case ESIS_ESH:
|
||||
printf(" esh");
|
||||
break;
|
||||
|
||||
case ESIS_ISH:
|
||||
printf(" ish");
|
||||
break;
|
||||
|
||||
default:
|
||||
printf(" type %d", eh->type & 0x1f);
|
||||
break;
|
||||
}
|
||||
off[0] = eh->cksum[0];
|
||||
off[1] = eh->cksum[1];
|
||||
if (vflag && osi_cksum(p, li, eh->cksum, cksum, off)) {
|
||||
printf(" bad cksum (got %02x%02x want %02x%02x)",
|
||||
eh->cksum[1], eh->cksum[0], cksum[1], cksum[0]);
|
||||
return;
|
||||
}
|
||||
if (eh->version != 1) {
|
||||
printf(" unsupported version %d", eh->version);
|
||||
return;
|
||||
}
|
||||
p += sizeof(*eh) + 2;
|
||||
li -= sizeof(*eh) + 2; /* protoid * li */
|
||||
|
||||
switch (eh->type & 0x1f) {
|
||||
case ESIS_REDIRECT: {
|
||||
const u_char *dst, *snpa, *is;
|
||||
|
||||
dst = p; p += *p + 1;
|
||||
if (p > snapend)
|
||||
return;
|
||||
printf(" %s", isonsap_string(dst));
|
||||
snpa = p; p += *p + 1;
|
||||
is = p; p += *p + 1;
|
||||
if (p > snapend)
|
||||
return;
|
||||
if (p > ep) {
|
||||
printf(" [bad li]");
|
||||
return;
|
||||
}
|
||||
if (is[0] == 0)
|
||||
printf(" > %s", etheraddr_string(&snpa[1]));
|
||||
else
|
||||
printf(" > %s", isonsap_string(is));
|
||||
li = ep - p;
|
||||
break;
|
||||
}
|
||||
#if 0
|
||||
case ESIS_ESH:
|
||||
printf(" esh");
|
||||
break;
|
||||
#endif
|
||||
case ESIS_ISH: {
|
||||
const u_char *is;
|
||||
|
||||
is = p; p += *p + 1;
|
||||
if (p > ep) {
|
||||
printf(" [bad li]");
|
||||
return;
|
||||
}
|
||||
if (p > snapend)
|
||||
return;
|
||||
printf(" %s", isonsap_string(is));
|
||||
li = ep - p;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
(void)printf(" len=%d", length);
|
||||
if (length && p < snapend) {
|
||||
length = snapend - p;
|
||||
default_print(p, length);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (vflag)
|
||||
while (p < ep && li) {
|
||||
int op, opli;
|
||||
const u_char *q;
|
||||
|
||||
if (snapend - p < 2)
|
||||
return;
|
||||
if (li < 2) {
|
||||
printf(" bad opts/li");
|
||||
return;
|
||||
}
|
||||
op = *p++;
|
||||
opli = *p++;
|
||||
li -= 2;
|
||||
if (opli > li) {
|
||||
printf(" opt (%d) too long", op);
|
||||
return;
|
||||
}
|
||||
li -= opli;
|
||||
q = p;
|
||||
p += opli;
|
||||
if (snapend < p)
|
||||
return;
|
||||
if (op == 198 && opli == 2) {
|
||||
printf(" tmo=%d", q[0] * 256 + q[1]);
|
||||
continue;
|
||||
}
|
||||
printf (" %d:<", op);
|
||||
while (--opli >= 0)
|
||||
printf("%02x", *q++);
|
||||
printf (">");
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
osi_cksum(register const u_char *p, register int len,
|
||||
const u_char *toff, u_char *cksum, u_char *off)
|
||||
{
|
||||
int x, y, f = (len - ((toff - p) + 1));
|
||||
long c0 = 0, c1 = 0;
|
||||
|
||||
if ((cksum[0] = off[0]) == 0 && (cksum[1] = off[1]) == 0)
|
||||
return 0;
|
||||
|
||||
off[0] = off[1] = 0;
|
||||
while (--len >= 0) {
|
||||
c0 += *p++;
|
||||
c1 += c0;
|
||||
c0 %= 255;
|
||||
c1 %= 255;
|
||||
}
|
||||
x = (c0 * f - c1);
|
||||
if (x < 0)
|
||||
x = 255 - (-x % 255);
|
||||
else
|
||||
x %= 255;
|
||||
y = -1 * (x + c0);
|
||||
if (y < 0)
|
||||
y = 255 - (-y % 255);
|
||||
else
|
||||
y %= 255;
|
||||
|
||||
off[0] = x;
|
||||
off[1] = y;
|
||||
|
||||
return (off[0] != cksum[0] || off[1] != cksum[1]);
|
||||
}
|
@ -1,294 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1995
|
||||
* 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.
|
||||
*
|
||||
* Initial contribution from John Hawkinson (jhawk@mit.edu).
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"$Id$";
|
||||
/*
|
||||
"@(#) Header: /afs/sipb/project/tcpdump/src/tcpdump-3.0.2/RCS/print-krb.c,v 1.3 1995/08/16 05:33:27 jhawk Exp ";
|
||||
*/
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
const char *c_print(register const u_char *s, register const u_char *ep);
|
||||
const u_char *krb4_print_hdr(const u_char *cp);
|
||||
void krb4_print(const u_char *cp);
|
||||
void krb_print(const u_char *dat, int length);
|
||||
|
||||
|
||||
#define AUTH_MSG_KDC_REQUEST 1<<1
|
||||
#define AUTH_MSG_KDC_REPLY 2<<1
|
||||
#define AUTH_MSG_APPL_REQUEST 3<<1
|
||||
#define AUTH_MSG_APPL_REQUEST_MUTUAL 4<<1
|
||||
#define AUTH_MSG_ERR_REPLY 5<<1
|
||||
#define AUTH_MSG_PRIVATE 6<<1
|
||||
#define AUTH_MSG_SAFE 7<<1
|
||||
#define AUTH_MSG_APPL_ERR 8<<1
|
||||
#define AUTH_MSG_DIE 63<<1
|
||||
|
||||
#define KERB_ERR_OK 0
|
||||
#define KERB_ERR_NAME_EXP 1
|
||||
#define KERB_ERR_SERVICE_EXP 2
|
||||
#define KERB_ERR_AUTH_EXP 3
|
||||
#define KERB_ERR_PKT_VER 4
|
||||
#define KERB_ERR_NAME_MAST_KEY_VER 5
|
||||
#define KERB_ERR_SERV_MAST_KEY_VER 6
|
||||
#define KERB_ERR_BYTE_ORDER 7
|
||||
#define KERB_ERR_PRINCIPAL_UNKNOWN 8
|
||||
#define KERB_ERR_PRINCIPAL_NOT_UNIQUE 9
|
||||
#define KERB_ERR_NULL_KEY 10
|
||||
|
||||
struct krb {
|
||||
u_char pvno; /* Protocol Version */
|
||||
u_char type; /* Type+B */
|
||||
} ;
|
||||
|
||||
static char tstr[] = " [|kerberos]";
|
||||
|
||||
static struct token type2str[] = {
|
||||
{ AUTH_MSG_KDC_REQUEST, "KDC_REQUEST" },
|
||||
{ AUTH_MSG_KDC_REPLY, "KDC_REPLY" },
|
||||
{ AUTH_MSG_APPL_REQUEST, "APPL_REQUEST" },
|
||||
{ AUTH_MSG_APPL_REQUEST_MUTUAL, "APPL_REQUEST_MUTUAL" },
|
||||
{ AUTH_MSG_ERR_REPLY, "ERR_REPLY" },
|
||||
{ AUTH_MSG_PRIVATE, "PRIVATE" },
|
||||
{ AUTH_MSG_SAFE, "SAFE" },
|
||||
{ AUTH_MSG_APPL_ERR, "APPL_ERR" },
|
||||
{ AUTH_MSG_DIE, "DIE" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static struct token kerr2str[] = {
|
||||
{ KERB_ERR_OK, "OK" },
|
||||
{ KERB_ERR_NAME_EXP, "NAME_EXP" },
|
||||
{ KERB_ERR_SERVICE_EXP, "SERVICE_EXP" },
|
||||
{ KERB_ERR_AUTH_EXP, "AUTH_EXP" },
|
||||
{ KERB_ERR_PKT_VER, "PKT_VER" },
|
||||
{ KERB_ERR_NAME_MAST_KEY_VER, "NAME_MAST_KEY_VER" },
|
||||
{ KERB_ERR_SERV_MAST_KEY_VER, "SERV_MAST_KEY_VER" },
|
||||
{ KERB_ERR_BYTE_ORDER, "BYTE_ORDER" },
|
||||
{ KERB_ERR_PRINCIPAL_UNKNOWN, "PRINCIPAL_UNKNOWN" },
|
||||
{ KERB_ERR_PRINCIPAL_NOT_UNIQUE, "PRINCIPAL_NOT_UNIQUE" },
|
||||
{ KERB_ERR_NULL_KEY, "NULL_KEY"},
|
||||
{ 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
/* little endian (unaligned) to host byte order */
|
||||
#define vtohlp(x) ((( ((char*)(x))[0] ) ) | \
|
||||
(( ((char*)(x))[1] ) << 8) | \
|
||||
(( ((char*)(x))[2] ) << 16) | \
|
||||
(( ((char*)(x))[3] ) << 24))
|
||||
#define vtohsp(x) ((( ((char*)(x))[0] ) ) | \
|
||||
(( ((char*)(x))[1] ) << 8))
|
||||
/* network (big endian) (unaligned) to host byte order */
|
||||
#define ntohlp(x) ((( ((char*)(x))[3] ) ) | \
|
||||
(( ((char*)(x))[2] ) << 8) | \
|
||||
(( ((char*)(x))[1] ) << 16) | \
|
||||
(( ((char*)(x))[0] ) << 24))
|
||||
#define ntohsp(x) ((( ((char*)(x))[1] ) ) | \
|
||||
(( ((char*)(x))[0] ) << 8))
|
||||
|
||||
|
||||
|
||||
const char *
|
||||
c_print(register const u_char *s, register const u_char *ep)
|
||||
{
|
||||
register u_char c;
|
||||
register int flag;
|
||||
|
||||
flag = 1;
|
||||
while (ep == NULL || s < ep) {
|
||||
c = *s++;
|
||||
if (c == '\0') {
|
||||
flag = 0;
|
||||
break;
|
||||
}
|
||||
if (!isascii(c)) {
|
||||
c = toascii(c);
|
||||
putchar('M');
|
||||
putchar('-');
|
||||
}
|
||||
if (!isprint(c)) {
|
||||
c ^= 0x40; /* DEL to ?, others to alpha */
|
||||
putchar('^');
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
if (flag)
|
||||
return NULL;
|
||||
return(s);
|
||||
}
|
||||
|
||||
|
||||
const u_char *
|
||||
krb4_print_hdr(const u_char *cp)
|
||||
{
|
||||
cp+=2;
|
||||
|
||||
#define TCHECK if (cp >= snapend) goto trunc
|
||||
#define PRINT if ((cp=c_print(cp, snapend))==NULL) goto trunc
|
||||
|
||||
TCHECK;
|
||||
PRINT;
|
||||
TCHECK;
|
||||
putchar('.'); PRINT;
|
||||
TCHECK;
|
||||
putchar('@'); PRINT;
|
||||
return(cp);
|
||||
|
||||
trunc:
|
||||
fputs(tstr, stdout);
|
||||
return(NULL);
|
||||
|
||||
#undef TCHECK
|
||||
#undef PRINT
|
||||
}
|
||||
|
||||
void krb4_print(const u_char *cp)
|
||||
{
|
||||
register const struct krb *kp;
|
||||
u_char type;
|
||||
u_short len;
|
||||
|
||||
#define TCHECK if (cp >= snapend) goto trunc
|
||||
#define PRINT if ((cp=c_print(cp, snapend))==NULL) goto trunc
|
||||
#define ENDIAN (kp->type & 0x01)
|
||||
/* ENDIAN is 1 for little, 0 for big */
|
||||
|
||||
kp = (struct krb *)cp;
|
||||
|
||||
if ((&kp->type) >= snapend) {
|
||||
fputs(tstr, stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
type = kp->type & (0xFF << 1);
|
||||
|
||||
printf(" %s %s: ", ENDIAN?"le":"be", tok2str(type2str, NULL, type));
|
||||
|
||||
switch(type) {
|
||||
case AUTH_MSG_KDC_REQUEST:
|
||||
if ((cp=krb4_print_hdr(cp)) == NULL)
|
||||
return;
|
||||
cp+=4; /* ctime */
|
||||
TCHECK;
|
||||
printf(" %dmin ", *cp++ * 5);
|
||||
TCHECK;
|
||||
PRINT;
|
||||
TCHECK;
|
||||
putchar('.'); PRINT;
|
||||
break;
|
||||
case AUTH_MSG_APPL_REQUEST:
|
||||
cp+=2;
|
||||
TCHECK;
|
||||
printf("v%d ", *cp++);
|
||||
TCHECK;
|
||||
PRINT;
|
||||
TCHECK;
|
||||
printf(" (%d)", *cp++);
|
||||
TCHECK;
|
||||
printf(" (%d)", *cp);
|
||||
TCHECK;
|
||||
break;
|
||||
case AUTH_MSG_KDC_REPLY:
|
||||
if ((cp=krb4_print_hdr(cp)) == NULL)
|
||||
return;
|
||||
cp+=10; /* timestamp + n + exp + kvno */
|
||||
TCHECK;
|
||||
len=ENDIAN? vtohsp(cp) : ntohsp(cp);
|
||||
printf(" (%d)", len);
|
||||
TCHECK;
|
||||
break;
|
||||
case AUTH_MSG_ERR_REPLY:
|
||||
if ((cp=krb4_print_hdr(cp)) == NULL)
|
||||
return;
|
||||
cp+=4; /* timestamp */
|
||||
TCHECK;
|
||||
printf(" %s ", tok2str(kerr2str, NULL,
|
||||
ENDIAN? vtohlp(cp) :
|
||||
ntohlp(cp)
|
||||
));
|
||||
cp+=4;
|
||||
TCHECK;
|
||||
PRINT;
|
||||
break;
|
||||
default:
|
||||
fputs("(unknown)", stdout);
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
trunc:
|
||||
fputs(tstr, stdout);
|
||||
#undef TCHECK
|
||||
}
|
||||
|
||||
void
|
||||
krb_print(const u_char *dat, int length)
|
||||
{
|
||||
register const struct krb *kp;
|
||||
|
||||
kp = (struct krb *)dat;
|
||||
|
||||
if (dat >= snapend) {
|
||||
fputs(tstr, stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (kp->pvno) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
printf(" v%d", kp->pvno);
|
||||
break;
|
||||
case 4:
|
||||
printf(" v%d", kp->pvno);
|
||||
krb4_print((const u_char*)kp);
|
||||
break;
|
||||
case 106:
|
||||
case 107:
|
||||
fputs(" v5", stdout);
|
||||
/* Decode ASN.1 here "someday" */
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
@ -1,196 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1992, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Code by Matt Thomas, Digital Equipment Corporation
|
||||
* with an awful lot of hacking by Jeffrey Mogul, DECWRL
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#)$Header: print-llc.c,v 1.13 94/06/14 20:18:45 leres Exp $";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
#include "extract.h" /* must come after interface.h */
|
||||
|
||||
#include "llc.h"
|
||||
|
||||
static struct token cmd2str[] = {
|
||||
{ LLC_UI, "ui" },
|
||||
{ LLC_TEST, "test" },
|
||||
{ LLC_XID, "xid" },
|
||||
{ LLC_UA, "ua" },
|
||||
{ LLC_DISC, "disc" },
|
||||
{ LLC_DM, "dm" },
|
||||
{ LLC_SABME, "sabme" },
|
||||
{ LLC_FRMR, "frmr" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
* Returns non-zero IFF it succeeds in printing the header
|
||||
*/
|
||||
int
|
||||
llc_print(const u_char *p, int length, int caplen,
|
||||
const u_char *esrc, const u_char *edst)
|
||||
{
|
||||
struct llc llc;
|
||||
register u_short et;
|
||||
register int ret;
|
||||
|
||||
if (caplen < 3) {
|
||||
(void)printf("[|llc]");
|
||||
default_print((u_char *)p, caplen);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Watch out for possible alignment problems */
|
||||
bcopy((char *)p, (char *)&llc, min(caplen, sizeof(llc)));
|
||||
|
||||
if (llc.ssap == LLCSAP_GLOBAL && llc.dsap == LLCSAP_GLOBAL) {
|
||||
ipx_print(p, length);
|
||||
return (1);
|
||||
}
|
||||
#ifdef notyet
|
||||
else if (p[0] == 0xf0 && p[1] == 0xf0)
|
||||
netbios_print(p, length);
|
||||
#endif
|
||||
if (llc.ssap == LLCSAP_ISONS && llc.dsap == LLCSAP_ISONS
|
||||
&& llc.llcui == LLC_UI) {
|
||||
isoclns_print(p + 3, length - 3, caplen - 3, esrc, edst);
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (llc.ssap == LLCSAP_SNAP && llc.dsap == LLCSAP_SNAP
|
||||
&& llc.llcui == LLC_UI) {
|
||||
if (caplen < sizeof(llc)) {
|
||||
(void)printf("[|llc-snap]");
|
||||
default_print((u_char *)p, caplen);
|
||||
return (0);
|
||||
}
|
||||
if (vflag)
|
||||
(void)printf("snap %s ", protoid_string(llc.llcpi));
|
||||
|
||||
caplen -= sizeof(llc);
|
||||
length -= sizeof(llc);
|
||||
p += sizeof(llc);
|
||||
|
||||
/* This is an encapsulated Ethernet packet */
|
||||
et = EXTRACT_SHORT(&llc.ethertype[0]);
|
||||
ret = ether_encap_print(et, p, length, caplen);
|
||||
if (ret)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
if ((llc.ssap & ~LLC_GSAP) == llc.dsap) {
|
||||
if (eflag)
|
||||
(void)printf("%s ", llcsap_string(llc.dsap));
|
||||
else
|
||||
(void)printf("%s > %s %s ",
|
||||
etheraddr_string(esrc),
|
||||
etheraddr_string(edst),
|
||||
llcsap_string(llc.dsap));
|
||||
} else {
|
||||
if (eflag)
|
||||
(void)printf("%s > %s ",
|
||||
llcsap_string(llc.ssap & ~LLC_GSAP),
|
||||
llcsap_string(llc.dsap));
|
||||
else
|
||||
(void)printf("%s %s > %s %s ",
|
||||
etheraddr_string(esrc),
|
||||
llcsap_string(llc.ssap & ~LLC_GSAP),
|
||||
etheraddr_string(edst),
|
||||
llcsap_string(llc.dsap));
|
||||
}
|
||||
|
||||
if ((llc.llcu & LLC_U_FMT) == LLC_U_FMT) {
|
||||
const char *m;
|
||||
char f;
|
||||
m = tok2str(cmd2str, "%02x", LLC_U_CMD(llc.llcu));
|
||||
switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) {
|
||||
case 0: f = 'C'; break;
|
||||
case LLC_GSAP: f = 'R'; break;
|
||||
case LLC_U_POLL: f = 'P'; break;
|
||||
case LLC_GSAP|LLC_U_POLL: f = 'F'; break;
|
||||
default: f = '?'; break;
|
||||
}
|
||||
|
||||
printf("%s/%c", m, f);
|
||||
|
||||
p += 3;
|
||||
length -= 3;
|
||||
caplen -= 3;
|
||||
|
||||
if ((llc.llcu & ~LLC_U_POLL) == LLC_XID) {
|
||||
if (*p == LLC_XID_FI) {
|
||||
printf(": %02x %02x", p[1], p[2]);
|
||||
p += 3;
|
||||
length -= 3;
|
||||
caplen -= 3;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
char f;
|
||||
llc.llcis = ntohs(llc.llcis);
|
||||
switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) {
|
||||
case 0: f = 'C'; break;
|
||||
case LLC_GSAP: f = 'R'; break;
|
||||
case LLC_U_POLL: f = 'P'; break;
|
||||
case LLC_GSAP|LLC_U_POLL: f = 'F'; break;
|
||||
default: f = '?'; break;
|
||||
}
|
||||
|
||||
if ((llc.llcu & LLC_S_FMT) == LLC_S_FMT) {
|
||||
static char *llc_s[] = { "rr", "rej", "rnr", "03" };
|
||||
(void)printf("%s (r=%d,%c)",
|
||||
llc_s[LLC_S_CMD(llc.llcis)],
|
||||
LLC_IS_NR(llc.llcis),
|
||||
f);
|
||||
} else {
|
||||
(void)printf("I (s=%d,r=%d,%c)",
|
||||
LLC_I_NS(llc.llcis),
|
||||
LLC_IS_NR(llc.llcis),
|
||||
f);
|
||||
}
|
||||
p += 4;
|
||||
length -= 4;
|
||||
caplen -= 4;
|
||||
}
|
||||
(void)printf(" len=%d", length);
|
||||
if (caplen > 0) {
|
||||
default_print_unaligned(p, caplen);
|
||||
}
|
||||
return(1);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,285 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1990, 1991, 1992, 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.
|
||||
*
|
||||
* Format and print ntp packets.
|
||||
* By Jeffrey Mogul/DECWRL
|
||||
* loosely based on print-bootp.c
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: print-ntp.c,v 1.14 94/06/14 20:18:46 leres Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
#undef MODEMASK /* Solaris sucks */
|
||||
#include "ntp.h"
|
||||
|
||||
static void p_sfix(const struct s_fixedpt *);
|
||||
static void p_ntp_time(const struct l_fixedpt *);
|
||||
static void p_ntp_delta(const struct l_fixedpt *, const struct l_fixedpt *);
|
||||
|
||||
/*
|
||||
* Print ntp requests
|
||||
*/
|
||||
void
|
||||
ntp_print(register const u_char *cp, int length)
|
||||
{
|
||||
register const struct ntpdata *bp;
|
||||
register const u_char *ep;
|
||||
int mode, version, leapind;
|
||||
static char rclock[5];
|
||||
|
||||
#define TCHECK(var, l) if ((u_char *)&(var) > ep - l) goto trunc
|
||||
|
||||
bp = (struct ntpdata *)cp;
|
||||
/* Note funny sized packets */
|
||||
if (length != sizeof(struct ntpdata))
|
||||
(void)printf(" [len=%d]", length);
|
||||
|
||||
/* 'ep' points to the end of avaible data. */
|
||||
ep = snapend;
|
||||
|
||||
TCHECK(bp->status, sizeof(bp->status));
|
||||
|
||||
version = (bp->status & VERSIONMASK) >> 3;
|
||||
printf(" v%d", version);
|
||||
|
||||
leapind = bp->status & LEAPMASK;
|
||||
switch (leapind) {
|
||||
|
||||
case NO_WARNING:
|
||||
break;
|
||||
|
||||
case PLUS_SEC:
|
||||
fputs(" +1s", stdout);
|
||||
break;
|
||||
|
||||
case MINUS_SEC:
|
||||
fputs(" -1s", stdout);
|
||||
break;
|
||||
}
|
||||
|
||||
mode = bp->status & MODEMASK;
|
||||
switch (mode) {
|
||||
|
||||
case MODE_UNSPEC: /* unspecified */
|
||||
fputs(" unspec", stdout);
|
||||
break;
|
||||
|
||||
case MODE_SYM_ACT: /* symmetric active */
|
||||
fputs(" sym_act", stdout);
|
||||
break;
|
||||
|
||||
case MODE_SYM_PAS: /* symmetric passive */
|
||||
fputs(" sym_pas", stdout);
|
||||
break;
|
||||
|
||||
case MODE_CLIENT: /* client */
|
||||
fputs(" client", stdout);
|
||||
break;
|
||||
|
||||
case MODE_SERVER: /* server */
|
||||
fputs(" server", stdout);
|
||||
break;
|
||||
|
||||
case MODE_BROADCAST: /* broadcast */
|
||||
fputs(" bcast", stdout);
|
||||
break;
|
||||
|
||||
case MODE_RES1: /* reserved */
|
||||
fputs(" res1", stdout);
|
||||
break;
|
||||
|
||||
case MODE_RES2: /* reserved */
|
||||
fputs(" res2", stdout);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
TCHECK(bp->stratum, sizeof(bp->stratum));
|
||||
printf(" strat %d", bp->stratum);
|
||||
|
||||
TCHECK(bp->ppoll, sizeof(bp->ppoll));
|
||||
printf(" poll %d", bp->ppoll);
|
||||
|
||||
/* Can't TCHECK bp->precision bitfield so bp->distance + 0 instead */
|
||||
TCHECK(bp->distance, 0);
|
||||
printf(" prec %d", bp->precision);
|
||||
|
||||
if (!vflag)
|
||||
return;
|
||||
|
||||
TCHECK(bp->distance, sizeof(bp->distance));
|
||||
fputs(" dist ", stdout);
|
||||
p_sfix(&bp->distance);
|
||||
|
||||
TCHECK(bp->dispersion, sizeof(bp->dispersion));
|
||||
fputs(" disp ", stdout);
|
||||
p_sfix(&bp->dispersion);
|
||||
|
||||
TCHECK(bp->refid, sizeof(bp->refid));
|
||||
fputs(" ref ", stdout);
|
||||
/* Interpretation depends on stratum */
|
||||
switch (bp->stratum) {
|
||||
|
||||
case UNSPECIFIED:
|
||||
case PRIM_REF:
|
||||
strncpy(rclock, (char *)&(bp->refid), 4);
|
||||
rclock[4] = '\0';
|
||||
fputs(rclock, stdout);
|
||||
break;
|
||||
|
||||
case INFO_QUERY:
|
||||
printf("%s INFO_QUERY", ipaddr_string(&(bp->refid)));
|
||||
/* this doesn't have more content */
|
||||
return;
|
||||
|
||||
case INFO_REPLY:
|
||||
printf("%s INFO_REPLY", ipaddr_string(&(bp->refid)));
|
||||
/* this is too complex to be worth printing */
|
||||
return;
|
||||
|
||||
default:
|
||||
printf("%s", ipaddr_string(&(bp->refid)));
|
||||
break;
|
||||
}
|
||||
|
||||
TCHECK(bp->reftime, sizeof(bp->reftime));
|
||||
putchar('@');
|
||||
p_ntp_time(&(bp->reftime));
|
||||
|
||||
TCHECK(bp->org, sizeof(bp->org));
|
||||
fputs(" orig ", stdout);
|
||||
p_ntp_time(&(bp->org));
|
||||
|
||||
TCHECK(bp->rec, sizeof(bp->rec));
|
||||
fputs(" rec ", stdout);
|
||||
p_ntp_delta(&(bp->org), &(bp->rec));
|
||||
|
||||
TCHECK(bp->xmt, sizeof(bp->xmt));
|
||||
fputs(" xmt ", stdout);
|
||||
p_ntp_delta(&(bp->org), &(bp->xmt));
|
||||
|
||||
return;
|
||||
|
||||
trunc:
|
||||
fputs(" [|ntp]", stdout);
|
||||
#undef TCHECK
|
||||
}
|
||||
|
||||
static void
|
||||
p_sfix(register const struct s_fixedpt *sfp)
|
||||
{
|
||||
register int i;
|
||||
register int f;
|
||||
register float ff;
|
||||
|
||||
i = ntohs(sfp->int_part);
|
||||
f = ntohs(sfp->fraction);
|
||||
ff = f / 65536.0; /* shift radix point by 16 bits */
|
||||
f = ff * 1000000.0; /* Treat fraction as parts per million */
|
||||
printf("%d.%06d", i, f);
|
||||
}
|
||||
|
||||
#define FMAXINT (4294967296.0) /* floating point rep. of MAXINT */
|
||||
|
||||
static void
|
||||
p_ntp_time(register const struct l_fixedpt *lfp)
|
||||
{
|
||||
register int32 i;
|
||||
register u_int32 uf;
|
||||
register u_int32 f;
|
||||
register float ff;
|
||||
|
||||
i = ntohl(lfp->int_part);
|
||||
uf = ntohl(lfp->fraction);
|
||||
ff = uf;
|
||||
if (ff < 0.0) /* some compilers are buggy */
|
||||
ff += FMAXINT;
|
||||
ff = ff / FMAXINT; /* shift radix point by 32 bits */
|
||||
f = ff * 1000000000.0; /* treat fraction as parts per billion */
|
||||
printf("%lu.%09d", i, f);
|
||||
}
|
||||
|
||||
/* Prints time difference between *lfp and *olfp */
|
||||
static void
|
||||
p_ntp_delta(register const struct l_fixedpt *olfp,
|
||||
register const struct l_fixedpt *lfp)
|
||||
{
|
||||
register int32 i;
|
||||
register u_int32 uf;
|
||||
register u_int32 ouf;
|
||||
register u_int32 f;
|
||||
register float ff;
|
||||
int signbit;
|
||||
|
||||
i = ntohl(lfp->int_part) - ntohl(olfp->int_part);
|
||||
|
||||
uf = ntohl(lfp->fraction);
|
||||
ouf = ntohl(olfp->fraction);
|
||||
|
||||
if (i > 0) { /* new is definitely greater than old */
|
||||
signbit = 0;
|
||||
f = uf - ouf;
|
||||
if (ouf > uf) /* must borrow from high-order bits */
|
||||
i -= 1;
|
||||
} else if (i < 0) { /* new is definitely less than old */
|
||||
signbit = 1;
|
||||
f = ouf - uf;
|
||||
if (uf > ouf) /* must carry into the high-order bits */
|
||||
i += 1;
|
||||
i = -i;
|
||||
} else { /* int_part is zero */
|
||||
if (uf > ouf) {
|
||||
signbit = 0;
|
||||
f = uf - ouf;
|
||||
} else {
|
||||
signbit = 1;
|
||||
f = ouf - uf;
|
||||
}
|
||||
}
|
||||
|
||||
ff = f;
|
||||
if (ff < 0.0) /* some compilers are buggy */
|
||||
ff += FMAXINT;
|
||||
ff = ff / FMAXINT; /* shift radix point by 32 bits */
|
||||
f = ff * 1000000000.0; /* treat fraction as parts per billion */
|
||||
if (signbit)
|
||||
putchar('-');
|
||||
else
|
||||
putchar('+');
|
||||
printf("%d.%09d", i, f);
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#)$Header: print-null.c,v 1.14 94/06/10 17:01:35 mccanne Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
#include "pcap.h"
|
||||
|
||||
#define NULL_HDRLEN 4
|
||||
|
||||
static void
|
||||
null_print(const u_char *p, const struct ip *ip, int length)
|
||||
{
|
||||
u_int family;
|
||||
|
||||
bcopy(p, &family, sizeof(family));
|
||||
|
||||
if (nflag) {
|
||||
/* XXX just dump the header */
|
||||
return;
|
||||
}
|
||||
switch (family) {
|
||||
|
||||
case AF_INET:
|
||||
printf("ip: ");
|
||||
break;
|
||||
|
||||
case AF_NS:
|
||||
printf("ns: ");
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("AF %d: ", family);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
null_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
|
||||
{
|
||||
int length = h->len;
|
||||
int caplen = h->caplen;
|
||||
const struct ip *ip;
|
||||
|
||||
ts_print(&h->ts);
|
||||
|
||||
/*
|
||||
* Some printers want to get back at the link level addresses,
|
||||
* and/or check that they're not walking off the end of the packet.
|
||||
* Rather than pass them all the way down, we set these globals.
|
||||
*/
|
||||
packetp = p;
|
||||
snapend = p + caplen;
|
||||
|
||||
length -= NULL_HDRLEN;
|
||||
|
||||
ip = (struct ip *)(p + NULL_HDRLEN);
|
||||
|
||||
if (eflag)
|
||||
null_print(p, ip, length);
|
||||
|
||||
ip_print((const u_char *)ip, length);
|
||||
|
||||
if (xflag)
|
||||
default_print((const u_char *)ip, caplen - NULL_HDRLEN);
|
||||
putchar('\n');
|
||||
}
|
||||
|
@ -1,578 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1992, 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.
|
||||
*
|
||||
* OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: print-ospf.c,v 1.12 94/06/14 20:18:46 leres Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
#include "ospf.h"
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define inline
|
||||
#endif
|
||||
|
||||
struct bits {
|
||||
u_int32 bit;
|
||||
const char *str;
|
||||
};
|
||||
|
||||
static const struct bits ospf_option_bits[] = {
|
||||
{ OSPF_OPTION_T, "T" },
|
||||
{ OSPF_OPTION_E, "E" },
|
||||
{ OSPF_OPTION_MC, "MC" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static const struct bits ospf_rla_flag_bits[] = {
|
||||
{ RLA_FLAG_B, "B" },
|
||||
{ RLA_FLAG_E, "E" },
|
||||
{ RLA_FLAG_W1, "W1" },
|
||||
{ RLA_FLAG_W2, "W2" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static const char *ospf_types[OSPF_TYPE_MAX] = {
|
||||
(char *) 0,
|
||||
"hello",
|
||||
"dd",
|
||||
"ls_req",
|
||||
"ls_upd",
|
||||
"ls_ack"
|
||||
};
|
||||
|
||||
static inline void
|
||||
ospf_print_seqage(register u_int32 seq, register time_t us)
|
||||
{
|
||||
register time_t sec = us % 60;
|
||||
register time_t mins = (us / 60) % 60;
|
||||
register time_t hour = us/3600;
|
||||
|
||||
printf(" S %X age ",
|
||||
seq);
|
||||
if (hour) {
|
||||
printf("%d:%02d:%02d",
|
||||
hour,
|
||||
mins,
|
||||
sec);
|
||||
} else if (mins) {
|
||||
printf("%d:%02d",
|
||||
mins,
|
||||
sec);
|
||||
} else {
|
||||
printf("%d",
|
||||
sec);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
ospf_print_bits(register const struct bits *bp, register u_char options)
|
||||
{
|
||||
char sep = ' ';
|
||||
|
||||
do {
|
||||
if (options & bp->bit) {
|
||||
printf("%c%s",
|
||||
sep,
|
||||
bp->str);
|
||||
sep = '/';
|
||||
}
|
||||
} while ((++bp)->bit) ;
|
||||
}
|
||||
|
||||
|
||||
#define LS_PRINT(lsp, type) switch (type) { \
|
||||
case LS_TYPE_ROUTER: \
|
||||
printf(" rtr %s ", ipaddr_string(&lsp->ls_router)); break; \
|
||||
case LS_TYPE_NETWORK: \
|
||||
printf(" net dr %s if %s", ipaddr_string(&lsp->ls_router), ipaddr_string(&lsp->ls_stateid)); break; \
|
||||
case LS_TYPE_SUM_IP: \
|
||||
printf(" sum %s abr %s", ipaddr_string(&lsp->ls_stateid), ipaddr_string(&lsp->ls_router)); break; \
|
||||
case LS_TYPE_SUM_ABR: \
|
||||
printf(" abr %s rtr %s", ipaddr_string(&lsp->ls_router), ipaddr_string(&lsp->ls_stateid)); break; \
|
||||
case LS_TYPE_ASE: \
|
||||
printf(" ase %s asbr %s", ipaddr_string(&lsp->ls_stateid), ipaddr_string(&lsp->ls_router)); break; \
|
||||
case LS_TYPE_GROUP: \
|
||||
printf(" group %s rtr %s", ipaddr_string(&lsp->ls_stateid), ipaddr_string(&lsp->ls_router)); break; \
|
||||
}
|
||||
|
||||
static int
|
||||
ospf_print_lshdr(register const struct lsa_hdr *lshp, const caddr_t end)
|
||||
{
|
||||
if ((caddr_t) (lshp + 1) > end) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf(" {"); /* } (ctags) */
|
||||
|
||||
if (!lshp->ls_type || lshp->ls_type >= LS_TYPE_MAX) {
|
||||
printf(" ??LS type %d?? }", /* { (ctags) */
|
||||
lshp->ls_type);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ospf_print_bits(ospf_option_bits, lshp->ls_options);
|
||||
ospf_print_seqage(ntohl(lshp->ls_seq),
|
||||
ntohs(lshp->ls_age));
|
||||
|
||||
LS_PRINT(lshp, lshp->ls_type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Print a single link state advertisement. If truncated return 1, else 0.
|
||||
*/
|
||||
|
||||
static int
|
||||
ospf_print_lsa(register const struct lsa *lsap, const caddr_t end)
|
||||
{
|
||||
register const char *ls_end;
|
||||
const struct rlalink *rlp;
|
||||
const struct tos_metric *tosp;
|
||||
const struct in_addr *ap;
|
||||
const struct aslametric *almp;
|
||||
const struct mcla *mcp;
|
||||
const u_int32 *lp;
|
||||
int j, k;
|
||||
|
||||
if (ospf_print_lshdr(&lsap->ls_hdr, end)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
ls_end = (caddr_t) lsap + ntohs(lsap->ls_hdr.ls_length);
|
||||
|
||||
if (ls_end > end) {
|
||||
printf(" }"); /* { (ctags) */
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (lsap->ls_hdr.ls_type) {
|
||||
case LS_TYPE_ROUTER:
|
||||
ospf_print_bits(ospf_rla_flag_bits, lsap->lsa_un.un_rla.rla_flags);
|
||||
|
||||
j = ntohs(lsap->lsa_un.un_rla.rla_count);
|
||||
rlp = lsap->lsa_un.un_rla.rla_link;
|
||||
while (j--) {
|
||||
struct rlalink *rln = (struct rlalink *) ((caddr_t) (rlp + 1) + ((rlp->link_toscount) * sizeof (struct tos_metric)));
|
||||
|
||||
if ((caddr_t) rln > ls_end) {
|
||||
break;
|
||||
}
|
||||
printf(" {"); /* } (ctags) */
|
||||
|
||||
switch (rlp->link_type) {
|
||||
case RLA_TYPE_VIRTUAL:
|
||||
printf(" virt");
|
||||
/* Fall through */
|
||||
|
||||
case RLA_TYPE_ROUTER:
|
||||
printf(" nbrid %s if %s",
|
||||
ipaddr_string(&rlp->link_id),
|
||||
ipaddr_string(&rlp->link_data));
|
||||
break;
|
||||
|
||||
case RLA_TYPE_TRANSIT:
|
||||
printf(" dr %s if %s",
|
||||
ipaddr_string(&rlp->link_id),
|
||||
ipaddr_string(&rlp->link_data));
|
||||
break;
|
||||
|
||||
case RLA_TYPE_STUB:
|
||||
printf(" net %s mask %s",
|
||||
ipaddr_string(&rlp->link_id),
|
||||
ipaddr_string(&rlp->link_data));
|
||||
break;
|
||||
|
||||
default:
|
||||
printf(" ??RouterLinksType %d?? }", /* { (ctags) */
|
||||
rlp->link_type);
|
||||
return 0;
|
||||
}
|
||||
printf(" tos 0 metric %d",
|
||||
ntohs(rlp->link_tos0metric));
|
||||
tosp = (struct tos_metric *) ((sizeof rlp->link_tos0metric) + (caddr_t) rlp);
|
||||
for (k = 0; k < rlp->link_toscount; k++, tosp++) {
|
||||
printf(" tos %d metric %d",
|
||||
ntohs(tosp->tos_type),
|
||||
ntohs(tosp->tos_metric));
|
||||
}
|
||||
printf(" }"); /* { (ctags) */
|
||||
rlp = rln;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_TYPE_NETWORK:
|
||||
printf(" mask %s rtrs",
|
||||
ipaddr_string(&lsap->lsa_un.un_nla.nla_mask));
|
||||
for (ap = lsap->lsa_un.un_nla.nla_router;
|
||||
(caddr_t) (ap + 1) <= ls_end;
|
||||
ap++) {
|
||||
printf(" %s",
|
||||
ipaddr_string(ap));
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_TYPE_SUM_IP:
|
||||
printf(" mask %s",
|
||||
ipaddr_string(&lsap->lsa_un.un_sla.sla_mask));
|
||||
/* Fall through */
|
||||
|
||||
case LS_TYPE_SUM_ABR:
|
||||
|
||||
for (lp = lsap->lsa_un.un_sla.sla_tosmetric;
|
||||
(caddr_t) (lp + 1) <= ls_end;
|
||||
lp++) {
|
||||
u_int32 ul = ntohl(*lp);
|
||||
|
||||
printf(" tos %d metric %d",
|
||||
(ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS,
|
||||
ul & SLA_MASK_METRIC);
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_TYPE_ASE:
|
||||
printf(" mask %s",
|
||||
ipaddr_string(&lsap->lsa_un.un_asla.asla_mask));
|
||||
|
||||
for (almp = lsap->lsa_un.un_asla.asla_metric;
|
||||
(caddr_t) (almp + 1) <= ls_end;
|
||||
almp++) {
|
||||
u_int32 ul = ntohl(almp->asla_tosmetric);
|
||||
|
||||
printf(" type %d tos %d metric %d",
|
||||
(ul & ASLA_FLAG_EXTERNAL) ? 2 : 1,
|
||||
(ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS,
|
||||
(ul & ASLA_MASK_METRIC));
|
||||
if (almp->asla_forward.s_addr) {
|
||||
printf(" forward %s",
|
||||
ipaddr_string(&almp->asla_forward));
|
||||
}
|
||||
if (almp->asla_tag.s_addr) {
|
||||
printf(" tag %s",
|
||||
ipaddr_string(&almp->asla_tag));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_TYPE_GROUP:
|
||||
/* Multicast extensions as of 23 July 1991 */
|
||||
for (mcp = lsap->lsa_un.un_mcla;
|
||||
(caddr_t) (mcp + 1) <= ls_end;
|
||||
mcp++) {
|
||||
switch (ntohl(mcp->mcla_vtype)) {
|
||||
case MCLA_VERTEX_ROUTER:
|
||||
printf(" rtr rtrid %s",
|
||||
ipaddr_string(&mcp->mcla_vid));
|
||||
break;
|
||||
|
||||
case MCLA_VERTEX_NETWORK:
|
||||
printf(" net dr %s",
|
||||
ipaddr_string(&mcp->mcla_vid));
|
||||
break;
|
||||
|
||||
default:
|
||||
printf(" ??VertexType %d??",
|
||||
ntohl(mcp->mcla_vtype));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf(" }"); /* { (ctags) */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ospf_print(register const u_char *bp, register int length,
|
||||
register const u_char *bp2)
|
||||
{
|
||||
register const struct ospfhdr *op;
|
||||
register const struct ip *ip;
|
||||
register const caddr_t end = (caddr_t)snapend;
|
||||
register const struct lsa *lsap;
|
||||
register const struct lsa_hdr *lshp;
|
||||
char sep;
|
||||
int i, j;
|
||||
const struct in_addr *ap;
|
||||
const struct lsr *lsrp;
|
||||
|
||||
op = (struct ospfhdr *)bp;
|
||||
ip = (struct ip *)bp2;
|
||||
/* Print the source and destination address */
|
||||
(void) printf("%s > %s:",
|
||||
ipaddr_string(&ip->ip_src),
|
||||
ipaddr_string(&ip->ip_dst));
|
||||
|
||||
if ((caddr_t) (&op->ospf_len + 1) > end) {
|
||||
goto trunc_test;
|
||||
}
|
||||
|
||||
/* If the type is valid translate it, or just print the type */
|
||||
/* value. If it's not valid, say so and return */
|
||||
if (op->ospf_type || op->ospf_type < OSPF_TYPE_MAX) {
|
||||
printf(" OSPFv%d-%s %d:",
|
||||
op->ospf_version,
|
||||
ospf_types[op->ospf_type],
|
||||
length);
|
||||
} else {
|
||||
printf(" ospf-v%d-??type %d?? %d:",
|
||||
op->ospf_version,
|
||||
op->ospf_type,
|
||||
length);
|
||||
return;
|
||||
}
|
||||
|
||||
if (length != ntohs(op->ospf_len)) {
|
||||
printf(" ??len %d??",
|
||||
ntohs(op->ospf_len));
|
||||
goto trunc_test;
|
||||
}
|
||||
|
||||
if ((caddr_t) (&op->ospf_routerid + 1) > end) {
|
||||
goto trunc_test;
|
||||
}
|
||||
|
||||
/* Print the routerid if it is not the same as the source */
|
||||
if (ip->ip_src.s_addr != op->ospf_routerid.s_addr) {
|
||||
printf(" rtrid %s",
|
||||
ipaddr_string(&op->ospf_routerid));
|
||||
}
|
||||
|
||||
if ((caddr_t) (&op->ospf_areaid + 1) > end) {
|
||||
goto trunc_test;
|
||||
}
|
||||
|
||||
if (op->ospf_areaid.s_addr) {
|
||||
printf(" area %s",
|
||||
ipaddr_string(&op->ospf_areaid));
|
||||
} else {
|
||||
printf(" backbone");
|
||||
}
|
||||
|
||||
if ((caddr_t) (op->ospf_authdata + OSPF_AUTH_SIZE) > end) {
|
||||
goto trunc_test;
|
||||
}
|
||||
|
||||
if (vflag) {
|
||||
/* Print authentication data (should we really do this?) */
|
||||
switch (ntohs(op->ospf_authtype)) {
|
||||
case OSPF_AUTH_NONE:
|
||||
break;
|
||||
|
||||
case OSPF_AUTH_SIMPLE:
|
||||
printf(" auth ");
|
||||
j = 0;
|
||||
for (i = 0; i < sizeof (op->ospf_authdata); i++) {
|
||||
if (!isprint(op->ospf_authdata[i])) {
|
||||
j = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j) {
|
||||
/* Print the auth-data as a string of octets */
|
||||
printf("%s.%s",
|
||||
ipaddr_string((struct in_addr *) op->ospf_authdata),
|
||||
ipaddr_string((struct in_addr *) &op->ospf_authdata[sizeof (struct in_addr)]));
|
||||
} else {
|
||||
/* Print the auth-data as a text string */
|
||||
printf("'%.8s'",
|
||||
op->ospf_authdata);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
printf(" ??authtype-%d??",
|
||||
ntohs(op->ospf_authtype));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Do rest according to version. */
|
||||
switch (op->ospf_version) {
|
||||
case 2:
|
||||
/* ospf version 2 */
|
||||
switch (op->ospf_type) {
|
||||
case OSPF_TYPE_UMD: /* Rob Coltun's special monitoring packets; do nothing */
|
||||
break;
|
||||
|
||||
case OSPF_TYPE_HELLO:
|
||||
if ((caddr_t) (&op->ospf_hello.hello_deadint + 1) > end) {
|
||||
break;
|
||||
}
|
||||
if (vflag) {
|
||||
ospf_print_bits(ospf_option_bits, op->ospf_hello.hello_options);
|
||||
printf(" mask %s int %d pri %d dead %d",
|
||||
ipaddr_string(&op->ospf_hello.hello_mask),
|
||||
ntohs(op->ospf_hello.hello_helloint),
|
||||
op->ospf_hello.hello_priority,
|
||||
ntohl(op->ospf_hello.hello_deadint));
|
||||
}
|
||||
|
||||
if ((caddr_t) (&op->ospf_hello.hello_dr + 1) > end) {
|
||||
break;
|
||||
}
|
||||
if (op->ospf_hello.hello_dr.s_addr) {
|
||||
printf(" dr %s",
|
||||
ipaddr_string(&op->ospf_hello.hello_dr));
|
||||
}
|
||||
|
||||
if ((caddr_t) (&op->ospf_hello.hello_bdr + 1) > end) {
|
||||
break;
|
||||
}
|
||||
if (op->ospf_hello.hello_bdr.s_addr) {
|
||||
printf(" bdr %s",
|
||||
ipaddr_string(&op->ospf_hello.hello_bdr));
|
||||
}
|
||||
|
||||
if (vflag) {
|
||||
if ((caddr_t) (op->ospf_hello.hello_neighbor + 1) > end) {
|
||||
break;
|
||||
}
|
||||
printf(" nbrs");
|
||||
for (ap = op->ospf_hello.hello_neighbor;
|
||||
(caddr_t) (ap + 1) <= end;
|
||||
ap++) {
|
||||
printf(" %s",
|
||||
ipaddr_string(ap));
|
||||
}
|
||||
}
|
||||
break; /* HELLO */
|
||||
|
||||
case OSPF_TYPE_DB:
|
||||
if ((caddr_t) (&op->ospf_db.db_seq + 1) > end) {
|
||||
break;
|
||||
}
|
||||
ospf_print_bits(ospf_option_bits, op->ospf_db.db_options);
|
||||
sep = ' ';
|
||||
if (op->ospf_db.db_flags & OSPF_DB_INIT) {
|
||||
printf("%cI",
|
||||
sep);
|
||||
sep = '/';
|
||||
}
|
||||
if (op->ospf_db.db_flags & OSPF_DB_MORE) {
|
||||
printf("%cM",
|
||||
sep);
|
||||
sep = '/';
|
||||
}
|
||||
if (op->ospf_db.db_flags & OSPF_DB_MASTER) {
|
||||
printf("%cMS",
|
||||
sep);
|
||||
sep = '/';
|
||||
}
|
||||
printf(" S %X",
|
||||
ntohl(op->ospf_db.db_seq));
|
||||
|
||||
if (vflag) {
|
||||
/* Print all the LS adv's */
|
||||
lshp = op->ospf_db.db_lshdr;
|
||||
|
||||
while (!ospf_print_lshdr(lshp, end)) {
|
||||
printf(" }"); /* { (ctags) */
|
||||
lshp++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case OSPF_TYPE_LSR:
|
||||
if (vflag) {
|
||||
for (lsrp = op->ospf_lsr; (caddr_t) (lsrp+1) <= end; lsrp++) {
|
||||
int32 type;
|
||||
|
||||
if ((caddr_t) (lsrp + 1) > end) {
|
||||
break;
|
||||
}
|
||||
|
||||
printf(" {"); /* } (ctags) */
|
||||
if (!(type = lsrp->ls_type) || type >= LS_TYPE_MAX) {
|
||||
printf(" ??LinkStateType %d }", /* { (ctags) */
|
||||
type);
|
||||
printf(" }"); /* { (ctags) */
|
||||
break;
|
||||
}
|
||||
|
||||
LS_PRINT(lsrp, type);
|
||||
printf(" }"); /* { (ctags) */
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case OSPF_TYPE_LSU:
|
||||
if (vflag) {
|
||||
lsap = op->ospf_lsu.lsu_lsa;
|
||||
i = ntohl(op->ospf_lsu.lsu_count);
|
||||
|
||||
while (i-- &&
|
||||
!ospf_print_lsa(lsap, end)) {
|
||||
lsap = (struct lsa *) ((caddr_t) lsap + ntohs(lsap->ls_hdr.ls_length));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case OSPF_TYPE_LSA:
|
||||
if (vflag) {
|
||||
lshp = op->ospf_lsa.lsa_lshdr;
|
||||
|
||||
while (!ospf_print_lshdr(lshp, end)) {
|
||||
printf(" }"); /* { (ctags) */
|
||||
lshp++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} /* end switch on v2 packet type */
|
||||
break;
|
||||
|
||||
default:
|
||||
printf(" ospf [version %d]",
|
||||
op->ospf_version);
|
||||
break;
|
||||
} /* end switch on version */
|
||||
|
||||
trunc_test:
|
||||
if ((snapend - bp) < length) {
|
||||
printf(" [|]");
|
||||
}
|
||||
|
||||
return; /* from ospf_print */
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#)$Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/print-ppp.c,v 1.2 1995/03/08 12:52:40 olah Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef PPP
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <pcap.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <netinet/if_ether.h>
|
||||
#include "ethertype.h"
|
||||
|
||||
#include <net/ppp_defs.h>
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
struct protonames {
|
||||
u_short protocol;
|
||||
char *name;
|
||||
};
|
||||
|
||||
static struct protonames protonames[] = {
|
||||
/*
|
||||
* Protocol field values.
|
||||
*/
|
||||
PPP_IP, "IP", /* Internet Protocol */
|
||||
PPP_XNS, "XNS", /* Xerox NS */
|
||||
PPP_IPX, "IPX", /* IPX Datagram (RFC1552) */
|
||||
PPP_VJC_COMP, "VJC_UNCOMP", /* VJ compressed TCP */
|
||||
PPP_VJC_UNCOMP, "VJC_UNCOMP", /* VJ uncompressed TCP */
|
||||
PPP_COMP, "COMP", /* compressed packet */
|
||||
PPP_IPCP, "IPCP", /* IP Control Protocol */
|
||||
PPP_IPXCP, "IPXCP", /* IPX Control Protocol (RFC1552) */
|
||||
PPP_CCP, "CCP", /* Compression Control Protocol */
|
||||
PPP_LCP, "LCP", /* Link Control Protocol */
|
||||
PPP_PAP, "PAP", /* Password Authentication Protocol */
|
||||
PPP_LQR, "LQR", /* Link Quality Report protocol */
|
||||
PPP_CHAP, "CHAP", /* Cryptographic Handshake Auth. Proto*/
|
||||
};
|
||||
|
||||
void
|
||||
ppp_hdlc_print(const u_char *p, int length)
|
||||
{
|
||||
int proto = PPP_PROTOCOL(p);
|
||||
int i;
|
||||
|
||||
printf("%4d %02x ", length, PPP_CONTROL(p));
|
||||
|
||||
for (i = (sizeof(protonames) / sizeof(protonames[0])) - 1; i >= 0; --i){
|
||||
if (proto == protonames[i].protocol) {
|
||||
printf("%s: ", protonames[i].name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i < 0)
|
||||
printf("%04x: ", proto);
|
||||
}
|
||||
|
||||
void
|
||||
ppp_if_print(u_char *user, const struct pcap_pkthdr *h,
|
||||
register const u_char *p)
|
||||
{
|
||||
register int length = h->len;
|
||||
register int caplen = h->caplen;
|
||||
|
||||
ts_print(&h->ts);
|
||||
|
||||
if (caplen < PPP_HDRLEN) {
|
||||
printf("[|ppp]");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Some printers want to get back at the link level addresses,
|
||||
* and/or check that they're not walking off the end of the packet.
|
||||
* Rather than pass them all the way down, we set these globals.
|
||||
*/
|
||||
packetp = p;
|
||||
snapend = p + caplen;
|
||||
|
||||
if (eflag)
|
||||
ppp_hdlc_print(p, length);
|
||||
|
||||
length -= PPP_HDRLEN;
|
||||
|
||||
switch(PPP_PROTOCOL(p)) {
|
||||
case PPP_IP:
|
||||
case ETHERTYPE_IP:
|
||||
ip_print((const u_char *)(p + PPP_HDRLEN), length);
|
||||
break;
|
||||
case PPP_IPX:
|
||||
case ETHERTYPE_IPX:
|
||||
ipx_print((const u_char *)(p + PPP_HDRLEN), length);
|
||||
break;
|
||||
|
||||
default:
|
||||
if(!eflag)
|
||||
ppp_hdlc_print(p, length);
|
||||
if(!xflag)
|
||||
default_print((const u_char *)(p + PPP_HDRLEN),
|
||||
caplen - PPP_HDRLEN);
|
||||
}
|
||||
|
||||
if (xflag)
|
||||
default_print((const u_char *)(p + PPP_HDRLEN),
|
||||
caplen - PPP_HDRLEN);
|
||||
out:
|
||||
putchar('\n');
|
||||
}
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
void
|
||||
ppp_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
|
||||
{
|
||||
error("not configured for ppp");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
#endif
|
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/print-rip.c,v 1.4 1995/03/08 12:52:40 olah Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
|
||||
#include <protocols/routed.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
static void
|
||||
rip_entry_print(register const struct netinfo *ni)
|
||||
{
|
||||
if (ni->rip_dst.sa_family != AF_INET) {
|
||||
register int i;
|
||||
|
||||
printf(" [family %d:", ni->rip_dst.sa_family);
|
||||
for (i = 0; i < 14; i += 2)
|
||||
printf(" %02x%02x", (u_char)ni->rip_dst.sa_data[i],
|
||||
(u_char)ni->rip_dst.sa_data[i+1]);
|
||||
printf("]");
|
||||
} else {
|
||||
register struct sockaddr_in *sin =
|
||||
(struct sockaddr_in *)&ni->rip_dst;
|
||||
printf(" %s", ipaddr_string(&sin->sin_addr));
|
||||
if (sin->sin_port)
|
||||
printf(" [port %d]", sin->sin_port);
|
||||
}
|
||||
printf("(%d)", ntohl(ni->rip_metric));
|
||||
}
|
||||
|
||||
void
|
||||
rip_print(const u_char *dat, int length)
|
||||
{
|
||||
register const struct rip *rp = (struct rip *)dat;
|
||||
register const struct netinfo *ni;
|
||||
register int amt = snapend - dat;
|
||||
register int i = min(length, amt) -
|
||||
(sizeof(struct rip) - sizeof(struct netinfo));
|
||||
int j;
|
||||
int trunc;
|
||||
|
||||
if (i < 0)
|
||||
return;
|
||||
|
||||
switch (rp->rip_cmd) {
|
||||
|
||||
case RIPCMD_REQUEST:
|
||||
printf(" rip-req %d", length);
|
||||
break;
|
||||
case RIPCMD_RESPONSE:
|
||||
j = length / sizeof(*ni);
|
||||
if (j * sizeof(*ni) != length - 4)
|
||||
printf(" rip-resp %d[%d]:", j, length);
|
||||
else
|
||||
printf(" rip-resp %d:", j);
|
||||
trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
|
||||
for (ni = rp->rip_nets; (i -= sizeof(*ni)) >= 0; ++ni)
|
||||
rip_entry_print(ni);
|
||||
if (trunc)
|
||||
printf("[|rip]");
|
||||
break;
|
||||
case RIPCMD_TRACEON:
|
||||
printf(" rip-traceon %d: \"%s\"", length, rp->rip_tracefile);
|
||||
break;
|
||||
case RIPCMD_TRACEOFF:
|
||||
printf(" rip-traceoff %d", length);
|
||||
break;
|
||||
case RIPCMD_POLL:
|
||||
printf(" rip-poll %d", length);
|
||||
break;
|
||||
case RIPCMD_POLLENTRY:
|
||||
printf(" rip-pollentry %d", length);
|
||||
break;
|
||||
default:
|
||||
printf(" rip-%d ?? %d", rp->rip_cmd, length);
|
||||
break;
|
||||
}
|
||||
if (rp->rip_vers != RIPVERSION)
|
||||
printf(" [vers %d]", rp->rip_vers);
|
||||
}
|
@ -1,243 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#)$Header: print-sl.c,v 1.28 94/06/10 17:01:38 mccanne Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef CSLIP
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
|
||||
#include <net/slcompress.h>
|
||||
#include <net/slip.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <pcap.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
static int lastlen[2][256];
|
||||
static int lastconn = 255;
|
||||
|
||||
static void sliplink_print(const u_char *, const struct ip *, int);
|
||||
static void compressed_sl_print(const u_char *, const struct ip *, int, int);
|
||||
|
||||
void
|
||||
sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
|
||||
{
|
||||
register int caplen = h->caplen;
|
||||
register int length = h->len;
|
||||
register const struct ip *ip;
|
||||
|
||||
ts_print(&h->ts);
|
||||
|
||||
if (caplen < SLIP_HDRLEN) {
|
||||
printf("[|slip]");
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
* Some printers want to get back at the link level addresses,
|
||||
* and/or check that they're not walking off the end of the packet.
|
||||
* Rather than pass them all the way down, we set these globals.
|
||||
*/
|
||||
packetp = p;
|
||||
snapend = p + caplen;
|
||||
|
||||
length -= SLIP_HDRLEN;
|
||||
|
||||
ip = (struct ip *)(p + SLIP_HDRLEN);
|
||||
|
||||
if (eflag)
|
||||
sliplink_print(p, ip, length);
|
||||
|
||||
ip_print((u_char *)ip, length);
|
||||
|
||||
if (xflag)
|
||||
default_print((u_char *)ip, caplen - SLIP_HDRLEN);
|
||||
out:
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
static void
|
||||
sliplink_print(register const u_char *p, register const struct ip *ip,
|
||||
register int length)
|
||||
{
|
||||
int dir;
|
||||
int hlen;
|
||||
|
||||
dir = p[SLX_DIR];
|
||||
putchar(dir == SLIPDIR_IN ? 'I' : 'O');
|
||||
putchar(' ');
|
||||
|
||||
if (nflag) {
|
||||
/* XXX just dump the header */
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 15; ++i)
|
||||
printf("%02x.", p[SLX_CHDR + i]);
|
||||
printf("%02x: ", p[SLX_CHDR + 15]);
|
||||
return;
|
||||
}
|
||||
switch (p[SLX_CHDR] & 0xf0) {
|
||||
|
||||
case TYPE_IP:
|
||||
printf("ip %d: ", length + SLIP_HDRLEN);
|
||||
break;
|
||||
|
||||
case TYPE_UNCOMPRESSED_TCP:
|
||||
/*
|
||||
* The connection id is stode in the IP protcol field.
|
||||
*/
|
||||
lastconn = ip->ip_p;
|
||||
hlen = ip->ip_hl;
|
||||
hlen += ((struct tcphdr *)&((int *)ip)[hlen])->th_off;
|
||||
lastlen[dir][lastconn] = length - (hlen << 2);
|
||||
printf("utcp %d: ", lastconn);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (p[SLX_CHDR] & TYPE_COMPRESSED_TCP) {
|
||||
compressed_sl_print(&p[SLX_CHDR], ip,
|
||||
length, dir);
|
||||
printf(": ");
|
||||
} else
|
||||
printf("slip-%d!: ", p[SLX_CHDR]);
|
||||
}
|
||||
}
|
||||
|
||||
static const u_char *
|
||||
print_sl_change(const char *str, register const u_char *cp)
|
||||
{
|
||||
register u_int i;
|
||||
|
||||
if ((i = *cp++) == 0) {
|
||||
i = (cp[0] << 8) | cp[1];
|
||||
cp += 2;
|
||||
}
|
||||
printf(" %s%d", str, i);
|
||||
return (cp);
|
||||
}
|
||||
|
||||
static const u_char *
|
||||
print_sl_winchange(register const u_char *cp)
|
||||
{
|
||||
register short i;
|
||||
|
||||
if ((i = *cp++) == 0) {
|
||||
i = (cp[0] << 8) | cp[1];
|
||||
cp += 2;
|
||||
}
|
||||
if (i >= 0)
|
||||
printf(" W+%d", i);
|
||||
else
|
||||
printf(" W%d", i);
|
||||
return (cp);
|
||||
}
|
||||
|
||||
static void
|
||||
compressed_sl_print(const u_char *chdr, const struct ip *ip,
|
||||
int length, int dir)
|
||||
{
|
||||
register const u_char *cp = chdr;
|
||||
register u_int flags;
|
||||
int hlen;
|
||||
|
||||
flags = *cp++;
|
||||
if (flags & NEW_C) {
|
||||
lastconn = *cp++;
|
||||
printf("ctcp %d", lastconn);
|
||||
} else
|
||||
printf("ctcp *");
|
||||
|
||||
/* skip tcp checksum */
|
||||
cp += 2;
|
||||
|
||||
switch (flags & SPECIALS_MASK) {
|
||||
case SPECIAL_I:
|
||||
printf(" *SA+%d", lastlen[dir][lastconn]);
|
||||
break;
|
||||
|
||||
case SPECIAL_D:
|
||||
printf(" *S+%d", lastlen[dir][lastconn]);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (flags & NEW_U)
|
||||
cp = print_sl_change("U=", cp);
|
||||
if (flags & NEW_W)
|
||||
cp = print_sl_winchange(cp);
|
||||
if (flags & NEW_A)
|
||||
cp = print_sl_change("A+", cp);
|
||||
if (flags & NEW_S)
|
||||
cp = print_sl_change("S+", cp);
|
||||
break;
|
||||
}
|
||||
if (flags & NEW_I)
|
||||
cp = print_sl_change("I+", cp);
|
||||
|
||||
/*
|
||||
* 'hlen' is the length of the uncompressed TCP/IP header (in words).
|
||||
* 'cp - chdr' is the length of the compressed header.
|
||||
* 'length - hlen' is the amount of data in the packet.
|
||||
*/
|
||||
hlen = ip->ip_hl;
|
||||
hlen += ((struct tcphdr *)&((int32 *)ip)[hlen])->th_off;
|
||||
lastlen[dir][lastconn] = length - (hlen << 2);
|
||||
printf(" %d (%d)", lastlen[dir][lastconn], cp - chdr);
|
||||
}
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
void
|
||||
sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
|
||||
{
|
||||
|
||||
error("not configured for slip");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1992, 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: print-sunrpc.c,v 1.12 94/06/14 20:18:48 leres Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
|
||||
#ifdef SOLARIS
|
||||
#include <tiuser.h>
|
||||
#endif
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/auth.h>
|
||||
#include <rpc/auth_unix.h>
|
||||
#include <rpc/svc.h>
|
||||
#include <rpc/rpc_msg.h>
|
||||
#include <rpc/pmap_prot.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
#include "extract.h" /* must come after interface.h */
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
static void bswap(u_int32 *, u_int);
|
||||
#endif
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
/*
|
||||
* Byte swap an array of n 32-bit words.
|
||||
* Assume input is word-aligned.
|
||||
* Check that buffer is bounded by "snapend".
|
||||
*/
|
||||
static void
|
||||
bswap(register u_int32 *bp, register u_int n)
|
||||
{
|
||||
register int nwords = ((char *)snapend - (char *)bp) / sizeof(*bp);
|
||||
|
||||
if (nwords > n)
|
||||
nwords = n;
|
||||
for (; --nwords >= 0; ++bp)
|
||||
*bp = ntohl(*bp);
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct token proc2str[] = {
|
||||
{ PMAPPROC_NULL, "null" },
|
||||
{ PMAPPROC_SET, "set" },
|
||||
{ PMAPPROC_UNSET, "unset" },
|
||||
{ PMAPPROC_GETPORT, "getport" },
|
||||
{ PMAPPROC_DUMP, "dump" },
|
||||
{ PMAPPROC_CALLIT, "call" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
void
|
||||
sunrpcrequest_print(register const u_char *bp, register int length,
|
||||
register const u_char *bp2)
|
||||
{
|
||||
register const struct rpc_msg *rp;
|
||||
register const struct ip *ip;
|
||||
|
||||
rp = (struct rpc_msg *)bp;
|
||||
ip = (struct ip *)bp2;
|
||||
|
||||
if (!nflag)
|
||||
(void)printf("%s.%x > %s.sunrpc: %d",
|
||||
ipaddr_string(&ip->ip_src),
|
||||
ntohl(rp->rm_xid),
|
||||
ipaddr_string(&ip->ip_dst),
|
||||
length);
|
||||
else
|
||||
(void)printf("%s.%x > %s.%x: %d",
|
||||
ipaddr_string(&ip->ip_src),
|
||||
ntohl(rp->rm_xid),
|
||||
ipaddr_string(&ip->ip_dst),
|
||||
PMAPPORT,
|
||||
length);
|
||||
printf(" %s", tok2str(proc2str, " proc #%d",
|
||||
ntohl(rp->rm_call.cb_proc)));
|
||||
}
|
||||
|
@ -1,307 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/print-tcp.c,v 1.3 1995/03/08 13:13:01 olah Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
#ifndef TCPOPT_WSCALE
|
||||
#define TCPOPT_WSCALE 3 /* window scale factor (rfc1072) */
|
||||
#endif
|
||||
#ifndef TCPOPT_SACKOK
|
||||
#define TCPOPT_SACKOK 4 /* selective ack ok (rfc1072) */
|
||||
#endif
|
||||
#ifndef TCPOPT_SACK
|
||||
#define TCPOPT_SACK 5 /* selective ack (rfc1072) */
|
||||
#endif
|
||||
#ifndef TCPOPT_ECHO
|
||||
#define TCPOPT_ECHO 6 /* echo (rfc1072) */
|
||||
#endif
|
||||
#ifndef TCPOPT_ECHOREPLY
|
||||
#define TCPOPT_ECHOREPLY 7 /* echo (rfc1072) */
|
||||
#endif
|
||||
#ifndef TCPOPT_TIMESTAMP
|
||||
#define TCPOPT_TIMESTAMP 8 /* timestamps (rfc1323) */
|
||||
#endif
|
||||
#ifndef TCPOPT_CC
|
||||
#define TCPOPT_CC 11 /* connection count (rfc1644) */
|
||||
#endif
|
||||
#ifndef TCPOPT_CCNEW
|
||||
#define TCPOPT_CCNEW 12 /* connection count new (rfc1644) */
|
||||
#endif
|
||||
#ifndef TCPOPT_CCECHO
|
||||
#define TCPOPT_CCECHO 13 /* connection count echo (rfc1644) */
|
||||
#endif
|
||||
|
||||
struct opt_table {
|
||||
int len; /* option length, zero if unknown */
|
||||
const char *nam; /* option name */
|
||||
};
|
||||
|
||||
static struct opt_table tcp_opts[] = {
|
||||
{ 1, "eol" },
|
||||
{ 1, "nop" },
|
||||
{ 4, "mss" },
|
||||
{ 3, "wscale" },
|
||||
{ 2, "sackOK" },
|
||||
{ 0, "sack" }, /* XXX sack: don't know how long */
|
||||
{ 6, "echo" },
|
||||
{ 6, "echoreply" },
|
||||
{10, "timestamp" },
|
||||
{ 0, "opt-%d:" },
|
||||
{ 0, "opt-%d:" },
|
||||
{ 6, "cc" },
|
||||
{ 6, "ccnew" },
|
||||
{ 6, "ccecho" },
|
||||
{ 0, "opt-%d:" }, /* last entry must be an unknown option */
|
||||
};
|
||||
#define MAXTCPOPT (sizeof(tcp_opts)/sizeof(tcp_opts[0])-1)
|
||||
|
||||
struct tha {
|
||||
struct in_addr src;
|
||||
struct in_addr dst;
|
||||
u_int port;
|
||||
};
|
||||
|
||||
struct tcp_seq_hash {
|
||||
struct tcp_seq_hash *nxt;
|
||||
struct tha addr;
|
||||
tcp_seq seq;
|
||||
tcp_seq ack;
|
||||
};
|
||||
|
||||
#define TSEQ_HASHSIZE 919
|
||||
|
||||
static struct tcp_seq_hash tcp_seq_hash[TSEQ_HASHSIZE];
|
||||
|
||||
|
||||
void
|
||||
tcp_print(register const u_char *bp, register int length,
|
||||
register const u_char *bp2)
|
||||
{
|
||||
register const struct tcphdr *tp;
|
||||
register const struct ip *ip;
|
||||
register u_char flags;
|
||||
register int hlen;
|
||||
u_short sport, dport, win, urp;
|
||||
u_int32 seq, ack;
|
||||
|
||||
tp = (struct tcphdr *)bp;
|
||||
ip = (struct ip *)bp2;
|
||||
if ((const u_char *)(tp + 1) > snapend) {
|
||||
printf("[|tcp]");
|
||||
return;
|
||||
}
|
||||
if (length < sizeof(struct tcphdr)) {
|
||||
(void)printf("truncated-tcp %d", length);
|
||||
return;
|
||||
}
|
||||
|
||||
sport = ntohs(tp->th_sport);
|
||||
dport = ntohs(tp->th_dport);
|
||||
seq = ntohl(tp->th_seq);
|
||||
ack = ntohl(tp->th_ack);
|
||||
win = ntohs(tp->th_win);
|
||||
urp = ntohs(tp->th_urp);
|
||||
|
||||
(void)printf("%s.%s > %s.%s: ",
|
||||
ipaddr_string(&ip->ip_src), tcpport_string(sport),
|
||||
ipaddr_string(&ip->ip_dst), tcpport_string(dport));
|
||||
|
||||
if (qflag) {
|
||||
(void)printf("tcp %d", length - tp->th_off * 4);
|
||||
return;
|
||||
}
|
||||
if ((flags = tp->th_flags) & (TH_SYN|TH_FIN|TH_RST|TH_PUSH)) {
|
||||
if (flags & TH_SYN)
|
||||
putchar('S');
|
||||
if (flags & TH_FIN)
|
||||
putchar('F');
|
||||
if (flags & TH_RST)
|
||||
putchar('R');
|
||||
if (flags & TH_PUSH)
|
||||
putchar('P');
|
||||
} else
|
||||
putchar('.');
|
||||
|
||||
if (!Sflag && (flags & TH_ACK)) {
|
||||
register struct tcp_seq_hash *th;
|
||||
register int rev;
|
||||
struct tha tha;
|
||||
/*
|
||||
* Find (or record) the initial sequence numbers for
|
||||
* this conversation. (we pick an arbitrary
|
||||
* collating order so there's only one entry for
|
||||
* both directions).
|
||||
*/
|
||||
if (sport < dport ||
|
||||
(sport == dport &&
|
||||
ip->ip_src.s_addr < ip->ip_dst.s_addr)) {
|
||||
tha.src = ip->ip_src, tha.dst = ip->ip_dst;
|
||||
tha.port = sport << 16 | dport;
|
||||
rev = 0;
|
||||
} else {
|
||||
tha.src = ip->ip_dst, tha.dst = ip->ip_src;
|
||||
tha.port = dport << 16 | sport;
|
||||
rev = 1;
|
||||
}
|
||||
|
||||
for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE];
|
||||
th->nxt; th = th->nxt)
|
||||
if (!bcmp((char *)&tha, (char *)&th->addr,
|
||||
sizeof(th->addr)))
|
||||
break;
|
||||
|
||||
if (!th->nxt || flags & TH_SYN) {
|
||||
/* didn't find it or new conversation */
|
||||
if (!th->nxt)
|
||||
th->nxt = (struct tcp_seq_hash *)
|
||||
calloc(1, sizeof (*th));
|
||||
th->addr = tha;
|
||||
if (rev)
|
||||
th->ack = seq, th->seq = ack - 1;
|
||||
else
|
||||
th->seq = seq, th->ack = ack - 1;
|
||||
} else {
|
||||
if (rev)
|
||||
seq -= th->ack, ack -= th->seq;
|
||||
else
|
||||
seq -= th->seq, ack -= th->ack;
|
||||
}
|
||||
}
|
||||
hlen = tp->th_off * 4;
|
||||
length -= hlen;
|
||||
if (length > 0 || flags & (TH_SYN | TH_FIN | TH_RST))
|
||||
(void)printf(" %u:%u(%d)", seq, seq + length, length);
|
||||
if (flags & TH_ACK)
|
||||
(void)printf(" ack %u", ack);
|
||||
|
||||
(void)printf(" win %d", win);
|
||||
|
||||
if (flags & TH_URG)
|
||||
(void)printf(" urg %d", urp);
|
||||
/*
|
||||
* Handle any options.
|
||||
*/
|
||||
if ((hlen -= sizeof(struct tcphdr)) > 0) {
|
||||
register const u_char *cp = (const u_char *)tp + sizeof(*tp);
|
||||
int i;
|
||||
char ch = '<';
|
||||
char lch = '>';
|
||||
|
||||
putchar(' ');
|
||||
/* adjust length if necessary */
|
||||
if (cp + hlen > snapend) {
|
||||
hlen = snapend - cp;
|
||||
lch = '|';
|
||||
}
|
||||
while (hlen > 0) {
|
||||
register struct opt_table *opt;
|
||||
|
||||
putchar(ch);
|
||||
ch = ',';
|
||||
|
||||
opt = *cp < MAXTCPOPT ?
|
||||
&tcp_opts[*cp] : &tcp_opts[MAXTCPOPT];
|
||||
(void)printf(opt->nam, *cp);
|
||||
|
||||
/* eol and nop have no length */
|
||||
if (opt->len == 1) {
|
||||
hlen--, cp++;
|
||||
continue;
|
||||
}
|
||||
/* quit if options are truncated */
|
||||
if ((hlen == 1) ||
|
||||
(opt->len != 0 && hlen < opt->len) ||
|
||||
(opt->len == 0 && hlen < *(cp + 1))) {
|
||||
lch = '|';
|
||||
break;
|
||||
}
|
||||
/* check if optlen in segment is what we assume */
|
||||
if (opt->len != 0 && *(cp + 1) != opt->len) {
|
||||
register int l = *(cp + 1);
|
||||
|
||||
(void)printf("[len %d]", l);
|
||||
hlen -= l;
|
||||
cp += l;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* print the option body */
|
||||
switch (*cp) {
|
||||
case TCPOPT_MAXSEG:
|
||||
(void)printf(" %d", cp[2] << 8 | cp[3]);
|
||||
break;
|
||||
case TCPOPT_WSCALE:
|
||||
(void)printf(" %d", cp[2]);
|
||||
break;
|
||||
case TCPOPT_SACKOK:
|
||||
break;
|
||||
case TCPOPT_ECHO:
|
||||
case TCPOPT_ECHOREPLY:
|
||||
case TCPOPT_CC:
|
||||
case TCPOPT_CCNEW:
|
||||
case TCPOPT_CCECHO:
|
||||
(void)printf(" %lu",
|
||||
cp[2] << 24 | cp[3] << 16 |
|
||||
cp[4] << 8 | cp[5]);
|
||||
break;
|
||||
case TCPOPT_TIMESTAMP:
|
||||
(void)printf(" %lu %lu",
|
||||
cp[2] << 24 | cp[3] << 16 |
|
||||
cp[4] << 8 | cp[5],
|
||||
cp[6] << 24 | cp[7] << 16 |
|
||||
cp[8] << 8 | cp[9]);
|
||||
break;
|
||||
default:
|
||||
hlen -= *++cp;
|
||||
for (i = *cp++ - 2; i > 0; --i)
|
||||
(void)printf("%02x", *cp++);
|
||||
break;
|
||||
}
|
||||
/* adjust length */
|
||||
hlen -= opt->len;
|
||||
cp += opt->len;
|
||||
}
|
||||
putchar(lch);
|
||||
}
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* Format and print trivial file transfer protocol packets.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: print-tftp.c,v 1.20 94/06/14 20:18:49 leres Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <arpa/tftp.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
/* op code to string mapping */
|
||||
static struct token op2str[] = {
|
||||
{ RRQ, "RRQ" }, /* read request */
|
||||
{ WRQ, "WRQ" }, /* write request */
|
||||
{ DATA, "DATA" }, /* data packet */
|
||||
{ ACK, "ACK" }, /* acknowledgement */
|
||||
{ ERROR, "ERROR" }, /* error code */
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* error code to string mapping */
|
||||
static struct token err2str[] = {
|
||||
{ EUNDEF, "EUNDEF" }, /* not defined */
|
||||
{ ENOTFOUND, "ENOTFOUND" }, /* file not found */
|
||||
{ EACCESS, "EACCESS" }, /* access violation */
|
||||
{ ENOSPACE, "ENOSPACE" }, /* disk full or allocation exceeded */
|
||||
{ EBADOP, "EBADOP" }, /* illegal TFTP operation */
|
||||
{ EBADID, "EBADID" }, /* unknown transfer ID */
|
||||
{ EEXISTS, "EEXISTS" }, /* file already exists */
|
||||
{ ENOUSER, "ENOUSER" }, /* no such user */
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
* Print trivial file transfer program requests
|
||||
*/
|
||||
void
|
||||
tftp_print(register const u_char *bp, int length)
|
||||
{
|
||||
register const struct tftphdr *tp;
|
||||
register const char *cp;
|
||||
register const u_char *ep, *p;
|
||||
register int opcode;
|
||||
#define TCHECK(var, l) if ((u_char *)&(var) > ep - l) goto trunc
|
||||
static char tstr[] = " [|tftp]";
|
||||
|
||||
tp = (const struct tftphdr *)bp;
|
||||
/* 'ep' points to the end of avaible data. */
|
||||
ep = snapend;
|
||||
|
||||
/* Print length */
|
||||
printf(" %d", length);
|
||||
|
||||
/* Print tftp request type */
|
||||
TCHECK(tp->th_opcode, sizeof(tp->th_opcode));
|
||||
opcode = ntohs(tp->th_opcode);
|
||||
cp = tok2str(op2str, "tftp-#%d", opcode);
|
||||
printf(" %s", cp);
|
||||
/* Bail if bogus opcode */
|
||||
if (*cp == 't')
|
||||
return;
|
||||
|
||||
switch (opcode) {
|
||||
|
||||
case RRQ:
|
||||
case WRQ:
|
||||
putchar(' ');
|
||||
/*
|
||||
* XXX Not all arpa/tftp.h's specify th_stuff as any
|
||||
* array; use address of th_block instead
|
||||
*/
|
||||
#ifdef notdef
|
||||
p = (u_char *)tp->th_stuff;
|
||||
#else
|
||||
p = (u_char *)&tp->th_block;
|
||||
#endif
|
||||
if (fn_print(p, ep)) {
|
||||
fputs(&tstr[1], stdout);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case DATA:
|
||||
TCHECK(tp->th_block, sizeof(tp->th_block));
|
||||
printf(" block %d", ntohs(tp->th_block));
|
||||
break;
|
||||
|
||||
case ACK:
|
||||
break;
|
||||
|
||||
case ERROR:
|
||||
/* Print error code string */
|
||||
TCHECK(tp->th_code, sizeof(tp->th_code));
|
||||
printf(" %s ", tok2str(err2str, "tftp-err-#%d",
|
||||
ntohs(tp->th_code)));
|
||||
/* Print error message string */
|
||||
if (fn_print((const u_char *)tp->th_data, ep)) {
|
||||
fputs(&tstr[1], stdout);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
/* We shouldn't get here */
|
||||
printf("(unknown #%d)", opcode);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
trunc:
|
||||
fputs(tstr, stdout);
|
||||
#undef TCHECK
|
||||
}
|
@ -1,271 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"$Id: print-udp.c,v 1.4 1995/08/29 19:48:11 wollman Exp $";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
|
||||
#undef NOERROR /* Solaris sucks */
|
||||
#include <arpa/nameser.h>
|
||||
#include <arpa/tftp.h>
|
||||
|
||||
#ifdef SOLARIS
|
||||
#include <tiuser.h>
|
||||
#endif
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/auth.h>
|
||||
#include <rpc/auth_unix.h>
|
||||
#include <rpc/svc.h>
|
||||
#include <rpc/rpc_msg.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
#include "appletalk.h"
|
||||
|
||||
#include "nfs.h"
|
||||
#include "bootp.h"
|
||||
|
||||
extern int packettype;
|
||||
|
||||
static void
|
||||
vat_print(const void *hdr, int len, register const struct udphdr *up)
|
||||
{
|
||||
/* vat/vt audio */
|
||||
u_int ts = *(u_short *)hdr;
|
||||
if ((ts & 0xf060) != 0) {
|
||||
/* probably vt */
|
||||
(void)printf(" udp/vt %d %d / %d",
|
||||
ntohs(up->uh_ulen) - sizeof(*up),
|
||||
ts & 0x3ff, ts >> 10);
|
||||
} else {
|
||||
/* probably vat */
|
||||
u_int i0 = ((u_int *)hdr)[0];
|
||||
u_int i1 = ((u_int *)hdr)[1];
|
||||
printf(" udp/vat %d c%d %u%s",
|
||||
ntohs(up->uh_ulen) - sizeof(*up) - 8,
|
||||
i0 & 0xffff,
|
||||
i1, i0 & 0x800000? "*" : "");
|
||||
/* audio format */
|
||||
if (i0 & 0x1f0000)
|
||||
printf(" f%d", (i0 >> 16) & 0x1f);
|
||||
if (i0 & 0x3f000000)
|
||||
printf(" s%d", (i0 >> 24) & 0x3f);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
rtp_print(const void *hdr, int len, register const struct udphdr *up)
|
||||
{
|
||||
/* rtp v1 video */
|
||||
u_int *ip = (u_int *)hdr;
|
||||
u_int i0 = ((u_int *)hdr)[0];
|
||||
u_int i1 = ((u_int *)hdr)[1];
|
||||
u_int hasopt = i0 & 0x800000;
|
||||
u_int contype = (i0 >> 16) & 0x3f;
|
||||
printf(" udp/rtp %d c%d %s%s %d",
|
||||
ntohs(up->uh_ulen) - sizeof(*up) - 8,
|
||||
contype,
|
||||
hasopt? "+" : "",
|
||||
i0 & 0x400000? "*" : "",
|
||||
i0 & 0xffff);
|
||||
if (contype == 31) {
|
||||
ip += 2;
|
||||
len >>= 2;
|
||||
len -= 2;
|
||||
if (hasopt) {
|
||||
u_int i2, optlen;
|
||||
do {
|
||||
i2 = ip[0];
|
||||
optlen = (i2 >> 16) & 0xff;
|
||||
if (optlen == 0 || optlen > len) {
|
||||
printf(" !opt");
|
||||
return;
|
||||
}
|
||||
ip += optlen;
|
||||
} while ((int)i2 >= 0);
|
||||
}
|
||||
printf(" 0x%04x", ip[0] >> 16);
|
||||
}
|
||||
if (vflag)
|
||||
printf(" %u", i1);
|
||||
}
|
||||
|
||||
/* XXX probably should use getservbyname() and cache answers */
|
||||
#define TFTP_PORT 69 /*XXX*/
|
||||
#define KERBEROS_PORT 80 /*XXX*/
|
||||
#define SUNRPC_PORT 111 /*XXX*/
|
||||
#define SNMP_PORT 161 /*XXX*/
|
||||
#define NTP_PORT 123 /*XXX*/
|
||||
#define SNMPTRAP_PORT 162 /*XXX*/
|
||||
#define RIP_PORT 520 /*XXX*/
|
||||
#define KERBEROS_SEC_PORT 750 /*XXX*/
|
||||
#define RSVP_ENCAP_PORT 3455 /*XXX*/
|
||||
|
||||
void
|
||||
udp_print(register const u_char *bp, int length, register const u_char *bp2)
|
||||
{
|
||||
register const struct udphdr *up;
|
||||
register const struct ip *ip;
|
||||
register const u_char *cp;
|
||||
u_short sport, dport, ulen;
|
||||
|
||||
up = (struct udphdr *)bp;
|
||||
ip = (struct ip *)bp2;
|
||||
cp = (u_char *)(up + 1);
|
||||
if (cp > snapend) {
|
||||
printf("[|udp]");
|
||||
return;
|
||||
}
|
||||
if (length < sizeof(struct udphdr)) {
|
||||
(void)printf(" truncated-udp %d", length);
|
||||
return;
|
||||
}
|
||||
length -= sizeof(struct udphdr);
|
||||
|
||||
sport = ntohs(up->uh_sport);
|
||||
dport = ntohs(up->uh_dport);
|
||||
ulen = ntohs(up->uh_ulen);
|
||||
if (packettype) {
|
||||
register struct rpc_msg *rp;
|
||||
enum msg_type direction;
|
||||
|
||||
switch (packettype) {
|
||||
case 1:
|
||||
(void)printf("%s.%s > %s.%s:",
|
||||
ipaddr_string(&ip->ip_src),
|
||||
udpport_string(sport),
|
||||
ipaddr_string(&ip->ip_dst),
|
||||
udpport_string(dport));
|
||||
vat_print((void *)(up + 1), length, up);
|
||||
break;
|
||||
case 2:
|
||||
(void)printf("%s.%s > %s.%s:",
|
||||
ipaddr_string(&ip->ip_src),
|
||||
udpport_string(sport),
|
||||
ipaddr_string(&ip->ip_dst),
|
||||
udpport_string(dport));
|
||||
wb_print((void *)(up + 1), length);
|
||||
break;
|
||||
case 3:
|
||||
rp = (struct rpc_msg *)(up + 1);
|
||||
direction = (enum msg_type)ntohl(rp->rm_direction);
|
||||
if (direction == CALL)
|
||||
sunrpcrequest_print((u_char *)rp, length,
|
||||
(u_char *)ip);
|
||||
else
|
||||
nfsreply_print((u_char *)rp, length,
|
||||
(u_char *)ip); /*XXX*/
|
||||
break;
|
||||
case 4:
|
||||
(void)printf("%s.%s > %s.%s:",
|
||||
ipaddr_string(&ip->ip_src),
|
||||
udpport_string(sport),
|
||||
ipaddr_string(&ip->ip_dst),
|
||||
udpport_string(dport));
|
||||
rtp_print((void *)(up + 1), length, up);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (! qflag) {
|
||||
register struct rpc_msg *rp;
|
||||
enum msg_type direction;
|
||||
|
||||
rp = (struct rpc_msg *)(up + 1);
|
||||
direction = (enum msg_type)ntohl(rp->rm_direction);
|
||||
if (dport == NFS_PORT && direction == CALL) {
|
||||
nfsreq_print((u_char *)rp, length, (u_char *)ip);
|
||||
return;
|
||||
}
|
||||
else if (sport == NFS_PORT && direction == REPLY) {
|
||||
nfsreply_print((u_char *)rp, length, (u_char *)ip);
|
||||
return;
|
||||
}
|
||||
#ifdef notdef
|
||||
else if (dport == SUNRPC_PORT && direction == CALL) {
|
||||
sunrpcrequest_print((u_char *)rp, length, (u_char *)ip);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
else if (((struct LAP *)cp)->type == lapDDP &&
|
||||
(atalk_port(sport) || atalk_port(dport))) {
|
||||
if (vflag)
|
||||
fputs("kip ", stdout);
|
||||
atalk_print(cp, length);
|
||||
return;
|
||||
}
|
||||
}
|
||||
(void)printf("%s.%s > %s.%s:",
|
||||
ipaddr_string(&ip->ip_src), udpport_string(sport),
|
||||
ipaddr_string(&ip->ip_dst), udpport_string(dport));
|
||||
|
||||
if (!qflag) {
|
||||
#define ISPORT(p) (dport == (p) || sport == (p))
|
||||
if (ISPORT(NAMESERVER_PORT))
|
||||
ns_print((const u_char *)(up + 1), length);
|
||||
else if (ISPORT(TFTP_PORT))
|
||||
tftp_print((const u_char *)(up + 1), length);
|
||||
else if (ISPORT(IPPORT_BOOTPC) || ISPORT(IPPORT_BOOTPS))
|
||||
bootp_print((const u_char *)(up + 1), length,
|
||||
sport, dport);
|
||||
else if (dport == RIP_PORT)
|
||||
rip_print((const u_char *)(up + 1), length);
|
||||
else if (ISPORT(SNMP_PORT) || ISPORT(SNMPTRAP_PORT))
|
||||
snmp_print((const u_char *)(up + 1), length);
|
||||
else if (ISPORT(NTP_PORT))
|
||||
ntp_print((const u_char *)(up + 1), length);
|
||||
else if (ISPORT(KERBEROS_PORT) || ISPORT(KERBEROS_SEC_PORT))
|
||||
krb_print((const void *)(up + 1), length);
|
||||
#if 0
|
||||
else if (ISPORT(RSVP_ENCAP_PORT))
|
||||
rsvpUDP_print((const u_char *)(up + 1), length);
|
||||
#endif
|
||||
else if (dport == 3456)
|
||||
vat_print((const void *)(up + 1), length, up);
|
||||
/*
|
||||
* Kludge in test for whiteboard packets.
|
||||
*/
|
||||
else if (dport == 4567)
|
||||
wb_print((const void *)(up + 1), length);
|
||||
else
|
||||
(void)printf(" udp %d", ulen - sizeof(*up));
|
||||
#undef ISPORT
|
||||
} else
|
||||
(void)printf(" udp %d", ulen - sizeof(*up));
|
||||
}
|
@ -1,445 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: print-wb.c,v 1.14 94/06/14 20:18:50 leres Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
/* XXX need to add byte-swapping macros! */
|
||||
|
||||
/*
|
||||
* Largest packet size. Everything should fit within this space.
|
||||
* For instance, multiline objects are sent piecewise.
|
||||
*/
|
||||
#define MAXFRAMESIZE 1024
|
||||
|
||||
/*
|
||||
* Multiple drawing ops can be sent in one packet. Each one starts on a
|
||||
* an even multiple of DOP_ALIGN bytes, which must be a power of two.
|
||||
*/
|
||||
#define DOP_ALIGN 4
|
||||
#define DOP_ROUNDUP(x) ((((int)(x)) + (DOP_ALIGN - 1)) & ~(DOP_ALIGN - 1))
|
||||
#define DOP_NEXT(d)\
|
||||
((struct dophdr*)((u_char *)(d) + \
|
||||
DOP_ROUNDUP(ntohs((d)->dh_len) + sizeof(*(d)))))
|
||||
|
||||
/*
|
||||
* Format of the whiteboard packet header.
|
||||
* The transport level header.
|
||||
*/
|
||||
struct pkt_hdr {
|
||||
u_int32 ph_src; /* site id of source */
|
||||
u_int32 ph_ts; /* time stamp (for skew computation) */
|
||||
u_short ph_version; /* version number */
|
||||
u_char ph_type; /* message type */
|
||||
u_char ph_flags; /* message flags */
|
||||
};
|
||||
|
||||
/* Packet types */
|
||||
#define PT_DRAWOP 0 /* drawing operation */
|
||||
#define PT_ID 1 /* announcement packet */
|
||||
#define PT_RREQ 2 /* repair request */
|
||||
#define PT_RREP 3 /* repair reply */
|
||||
#define PT_KILL 4 /* terminate participation */
|
||||
#define PT_PREQ 5 /* page vector request */
|
||||
#define PT_PREP 7 /* page vector reply */
|
||||
|
||||
/* flags */
|
||||
#define PF_USER 0x01 /* hint that packet has interactive data */
|
||||
#define PF_VIS 0x02 /* only visible ops wanted */
|
||||
|
||||
struct PageID {
|
||||
u_int32 p_sid; /* session id of initiator */
|
||||
u_int32 p_uid; /* page number */
|
||||
};
|
||||
|
||||
struct dophdr {
|
||||
u_int32 dh_ts; /* sender's timestamp */
|
||||
u_short dh_len; /* body length */
|
||||
u_char dh_flags;
|
||||
u_char dh_type; /* body type */
|
||||
/* body follows */
|
||||
};
|
||||
/*
|
||||
* Drawing op sub-types.
|
||||
*/
|
||||
#define DT_RECT 2
|
||||
#define DT_LINE 3
|
||||
#define DT_ML 4
|
||||
#define DT_DEL 5
|
||||
#define DT_XFORM 6
|
||||
#define DT_ELL 7
|
||||
#define DT_CHAR 8
|
||||
#define DT_STR 9
|
||||
#define DT_NOP 10
|
||||
#define DT_PSCODE 11
|
||||
#define DT_PSCOMP 12
|
||||
#define DT_REF 13
|
||||
#define DT_SKIP 14
|
||||
#define DT_HOLE 15
|
||||
#define DT_MAXTYPE 15
|
||||
|
||||
/*
|
||||
* A drawing operation.
|
||||
*/
|
||||
struct pkt_dop {
|
||||
struct PageID pd_page; /* page that operations apply to */
|
||||
u_int32 pd_sseq; /* start sequence number */
|
||||
u_int32 pd_eseq; /* end sequence number */
|
||||
/* drawing ops follow */
|
||||
};
|
||||
|
||||
/*
|
||||
* A repair request.
|
||||
*/
|
||||
struct pkt_rreq {
|
||||
u_int32 pr_id; /* source id of drawops to be repaired */
|
||||
struct PageID pr_page; /* page of drawops */
|
||||
u_int32 pr_sseq; /* start seqno */
|
||||
u_int32 pr_eseq; /* end seqno*/
|
||||
};
|
||||
|
||||
/*
|
||||
* A repair reply.
|
||||
*/
|
||||
struct pkt_rrep {
|
||||
u_int32 pr_id; /* original site id of ops */
|
||||
struct pkt_dop pr_dop;
|
||||
/* drawing ops follow */
|
||||
};
|
||||
|
||||
struct id_off {
|
||||
u_int32 id;
|
||||
u_int32 off;
|
||||
};
|
||||
|
||||
struct pgstate {
|
||||
u_int32 slot;
|
||||
struct PageID page;
|
||||
u_short nid;
|
||||
u_short rsvd;
|
||||
/* seqptr's */
|
||||
};
|
||||
|
||||
/*
|
||||
* An announcement packet.
|
||||
*/
|
||||
struct pkt_id {
|
||||
u_int32 pi_mslot;
|
||||
struct PageID pi_mpage; /* current page */
|
||||
struct pgstate pi_ps;
|
||||
/* seqptr's */
|
||||
/* null-terminated site name */
|
||||
};
|
||||
|
||||
struct pkt_preq {
|
||||
struct PageID pp_page;
|
||||
u_int32 pp_low;
|
||||
u_int32 pp_high;
|
||||
};
|
||||
|
||||
struct pkt_prep {
|
||||
u_int32 pp_n; /* size of pageid array */
|
||||
/* pgstate's follow */
|
||||
};
|
||||
|
||||
static int
|
||||
wb_id(const struct pkt_id *id, int len)
|
||||
{
|
||||
int i;
|
||||
const char *cp;
|
||||
const struct id_off *io;
|
||||
char c;
|
||||
int nid;
|
||||
|
||||
len -= sizeof(*id);
|
||||
if (len < 0) {
|
||||
printf(" truncated-wb-id!");
|
||||
return (0);
|
||||
}
|
||||
if ((u_char *)(id + 1) > snapend)
|
||||
return (-1);
|
||||
nid = ntohs(id->pi_ps.nid);
|
||||
len -= sizeof(*io) * nid;
|
||||
if (len < 0) {
|
||||
printf(" truncated-wb-id!");
|
||||
return (0);
|
||||
}
|
||||
io = (struct id_off *)(id + 1);
|
||||
cp = (char *)(io + nid);
|
||||
if ((u_char *)cp + len > snapend)
|
||||
return (-1);
|
||||
|
||||
printf(" wb-id: %d/%s:%d (max %d/%s:%d) ",
|
||||
ntohl(id->pi_ps.slot),
|
||||
ipaddr_string(&id->pi_ps.page.p_sid),
|
||||
ntohl(id->pi_ps.page.p_uid),
|
||||
ntohl(id->pi_mslot),
|
||||
ipaddr_string(&id->pi_mpage.p_sid),
|
||||
ntohl(id->pi_mpage.p_uid));
|
||||
|
||||
if (cp[len - 1] != '\0')
|
||||
printf("(unterm!) ");
|
||||
|
||||
fn_print((u_char *)cp, (u_char *)cp + len);
|
||||
|
||||
c = '<';
|
||||
for (i = 0; i < nid; ++io, ++i) {
|
||||
printf("%c%s:%d", c, ipaddr_string(&io->id), ntohl(io->off));
|
||||
c = ',';
|
||||
}
|
||||
printf(">");
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
wb_rreq(const struct pkt_rreq *rreq, int len)
|
||||
{
|
||||
if (len < sizeof(*rreq)) {
|
||||
printf(" truncated-wb-rreq!");
|
||||
return (0);
|
||||
}
|
||||
if ((u_char *)(rreq + 1) > snapend)
|
||||
return (-1);
|
||||
|
||||
printf(" wb-rreq: please repair %s %s:%ld<%ld:%ld>",
|
||||
ipaddr_string(&rreq->pr_id),
|
||||
ipaddr_string(&rreq->pr_page.p_sid), ntohl(rreq->pr_page.p_uid),
|
||||
ntohl(rreq->pr_sseq), ntohl(rreq->pr_eseq));
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
wb_preq(const struct pkt_preq *preq, int len)
|
||||
{
|
||||
if (len < sizeof(*preq)) {
|
||||
printf(" truncated-wb-preq!");
|
||||
return (0);
|
||||
}
|
||||
if ((u_char *)(preq + 1) > snapend)
|
||||
return (-1);
|
||||
|
||||
printf(" wb-preq: need %d/%s:%ld",
|
||||
ntohl(preq->pp_low),
|
||||
ipaddr_string(&preq->pp_page.p_sid),
|
||||
ntohl(preq->pp_page.p_uid));
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
wb_prep(const struct pkt_prep *prep, int len)
|
||||
{
|
||||
int n;
|
||||
const struct pgstate* ps;
|
||||
const u_char* ep = snapend;
|
||||
|
||||
if (len < sizeof(*prep)) {
|
||||
printf(" truncated-wb-prep!");
|
||||
return (0);
|
||||
}
|
||||
printf(" wb-prep:");
|
||||
n = ntohl(prep->pp_n);
|
||||
ps = (const struct pgstate*)(prep + 1);
|
||||
while (--n >= 0 && (u_char*)ps < ep) {
|
||||
const struct id_off *io, *ie;
|
||||
char c = '<';
|
||||
|
||||
printf(" %lu/%s:%lu", ntohl(ps->slot),
|
||||
ipaddr_string(&ps->page.p_sid),
|
||||
ntohl(ps->page.p_uid));
|
||||
io = (struct id_off*)(ps + 1);
|
||||
for (ie = io + ps->nid; io < ie && (u_char*)io < ep; ++io) {
|
||||
printf("%c%s:%lu", c, ipaddr_string(&io->id),
|
||||
ntohl(io->off));
|
||||
c = ',';
|
||||
}
|
||||
printf(">");
|
||||
ps = (struct pgstate*)io;
|
||||
}
|
||||
return ((u_char*)ps <= ep? 0 : -1);
|
||||
}
|
||||
|
||||
|
||||
char *dopstr[] = {
|
||||
"dop-0!",
|
||||
"dop-1!",
|
||||
"RECT",
|
||||
"LINE",
|
||||
"ML",
|
||||
"DEL",
|
||||
"XFORM",
|
||||
"ELL",
|
||||
"CHAR",
|
||||
"STR",
|
||||
"NOP",
|
||||
"PSCODE",
|
||||
"PSCOMP",
|
||||
"REF",
|
||||
"SKIP",
|
||||
"HOLE",
|
||||
};
|
||||
|
||||
static int
|
||||
wb_dops(const struct dophdr *dh, u_int32 ss, u_int32 es)
|
||||
{
|
||||
printf(" <");
|
||||
for ( ; ss <= es; ++ss) {
|
||||
register int t = dh->dh_type;
|
||||
|
||||
if (t > DT_MAXTYPE)
|
||||
printf(" dop-%d!", t);
|
||||
else {
|
||||
printf(" %s", dopstr[t]);
|
||||
if (t == DT_SKIP || t == DT_HOLE) {
|
||||
int ts = ntohl(dh->dh_ts);
|
||||
printf("%d", ts - ss + 1);
|
||||
if (ss > ts || ts > es) {
|
||||
printf("[|]");
|
||||
if (ts < ss)
|
||||
return (0);
|
||||
}
|
||||
ss = ts;
|
||||
}
|
||||
}
|
||||
dh = DOP_NEXT(dh);
|
||||
if ((u_char*)dh >= snapend) {
|
||||
printf("[|wb]");
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf(" >");
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
wb_rrep(const struct pkt_rrep *rrep, int len)
|
||||
{
|
||||
const struct pkt_dop *dop = &rrep->pr_dop;
|
||||
|
||||
len -= sizeof(*rrep);
|
||||
if (len < 0) {
|
||||
printf(" truncated-wb-rrep!");
|
||||
return (0);
|
||||
}
|
||||
if ((u_char *)(rrep + 1) > snapend)
|
||||
return (-1);
|
||||
|
||||
printf(" wb-rrep: for %s %s:%d<%ld:%ld>",
|
||||
ipaddr_string(&rrep->pr_id),
|
||||
ipaddr_string(&dop->pd_page.p_sid), ntohl(dop->pd_page.p_uid),
|
||||
ntohl(dop->pd_sseq), ntohl(dop->pd_eseq));
|
||||
|
||||
return (wb_dops((const struct dophdr*)(dop + 1),
|
||||
ntohl(dop->pd_sseq), ntohl(dop->pd_eseq)));
|
||||
}
|
||||
|
||||
static int
|
||||
wb_drawop(const struct pkt_dop *dop, int len)
|
||||
{
|
||||
len -= sizeof(*dop);
|
||||
if (len < 0) {
|
||||
printf(" truncated-wb-dop!");
|
||||
return (0);
|
||||
}
|
||||
if ((u_char *)(dop + 1) > snapend)
|
||||
return (-1);
|
||||
|
||||
printf(" wb-dop: %s:%d<%ld:%ld>",
|
||||
ipaddr_string(&dop->pd_page.p_sid), ntohl(dop->pd_page.p_uid),
|
||||
ntohl(dop->pd_sseq), ntohl(dop->pd_eseq));
|
||||
|
||||
return (wb_dops((const struct dophdr*)(dop + 1),
|
||||
ntohl(dop->pd_sseq), ntohl(dop->pd_eseq)));
|
||||
}
|
||||
|
||||
/*
|
||||
* Print whiteboard multicast packets.
|
||||
*/
|
||||
void
|
||||
wb_print(register const void *hdr, register int len)
|
||||
{
|
||||
register const struct pkt_hdr* ph;
|
||||
|
||||
ph = (const struct pkt_hdr*)hdr;
|
||||
len -= sizeof(*ph);
|
||||
if (len < 0) {
|
||||
printf(" truncated-wb!");
|
||||
return;
|
||||
}
|
||||
if ((u_char *)(ph + 1) > snapend) {
|
||||
trunc:
|
||||
printf("[|wb]");
|
||||
return;
|
||||
}
|
||||
if (ph->ph_flags)
|
||||
printf("*");
|
||||
switch (ph->ph_type) {
|
||||
|
||||
case PT_KILL:
|
||||
printf(" wb-kill");
|
||||
break;
|
||||
|
||||
case PT_ID:
|
||||
if (wb_id((struct pkt_id *)(ph + 1), len) < 0)
|
||||
goto trunc;
|
||||
break;
|
||||
|
||||
case PT_RREQ:
|
||||
if (wb_rreq((struct pkt_rreq *)(ph + 1), len) < 0)
|
||||
goto trunc;
|
||||
break;
|
||||
|
||||
case PT_RREP:
|
||||
if (wb_rrep((struct pkt_rrep *)(ph + 1), len) < 0)
|
||||
goto trunc;
|
||||
break;
|
||||
|
||||
case PT_DRAWOP:
|
||||
if (wb_drawop((struct pkt_dop *)(ph + 1), len) < 0)
|
||||
goto trunc;
|
||||
break;
|
||||
|
||||
case PT_PREQ:
|
||||
if (wb_preq((struct pkt_preq *)(ph + 1), len) < 0)
|
||||
goto trunc;
|
||||
break;
|
||||
|
||||
case PT_PREP:
|
||||
if (wb_prep((struct pkt_prep *)(ph + 1), len) < 0)
|
||||
goto trunc;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf(" wb-%d!", ph->ph_type);
|
||||
return;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,413 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 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.
|
||||
*/
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994\nThe Regents of the University of California. All rights reserved.\n";
|
||||
static char rcsid[] =
|
||||
"@(#)$Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/tcpdump.c,v 1.2 1995/03/08 12:52:48 olah Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* tcpdump - monitor tcp/ip traffic on an ethernet.
|
||||
*
|
||||
* First written in 1987 by Van Jacobson, Lawrence Berkeley Laboratory.
|
||||
* Mercilessly hacked and occasionally improved since then via the
|
||||
* combined efforts of Van, Steve McCanne and Craig Leres of LBL.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <pcap.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "addrtoname.h"
|
||||
|
||||
int fflag; /* don't translate "foreign" IP address */
|
||||
int nflag; /* leave addresses as numbers */
|
||||
int Nflag; /* remove domains from printed host names */
|
||||
int pflag; /* don't go promiscuous */
|
||||
int qflag; /* quick (shorter) output */
|
||||
int tflag = 1; /* print packet arrival time */
|
||||
int eflag; /* print ethernet header */
|
||||
int vflag; /* verbose */
|
||||
int xflag; /* print packet in hex */
|
||||
int Oflag = 1; /* run filter code optimizer */
|
||||
int Sflag; /* print raw TCP sequence numbers */
|
||||
int packettype;
|
||||
|
||||
int dflag; /* print filter code */
|
||||
|
||||
char *program_name;
|
||||
|
||||
int thiszone;
|
||||
|
||||
SIGRET cleanup(int);
|
||||
extern void bpf_dump(struct bpf_program *, int);
|
||||
|
||||
/* Length of saved portion of packet. */
|
||||
int snaplen = DEFAULT_SNAPLEN;
|
||||
|
||||
struct printer {
|
||||
pcap_handler f;
|
||||
int type;
|
||||
};
|
||||
|
||||
static struct printer printers[] = {
|
||||
{ ether_if_print, DLT_EN10MB },
|
||||
{ sl_if_print, DLT_SLIP },
|
||||
{ ppp_if_print, DLT_PPP },
|
||||
{ fddi_if_print, DLT_FDDI },
|
||||
{ null_if_print, DLT_NULL },
|
||||
{ NULL, 0 },
|
||||
};
|
||||
|
||||
static pcap_handler
|
||||
lookup_printer(int type)
|
||||
{
|
||||
struct printer *p;
|
||||
|
||||
for (p = printers; p->f; ++p)
|
||||
if (type == p->type)
|
||||
return p->f;
|
||||
|
||||
error("unknown data link type 0x%x", type);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static pcap_t *pd;
|
||||
|
||||
#ifdef __osf__
|
||||
#include <sys/sysinfo.h>
|
||||
#include <sys/proc.h>
|
||||
void
|
||||
abort_on_misalignment()
|
||||
{
|
||||
int buf[2];
|
||||
|
||||
buf[0] = SSIN_UACPROC;
|
||||
buf[1] = UAC_SIGBUS;
|
||||
if (setsysinfo(SSI_NVPAIRS, buf, 1, 0, 0) < 0) {
|
||||
perror("setsysinfo");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
register int cnt, op;
|
||||
u_long localnet, netmask;
|
||||
register char *cp, *infile, *cmdbuf, *device, *RFileName, *WFileName;
|
||||
pcap_handler printer;
|
||||
struct bpf_program fcode;
|
||||
u_char *pcap_userdata;
|
||||
char errbuf[PCAP_ERRBUF_SIZE];
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind, opterr;
|
||||
|
||||
#ifdef __osf__
|
||||
abort_on_misalignment();
|
||||
#endif
|
||||
|
||||
cnt = -1;
|
||||
device = NULL;
|
||||
infile = NULL;
|
||||
RFileName = NULL;
|
||||
WFileName = NULL;
|
||||
if ((cp = strrchr(argv[0], '/')) != NULL)
|
||||
program_name = cp + 1;
|
||||
else
|
||||
program_name = argv[0];
|
||||
|
||||
opterr = 0;
|
||||
while ((op = getopt(argc, argv, "c:defF:i:lnNOpqr:s:StT:vw:xY")) != EOF)
|
||||
switch (op) {
|
||||
case 'c':
|
||||
cnt = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
++dflag;
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
++eflag;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
++fflag;
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
infile = optarg;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
device = optarg;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
setlinebuf(stdout);
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
++nflag;
|
||||
break;
|
||||
|
||||
case 'N':
|
||||
++Nflag;
|
||||
break;
|
||||
|
||||
case 'O':
|
||||
Oflag = 0;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
++pflag;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
++qflag;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
RFileName = optarg;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
snaplen = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
++Sflag;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
--tflag;
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
if (strcasecmp(optarg, "vat") == 0)
|
||||
packettype = 1;
|
||||
else if (strcasecmp(optarg, "wb") == 0)
|
||||
packettype = 2;
|
||||
else if (strcasecmp(optarg, "rpc") == 0)
|
||||
packettype = 3;
|
||||
else if (strcasecmp(optarg, "rtp") == 0)
|
||||
packettype = 4;
|
||||
else
|
||||
error("unknown packet type `%s'", optarg);
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
++vflag;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
WFileName = optarg;
|
||||
break;
|
||||
#ifdef YYDEBUG
|
||||
case 'Y':
|
||||
{
|
||||
extern int yydebug;
|
||||
yydebug = 1;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case 'x':
|
||||
++xflag;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
if (tflag > 0)
|
||||
thiszone = gmt2local();
|
||||
|
||||
if (RFileName != NULL) {
|
||||
/*
|
||||
* We don't need network access, so set it back to the user id.
|
||||
* Also, this prevents the user from reading anyone's
|
||||
* trace file.
|
||||
*/
|
||||
setuid(getuid());
|
||||
|
||||
pd = pcap_open_offline(RFileName, errbuf);
|
||||
if (pd == NULL)
|
||||
error(errbuf);
|
||||
/* use the snaplen stored in the file */
|
||||
snaplen = pcap_snapshot(pd);
|
||||
localnet = 0;
|
||||
netmask = 0;
|
||||
if (fflag != 0)
|
||||
error("-f and -r options are incompatible");
|
||||
} else {
|
||||
if (device == NULL) {
|
||||
device = pcap_lookupdev(errbuf);
|
||||
if (device == NULL)
|
||||
error(errbuf);
|
||||
}
|
||||
pd = pcap_open_live(device, snaplen, !pflag, 1000, errbuf);
|
||||
if (pd == NULL)
|
||||
error(errbuf);
|
||||
if (pcap_lookupnet(device, &localnet, &netmask, errbuf) < 0)
|
||||
error(errbuf);
|
||||
/*
|
||||
* Let user own process after socket has been opened.
|
||||
*/
|
||||
setuid(getuid());
|
||||
}
|
||||
if (infile)
|
||||
cmdbuf = read_infile(infile);
|
||||
else
|
||||
cmdbuf = copy_argv(&argv[optind]);
|
||||
|
||||
if (pcap_compile(pd, &fcode, cmdbuf, Oflag, netmask) < 0)
|
||||
error(pcap_geterr(pd));
|
||||
if (dflag) {
|
||||
bpf_dump(&fcode, dflag);
|
||||
exit(0);
|
||||
}
|
||||
init_addrtoname(fflag, localnet, netmask);
|
||||
|
||||
(void)signal(SIGTERM, cleanup);
|
||||
(void)signal(SIGINT, cleanup);
|
||||
(void)signal(SIGHUP, cleanup);
|
||||
|
||||
if (pcap_setfilter(pd, &fcode) < 0)
|
||||
error(pcap_geterr(pd));
|
||||
if (WFileName) {
|
||||
pcap_dumper_t *p = pcap_dump_open(pd, WFileName);
|
||||
if (p == NULL)
|
||||
error(pcap_geterr(pd));
|
||||
printer = pcap_dump;
|
||||
pcap_userdata = (u_char *)p;
|
||||
} else {
|
||||
printer = lookup_printer(pcap_datalink(pd));
|
||||
pcap_userdata = 0;
|
||||
}
|
||||
if (RFileName == NULL) {
|
||||
fprintf(stderr, "%s: listening on %s\n", program_name, device);
|
||||
fflush(stderr);
|
||||
}
|
||||
pcap_loop(pd, cnt, printer, pcap_userdata);
|
||||
pcap_close(pd);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* make a clean exit on interrupts */
|
||||
SIGRET
|
||||
cleanup(int signo)
|
||||
{
|
||||
struct pcap_stat stat;
|
||||
|
||||
/* Can't print the summary if reading from a savefile */
|
||||
if (pd != NULL && pcap_file(pd) == NULL) {
|
||||
(void)fflush(stdout);
|
||||
putc('\n', stderr);
|
||||
if (pcap_stats(pd, &stat) < 0)
|
||||
(void)fprintf(stderr, "pcap_stats: %s\n",
|
||||
pcap_geterr(pd));
|
||||
else {
|
||||
(void)fprintf(stderr, "%d packets received by filter\n",
|
||||
stat.ps_recv);
|
||||
(void)fprintf(stderr, "%d packets dropped by kernel\n",
|
||||
stat.ps_drop);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Like default_print() but data need not be aligned */
|
||||
void
|
||||
default_print_unaligned(register const u_char *cp, register int length)
|
||||
{
|
||||
register u_int i, s;
|
||||
register int nshorts;
|
||||
|
||||
nshorts = (u_int) length / sizeof(u_short);
|
||||
i = 0;
|
||||
while (--nshorts >= 0) {
|
||||
if ((i++ % 8) == 0)
|
||||
(void)printf("\n\t\t\t");
|
||||
s = *cp++;
|
||||
(void)printf(" %02x%02x", s, *cp++);
|
||||
}
|
||||
if (length & 1) {
|
||||
if ((i % 8) == 0)
|
||||
(void)printf("\n\t\t\t");
|
||||
(void)printf(" %02x", *cp);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
default_print(register const u_char *bp, register int length)
|
||||
{
|
||||
register const u_short *sp;
|
||||
register u_int i;
|
||||
register int nshorts;
|
||||
|
||||
if ((int)bp & 1) {
|
||||
default_print_unaligned(bp, length);
|
||||
return;
|
||||
}
|
||||
sp = (u_short *)bp;
|
||||
nshorts = (u_int) length / sizeof(u_short);
|
||||
i = 0;
|
||||
while (--nshorts >= 0) {
|
||||
if ((i++ % 8) == 0)
|
||||
(void)printf("\n\t\t\t");
|
||||
(void)printf(" %04x", ntohs(*sp++));
|
||||
}
|
||||
if (length & 1) {
|
||||
if ((i % 8) == 0)
|
||||
(void)printf("\n\t\t\t");
|
||||
(void)printf(" %02x", *(u_char *)sp);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
extern char version[];
|
||||
|
||||
(void)fprintf(stderr, "Version %s\n", version);
|
||||
(void)fprintf(stderr,
|
||||
"Usage: tcpdump [-deflnOpqtvx] [-c count] [-i interface]\n");
|
||||
(void)fprintf(stderr,
|
||||
"\t\t[-r filename] [-w filename] [expr]\n");
|
||||
exit(-1);
|
||||
}
|
@ -1,326 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/util.c,v 1.2 1995/03/08 12:52:49 olah Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#ifdef SOLARIS
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
/*
|
||||
* Print out a filename (or other ascii string).
|
||||
* If ep is NULL, assume no truncation check is needed.
|
||||
* Return true if truncated.
|
||||
*/
|
||||
int
|
||||
fn_print(register const u_char *s, register const u_char *ep)
|
||||
{
|
||||
register int ret;
|
||||
register u_char c;
|
||||
|
||||
ret = 1; /* assume truncated */
|
||||
putchar('"');
|
||||
while (ep == NULL || s < ep) {
|
||||
c = *s++;
|
||||
if (c == '\0') {
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
if (!isascii(c)) {
|
||||
c = toascii(c);
|
||||
putchar('M');
|
||||
putchar('-');
|
||||
}
|
||||
if (!isprint(c)) {
|
||||
c ^= 0x40; /* DEL to ?, others to alpha */
|
||||
putchar('^');
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
putchar('"');
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print out a counted filename (or other ascii string).
|
||||
* If ep is NULL, assume no truncation check is needed.
|
||||
* Return true if truncated.
|
||||
*/
|
||||
int
|
||||
fn_printn(register const u_char *s, register u_int n,
|
||||
register const u_char *ep)
|
||||
{
|
||||
register int ret;
|
||||
register u_char c;
|
||||
|
||||
ret = 1; /* assume truncated */
|
||||
putchar('"');
|
||||
while (ep == NULL || s < ep) {
|
||||
if (n-- <= 0) {
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
c = *s++;
|
||||
if (!isascii(c)) {
|
||||
c = toascii(c);
|
||||
putchar('M');
|
||||
putchar('-');
|
||||
}
|
||||
if (!isprint(c)) {
|
||||
c ^= 0x40; /* DEL to ?, others to alpha */
|
||||
putchar('^');
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
putchar('"');
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print the timestamp
|
||||
*/
|
||||
void
|
||||
ts_print(register const struct timeval *tvp)
|
||||
{
|
||||
register int s;
|
||||
extern int32 thiszone;
|
||||
|
||||
if (tflag > 0) {
|
||||
/* Default */
|
||||
s = (tvp->tv_sec + thiszone) % 86400;
|
||||
(void)printf("%02d:%02d:%02d.%06d ",
|
||||
s / 3600, (s % 3600) / 60, s % 60, tvp->tv_usec);
|
||||
} else if (tflag < 0) {
|
||||
/* Unix timeval style */
|
||||
(void)printf("%d.%06d ", tvp->tv_sec, tvp->tv_usec);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a token value to a string; use "fmt" if not found.
|
||||
*/
|
||||
const char *
|
||||
tok2str(register const struct token *lp, register const char *fmt,
|
||||
register int v)
|
||||
{
|
||||
static char buf[128];
|
||||
|
||||
while (lp->s != NULL) {
|
||||
if (lp->v == v)
|
||||
return (lp->s);
|
||||
++lp;
|
||||
}
|
||||
if (fmt == NULL)
|
||||
fmt = "#%d";
|
||||
(void)sprintf(buf, fmt, v);
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/* A replacement for strdup() that cuts down on malloc() overhead */
|
||||
char *
|
||||
savestr(register const char *str)
|
||||
{
|
||||
register u_int size;
|
||||
register char *p;
|
||||
static char *strptr = NULL;
|
||||
static u_int strsize = 0;
|
||||
|
||||
size = strlen(str) + 1;
|
||||
if (size > strsize) {
|
||||
strsize = 1024;
|
||||
if (strsize < size)
|
||||
strsize = size;
|
||||
strptr = malloc(strsize);
|
||||
if (strptr == NULL)
|
||||
error("savestr: malloc");
|
||||
}
|
||||
(void)strcpy(strptr, str);
|
||||
p = strptr;
|
||||
strptr += size;
|
||||
strsize -= size;
|
||||
return (p);
|
||||
}
|
||||
|
||||
#ifdef NOVFPRINTF
|
||||
/*
|
||||
* Stock 4.3 doesn't have vfprintf.
|
||||
* This routine is due to Chris Torek.
|
||||
*/
|
||||
vfprintf(f, fmt, args)
|
||||
FILE *f;
|
||||
char *fmt;
|
||||
va_list args;
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((f->_flag & _IOWRT) == 0) {
|
||||
if (f->_flag & _IORW)
|
||||
f->_flag |= _IOWRT;
|
||||
else
|
||||
return EOF;
|
||||
}
|
||||
ret = _doprnt(fmt, args, f);
|
||||
return ferror(f) ? EOF : ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* VARARGS */
|
||||
__dead void
|
||||
#if __STDC__ || defined(SOLARIS)
|
||||
error(char *fmt, ...)
|
||||
#else
|
||||
error(fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
(void)fprintf(stderr, "%s: ", program_name);
|
||||
#if __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
(void)vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
if (*fmt) {
|
||||
fmt += strlen(fmt);
|
||||
if (fmt[-1] != '\n')
|
||||
(void)fputc('\n', stderr);
|
||||
}
|
||||
exit(1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/* VARARGS */
|
||||
void
|
||||
#if __STDC__ || defined(SOLARIS)
|
||||
warning(char *fmt, ...)
|
||||
#else
|
||||
warning(fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
(void)fprintf(stderr, "%s: warning: ", program_name);
|
||||
#if __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
(void)vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
if (*fmt) {
|
||||
fmt += strlen(fmt);
|
||||
if (fmt[-1] != '\n')
|
||||
(void)fputc('\n', stderr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy arg vector into a new buffer, concatenating arguments with spaces.
|
||||
*/
|
||||
char *
|
||||
copy_argv(register char **argv)
|
||||
{
|
||||
register char **p;
|
||||
register int len = 0;
|
||||
char *buf;
|
||||
char *src, *dst;
|
||||
|
||||
p = argv;
|
||||
if (*p == 0)
|
||||
return 0;
|
||||
|
||||
while (*p)
|
||||
len += strlen(*p++) + 1;
|
||||
|
||||
buf = malloc(len);
|
||||
|
||||
p = argv;
|
||||
dst = buf;
|
||||
while ((src = *p++) != NULL) {
|
||||
while ((*dst++ = *src++) != '\0')
|
||||
;
|
||||
dst[-1] = ' ';
|
||||
}
|
||||
dst[-1] = '\0';
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *
|
||||
read_infile(char *fname)
|
||||
{
|
||||
struct stat buf;
|
||||
int fd;
|
||||
char *p;
|
||||
|
||||
fd = open(fname, O_RDONLY);
|
||||
if (fd < 0)
|
||||
error("can't open '%s'", fname);
|
||||
|
||||
if (fstat(fd, &buf) < 0)
|
||||
error("can't state '%s'", fname);
|
||||
|
||||
p = malloc((u_int)buf.st_size);
|
||||
if (read(fd, p, (int)buf.st_size) != buf.st_size)
|
||||
error("problem reading '%s'", fname);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
int
|
||||
gmt2local()
|
||||
{
|
||||
time_t now;
|
||||
struct tm *tmp;
|
||||
|
||||
time(&now);
|
||||
tmp = localtime(&now);
|
||||
return tmp->tm_gmtoff;
|
||||
}
|
Loading…
Reference in New Issue
Block a user