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

📄 _rip.c

📁 This directory contains source code for tcpdump, a tool for network monitoring and data acquisition
💻 C
字号:
/* 
 * Copyright (c) 1989, 1990, 1991, 1993, 1994, 1996
 *      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.
 */

#include <stdio.h>
#include <time.h>
#include <sys/socket.h>

#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>

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

struct rip {
       u_char  rip_cmd;       /* request/response */
       u_char  rip_vers;      /* protocol version # */
       u_short rip_zero2;     /* unused */
     };

#define RIPCMD_REQUEST    1   /* want info */
#define RIPCMD_RESPONSE   2   /* responding to request */
#define RIPCMD_TRACEON    3   /* turn tracing on */
#define RIPCMD_TRACEOFF   4   /* turn it off */
#define RIPCMD_POLL       5   /* want info from everybody */
#define RIPCMD_POLLENTRY  6   /* poll for entry */

struct rip_netinfo {
       u_short    rip_family;
       u_short    rip_tag;
       u_int32_t  rip_dest;
       u_int32_t  rip_dest_mask;
       u_int32_t  rip_router;
       u_int32_t  rip_metric;    /* cost of route */
     };

static void rip_entry_print (int vers, const struct rip_netinfo *ni)
{
  u_char *cp, *ep;

  if (EXTRACT_16BITS (&ni->rip_family) != AF_INET)
  {
    PRINTF (" [family %d:", EXTRACT_16BITS (&ni->rip_family));
    cp = (u_char *) & ni->rip_tag;
    ep = (u_char *) & ni->rip_metric + sizeof(ni->rip_metric);
    for (; cp < ep; cp += 2)
       PRINTF (" %04x", EXTRACT_16BITS (cp));
    PUTS ("]");
  }
  else if (vers < 2)
  {
    /* RFC 1058 */
    PUTCHAR (' ');
    PUTS (ipaddr_string (&ni->rip_dest));
  }
  else
  {
    /* RFC 1723 */
    PRINTF (" {%s", ipaddr_string (&ni->rip_dest));
    if (ni->rip_dest_mask)
       PRINTF ("/%s", ipaddr_string (&ni->rip_dest_mask));
    if (ni->rip_router)
       PRINTF ("->%s", ipaddr_string (&ni->rip_router));
    if (ni->rip_tag)
       PRINTF (" tag %04x", EXTRACT_16BITS (&ni->rip_tag));
    PUTS ("}");
  }
  PRINTF ("(%ld)", EXTRACT_32BITS (&ni->rip_metric));
}

void rip_print (const u_char * dat, u_int length)
{
  const struct rip *rp;
  const struct rip_netinfo *ni;
  int   i, j, trunc;

  i = min (length, snapend - dat) - (sizeof(*rp) - sizeof(*ni));
  if (i < 0)
     return;

  rp = (struct rip *) dat;
  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);
         ni = (struct rip_netinfo *) (rp + 1);
         for (; (i -= sizeof(*ni)) >= 0; ++ni)
            rip_entry_print (rp->rip_vers, ni);
         if (trunc)
            PUTS ("[|rip]");
         break;

    case RIPCMD_TRACEON:
         PRINTF (" rip-traceon %d: \"", length);
         fn_print ((char *) (rp + 1), (char *) snapend);
         PUTS ("\"\n");
         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;
  }
  switch (rp->rip_vers)
  {
    case 1:
    case 2:
         break;

    default:
         PRINTF (" [vers %d]", rp->rip_vers);
         break;
  }
}

⌨️ 快捷键说明

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