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

📄 _srm2.c

📁 This directory contains source code for tcpdump, a tool for network monitoring and data acquisition
💻 C
字号:
/*
 * Copyright (c) 1998 The University of Utah and the Flux Group.
 * All rights reserved.
 *
 * Permission to use, copy, modify and distribute this software is hereby
 * granted provided that (1) source code retains these copyright, permission,
 * and disclaimer notices, and (2) redistributions including binaries
 * reproduce the notices in supporting documentation.
 *
 * THE UNIVERSITY OF UTAH ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
 * CONDITION.  THE UNIVERSITY OF UTAH DISCLAIMS ANY LIABILITY OF ANY KIND
 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
 */

/*
 * Copyright (c) 1998 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 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 Computer Systems
 *       Engineering Group at Lawrence Berkeley Laboratory.
 * 4. Neither the name of the University nor of the Laboratory 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.
 *
 * ---------------------------
 *
 * Filename: print-srm2.c
 *   -- Author: Kristin Wright <kwright@cs.utah.edu> and
 *              Suchitra Raman <suchi@cs.berkeley.edu>
 *
 * Extensions to tcpdump for libsrm 2.0a1 packets. 
 *
 * See http://www-mash.cs.berkeley.edu/mash/software/srm2.0/
 * for information on libsrm, a user-level reliable multicast 
 * transport library. 
 *
 * ---------------------------
 *
 */

#if 0
static const char rcsid[] =
  "@(#) $Header: /usr/lsrc/flux/CVS/tcpdump/print-srm2.c,v 1.1 2000/01/18 23:37:58 kwright Exp $";
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <ctype.h>

#include <sys/param.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netdb.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/tcp.h>
#include <netinet/tcpip.h>

#include "interfac.h"

struct srm2_cmnhdr {
       u_int8_t  ch_flags;       /* Version : 2, Padding : 1 */
       u_int8_t  ch_type;        /* SRMv2 Pkt type */
       u_int8_t  ch_tcid;        /* SRMv2 traffic class ID */
       u_int8_t  ch_unused;
       u_int32_t ch_ipaddr;      /* IPv4 address */
     };

struct srmv2_conhdr {
       u_int32_t ch_srcid[4];
       u_int32_t ch_cid;
     };

struct srmv2_aduhdr {
       u_int8_t  ah_flags;       /* Fragment : 1, LastADU : 1, Reserved : 6 */
       u_int8_t  ah_atype;
       u_int16_t ah_alen;
       u_int32_t ah_seqno;
       u_int32_t ah_ts[2];
     };

typedef u_int32_t srmv2_fraghdr; /* MSbit is the "more" flag */

struct srmv2_rreqhdr {
       u_int32_t rh_ss;
       u_int32_t rh_sbytes;
       u_int32_t rh_es;
       u_int32_t rh_ebytes;
     };

struct srmv2_announcehdr {
       u_int32_t ah_cid;
       u_int32_t ah_sign;
     };


/* Packet types
 */
#define PT_SRM2_DATA         1
#define PT_SRM2_ANNOUNCEMENT 2
#define PT_SRM2_RREQ         3
#define PT_SRM2_NSREQUEST    4

#define PT_SRM2_DELAYS       6
#define PT_SRM2_NSREPAIR     7
#define PT_SRM2_REXMIT       9

static __inline void srm2_conhdr (const struct srmv2_conhdr *ch)
{
  /* Checking for length should be done prior to call.
   */
  PRINTF (" %08x:%08x:%08x:%08x 0x%08x/",
          ntohl(ch->ch_srcid[0]), ntohl(ch->ch_srcid[1]),
          ntohl(ch->ch_srcid[2]), ntohl(ch->ch_srcid[3]),
          ntohl(ch->ch_cid));
}

static __inline void srm2_data (struct srmv2_aduhdr *ah, u_int len)
{
  if (len >= sizeof(*ah) && snapend >= (u_char*)(ah+1))
     PRINTF ("%d F:%d L:%d srm2-data ",
             ntohl(ah->ah_seqno), ah->ah_flags >> 7,
             (ah->ah_flags >> 6) & 1);
}

static __inline void srm2_announcement (struct srmv2_announcehdr *announce_hdr, u_int len)
{
  if (len >= sizeof(*announce_hdr) && snapend >= (u_char*)(announce_hdr+1))
     PRINTF ("[sig 0x%08x:0x%08x] srm2-anno ",
             ntohl (announce_hdr->ah_cid),
             ntohl (announce_hdr->ah_sign));
}

static __inline void srm2_rreq (struct srmv2_rreqhdr *rreq_hdr, u_int len)
{
  if (len >= sizeof(*rreq_hdr) && snapend >= (u_char*)(rreq_hdr+1))
     PRINTF ("[%d:%d  %d:%d] srm2-rreq ",
             ntohl(rreq_hdr->rh_ss),
             ntohl(rreq_hdr->rh_sbytes),
             ntohl(rreq_hdr->rh_es),
             ntohl(rreq_hdr->rh_ebytes));
}

void srm2_print (const u_char *hdr, u_int len)
{
  const struct srmv2_conhdr *conhdr;
  const struct srm2_cmnhdr  *ch = (const struct srm2_cmnhdr*)hdr;

  if (len < sizeof(*ch) || (u_char*)(ch+1) > snapend)
  {
    PUTS ("[|srm2]");
    return;
  }
  PRINTF (" v%d  %5dB [tcid 0x%x] ", ch->ch_flags >> 6, len, ch->ch_tcid);
  len -= sizeof(*ch);

  /* All valid packets contain the common header with the source ID.
   */
  conhdr = (const struct srmv2_conhdr*)(ch + 1);
  if (len < sizeof(*conhdr) || (u_char*)(conhdr + 1) > snapend)
     return;

  srm2_conhdr (conhdr);
  len -= sizeof(*conhdr);

  switch (ch->ch_type)
  {
    case PT_SRM2_DATA:
         srm2_data ((struct srmv2_aduhdr*)(conhdr + 1), len);
         return;

    case PT_SRM2_ANNOUNCEMENT:
         srm2_announcement ((struct srmv2_announcehdr*)(conhdr + 1), len);
         break;

    case PT_SRM2_RREQ:
         srm2_rreq ((struct srmv2_rreqhdr*)(conhdr + 1), len);
         break;

    case PT_SRM2_NSREQUEST:
         PUTS (" srm2-nreq");
         break;

    case PT_SRM2_DELAYS:
         PUTS (" srm2-dely");
         break;

    case PT_SRM2_NSREPAIR:
         PUTS (" srm2-nrep");
         break;

    case PT_SRM2_REXMIT:
         srm2_data ((struct srmv2_aduhdr*)(conhdr + 1), len);
         PUTS (" RX ");
         break;

    default:
         PRINTF (" srm2-%d!", ch->ch_type);
#if 0
         {
#define SRM2_STRSIZE 100
           char   str[SRM2_STRSIZE];
           u_int  slen;
           u_char *h = (u_char*)(ch + 1);

           slen = min (snapend-h+1, SRM2_STRSIZE);
           snprintf (str, slen, "%s", (const char*)h);
           PRINTF ("\t%s", str);
         }
#endif
  }
}

⌨️ 快捷键说明

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