📄 _xtp.c
字号:
/*
* Copyright (c) 1997
* Sandia National Laboratories. 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, Sandia National Laboratories, 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
#include "a2name.h"
#include "interfac.h"
#if (SIZEOF_LONG_LONG == 8)
#include "xtp.h"
/*
* This function prints out the options
*/
static void print_opt (u_short options)
{
if (!options)
return;
PUTS (" (");
if (options & XH_BTAG)
PUTS ("Bt");
if (options & XH_END)
PUTS ("En");
if (options & XH_EOM)
PUTS ("Eo");
if (options & XH_WCLOSE)
PUTS ("Wc");
if (options & XH_RCLOSE)
PUTS ("Rc");
if (options & XH_DREQ)
PUTS ("Dr");
if (options & XH_SREQ)
PUTS ("Sr");
if (options & XH_FASTNAK)
PUTS ("Fn");
if (options & XH_NOFLOW)
PUTS ("Nf");
if (options & XH_SORT)
PUTS ("So");
if (options & XH_RES)
PUTS ("Re");
if (options & XH_MULTI)
PUTS ("Mc");
if (options & XH_NOERR)
PUTS ("Ne");
if (options & XH_EDGE)
PUTS ("Eg");
if (options & XH_NOCHECK)
PUTS ("Nc");
PUTCHAR (')');
}
void xtp_print (const u_char *bp, u_int length, const u_char *bp2)
{
struct xtphdr_long *xp = (struct xtphdr_long*) bp;
struct ip *ip = (struct ip *) bp2;
u_short sport, dport;
u_long sync, echo = 0;
xtp_seq rseq, alloc, seq;
xtp_key key, xkey;
/*
* We have to be careful with these next two tests.
* xtphdr_long is defined as xtphdr plus the union of
* xtp segment structures. The length of xtphdr_long is
* the length of xtphdr (32) plus the length of the largest
* structure in the union (40).
* We can receive packets that are packets that
* are shorter than the xtphdr_long, e.g., the CNTL packet
* is 64 bytes long < sizeof(xtphdr_long).
*
* The next two tests come from tcp_print and were
* designed to prevent the user from looking into memory
* if the tcp header was shortened in some way.
* Since the common element of xtphdr_long is xtphdr, we
* will check to see if at least sizeof(xtphdr) is safe to
* examine.
*
* We must be very careful when we access values in the union,
* as we have NOT checked it they are really there.
*
* awj 6/27/96
*
*/
if (((const u_char*)xp + sizeof(struct xtphdr)) > snapend)
{
PUTS ("[|xtp]");
return;
}
if (length < sizeof(struct xtphdr))
{
PRINTF ("truncated-xtp %d", length);
return;
}
/*
* Print to/from information
*/
if (xp->xh_cmd.ptype == X_FIRST)
{
sport = ntohs (xp->xp_addr.xa_sport);
dport = ntohs (xp->xp_addr.xa_dport);
PRINTF ("%s.%s > %s.%s.",
ipaddr_string (&ip->ip_src), tcpport_string (sport),
ipaddr_string (&ip->ip_dst), tcpport_string (dport));
}
else
PRINTF ("%s > %s.", ipaddr_string (&ip->ip_src),
ipaddr_string (&ip->ip_dst));
/* Print the key value
*/
key = xp->xh_key;
NTOHQ (key);
PRINTF ("0x%llx", CLR_HI_BIT (key));
if (TEST_HI_BIT (key))
PUTS ("(r): ");
else PUTS (": ");
/* Quiet flag, don't continue.
*/
if (qflag)
{
PRINTF ("xtp %lu", ntohl (xp->xh_dlen));
return;
}
/* Get the sequence number and dlen
*/
seq = xp->xh_seq;
NTOHQ (seq);
length = ntohl (xp->xh_dlen);
/* If this is a control packet, get the control information
*/
if (xp->xh_cmd.ptype & 0x01)
{
rseq = xp->xp_cntl.xc_rseq;
NTOHQ (rseq);
alloc = xp->xp_cntl.xc_alloc;
NTOHQ (alloc);
echo = ntohl (xp->xp_cntl.xc_echo);
}
switch (xp->xh_cmd.ptype)
{
case X_DATA:
PUTCHAR ('.');
print_opt (ntohs (xp->xh_cmd.options));
PRINTF (" %lld:%lld(%d)", seq, seq + length, length);
break;
case X_CNTL:
PUTCHAR ('C');
print_opt (ntohs (xp->xh_cmd.options));
PRINTF (" %lld(%d)", seq, length);
PRINTF (" rseq %lld alloc %lld echo %lu", rseq, alloc, echo);
break;
case X_FIRST:
PUTCHAR ('F');
print_opt (ntohs (xp->xh_cmd.options));
PRINTF (" 0:%d(%d)", length, length);
break;
case X_ECNTL:
PUTCHAR ('E');
print_opt (ntohs (xp->xh_cmd.options));
PRINTF (" %lld(%d)", seq, length);
PRINTF (" rseq %lld alloc %lld echo %lu", rseq, alloc, echo);
break;
case X_TCNTL:
PUTCHAR ('T');
print_opt (ntohs (xp->xh_cmd.options));
PRINTF (" %lld(%d)", seq, length);
PRINTF (" rseq %lld alloc %lld echo %lu", rseq, alloc, echo);
if (snapend >= (const u_char*)xp + sizeof(struct xtphdr_long))
{
xkey = xp->xp_tcntl.xc_xkey;
NTOHQ (xkey);
PRINTF (" 0x%llx", CLR_HI_BIT (xkey));
if (TEST_HI_BIT (xkey))
PUTS ("(r)");
}
break;
case X_JCNTL:
PUTCHAR ('J');
print_opt (ntohs (xp->xh_cmd.options));
PRINTF (" %lld(%d)", seq, length);
PRINTF (" rseq %lld alloc %lld echo %lu", rseq, alloc, echo);
break;
case X_DIAG:
PUTCHAR ('D');
print_opt (ntohs (xp->xh_cmd.options));
PRINTF (" %lld(%d)", seq, length);
break;
default:
PUTS ("Error: unknown packet type.\n");
return;
}
/* Print the sync value
*/
sync = ntohl (xp->xh_sync);
PRINTF (" sync %lu", sync);
}
#else /* if SIZEOF_LONG_LONG != 8 */
void xtp_print (const u_char *bp, u_int length, const u_char *bp2)
{
const struct ip *ip = (struct ip *) bp2;
PRINTF ("%s > %s %d (xtp)",
ipaddr_string (&ip->ip_src),
ipaddr_string (&ip->ip_dst), length);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -