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

📄 snoopdrv.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/snoopdrv.c,v 1.4 2003/01/15 14:04:36 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved.  Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** *  Copyright 1994-1997 Epilogue Technology Corporation. *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. ****************************************************************************//* * $Log: snoopdrv.c,v $ * Revision 1.4  2003/01/15 14:04:36  josh * directory structure shifting * * Revision 1.3  2001/11/08 15:56:27  tneale * Updated for newest file layout * * Revision 1.2  2001/11/06 20:11:12  josh * updating include paths to include proper path to layout directory * * Revision 1.1.1.1  2001/11/05 17:48:43  tneale * Tornado shuffle * * Revision 1.18  2001/01/19 22:23:53  paul * Update copyright. * * Revision 1.17  2000/10/20 18:32:25  paul * Properly conditionalized driver.ip_send * * Revision 1.16  2000/10/16 19:21:55  paul * Restore sockets and mempool code. * * Revision 1.15  2000/03/17 00:12:46  meister * Update copyright message * * Revision 1.14  2000/03/13 21:22:10  paul * Removed some code that we are no longer working on. * * Revision 1.13  1999/11/05 22:29:07  paul * Updated driver structs to reflect conditional backwards-compatibility * fields and new fields. * * Revision 1.12  1999/04/28 23:53:26  sra * Clean up various minor installation option glitches. * * Revision 1.11  1998/02/25 15:21:51  sra * Finish moving types.h, bug.h, and bugdef.h to common/h/. * * Revision 1.10  1998/02/25 04:57:41  sra * Update copyrights. * * Revision 1.9  1997/05/20 02:21:50  mrf * make snark lib driver code use new ldb arp definitions * * Revision 1.8  1997/05/07 17:23:38  mrf * move ipv6_send function to end of net_if structure * * Revision 1.6  1997/04/19 02:48:03  mrf * added basic ipv6 code, config ipv6 addresses, added new ipv6_send handler * to snoop and bpf driver structures, added configurable maxlnt and cleaned * up makefile.cfg formatting error * * Revision 1.4  1997/03/20 06:53:13  sra * DFARS-safe copyright text.  Zap! * * Revision 1.3  1997/02/25 10:58:16  sra * Update copyright notice, dust under the bed. * * Revision 1.2  1997/02/19 08:10:29  sra * More fun merging snmptalk into snark, general snark cleanup. * * Revision 1.1  1996/11/13 15:06:46  mrf * Initial revision * * Revision 2.1  1996/03/22  10:05:39  sra * Update copyrights prior to Attache 3.2 release. * * Revision 2.0  1995/05/10  22:38:15  sra * Attache release 3.0. * * Revision 1.3  1995/01/06  00:52:48  sra * Update copyright notice for 2.1 release. * * Revision 1.2  1994/09/04  06:13:38  sra * Clean up antique type names and install macros. * * Revision 1.1  1994/01/09  23:57:29  sra * Add support for NIT under SunOS 4.1.2. * *//* [clearcase]modification history-------------------01a,19apr05,job  update copyright notices*//* * This file contains the Attache driver code for SNOOP. */#include <stdio.h>#include <unistd.h>#include <wrn/wm/attache/config.h>#include <wrn/wm/common/types.h>#include <wrn/wm/attache/mib.h>#include <wrn/wm/attache/timer.h>#include <wrn/wm/attache/packet.h>#include <wrn/wm/attache/net.h>#include <wrn/wm/attache/ether.h>#include <wrn/wm/attache/arp.h>#include <wrn/wm/attache/route.h>#include <wrn/wm/attache/glue.h>#include <wrn/wm/util/layout/ldbglue.h>#inlcude <layout/arp.h>#include <wrn/wm/demo/snoop.h>#include <wrn/wm/demo/bsdif.h>#include <wrn/wm/demo/snoopdrv.h>struct snoop_driver_private {  bits8_t mac[6];		/* MAC address for this interface */};#define	TEN_MEGABITS	10000000/* * Routines to read (struct bsdif) generic network interface. */static void snoop_driver_rcv  (unsigned char *buffer,   unsigned buflen,   unsigned netlen,   void *cookie){  packet *p;    if (buflen != netlen || (p = pkt_alloc(buflen + 2)) == 0)     return;  MEMCPY(p->pkt_data += 2, buffer, buflen);  p->pkt_datalen = buflen;  p->pkt_n = cookie;  et_rcv(p);}static void snoop_driver_read (int fd, void *cookie, unsigned flags){  struct net *net = cookie;  if ((net->flags & NF_DRIVER_DOWN) == 0 && (flags & BSDIF_READ) != 0)    (void) snoop_read(fd, net->driver->maxlen, snoop_driver_rcv, (void *)net);}/* * Attache device driver routines for SNOOP. */static void snoop_driver_init (struct net *net){  /* prefix from "obsolete" portion of dec's space (see rfc1340) */  static bits8_t snp_driver_mac_prefix[3] = { 0xAA, 0x00, 0x00 };  struct bsdif *bif = net->specific;  struct snoop_driver_private *private;  char *name = net->s_name + STRLEN(net->driver->prefix);  pid_t proc = getpid();  bits32_t hostid = gethostid();  net->flags |= NF_DRIVER_DOWN;  net->speed = TEN_MEGABITS;  if (net->h_address == 0)    {      if ((bif->private = private = GLUE_ALLOC(sizeof(*private))) == 0)	return;      net->ha_len = sizeof(private->mac);      net->h_address = private->mac;      MEMCPY(private->mac+0, snp_driver_mac_prefix, 3);      /* use the IP address if we've already got one (this depends on the        * backward compatibility mode sticking the address in the net_if) */      if (net->ip_addr != 0L)	MEMCPY(private->mac+3, ((bits8_t *) &net->ip_addr) + 1, 3);      else {	/* if not, cons up something unique */	*(private->mac+3) |= (bits8_t)(proc & 0xff);	*(private->mac+4) |= (bits8_t)(proc>>8 & 0xff);	if (hostid & 0xff) 	  *(private->mac+5) |= (bits8_t)(hostid & 0xff);      }    }  else    private = (struct snoop_driver_private *) net->h_address;        if ((bif->fd = snoop_open(name, net->driver->maxlen, private->mac)) < 0)    return;  bif->handler = snoop_driver_read;  bif->flags |= BSDIF_READ;  net->flags &= ~NF_DRIVER_DOWN;}static void snoop_driver_send (struct packet *p){  struct bsdif *bif = p->pkt_n->specific;  /*   * Send the packet, logging any error that might occur.   * If the driver is down, just drop the packet.   */  if ((p->pkt_n->flags & NF_DRIVER_DOWN) == 0 &&       snoop_write(bif->fd, p->pkt_data, p->pkt_datalen) < 0)    perror("SNOOP write() failure");  pkt_free(p);}static void snoop_driver_close (struct net *net){  struct bsdif *bif = net->specific;  if ((net->flags & NF_DRIVER_DOWN) == 0) {    snoop_close(bif->fd);    net->flags |= NF_DRIVER_DOWN;  }  if (bif->private) {    GLUE_FREE(bif->private);    bif->private = 0;  }}/* * This could be static now, but it might be useful to leave it visible. */struct driver snoop_driver = {  snoop_driver_init,		/* Interface initialization routine  */  snoop_driver_send,		/* Raw packet send routine */#if INSTALL_ATTACHE_34_IPV4_API_COMPAT  et_ip_send,			/* IP packet send encapsulation routine */#else  0,#endif  et_arp_send,			/* ARP packet send encapsulation routine */  0,				/* Test routine (unused) */  snoop_driver_close,		/* Interface close routine */  "snp",			/* Driver short name */  "SNOOP  Ethernet", 		/* Driver long name */  14,				/* Local net header length */  0,				/* Local net trailer length */  1514,				/* Ethernet frame size */  IF_ETHERNET,			/* MIB type of interfaces using this driver */  ARP_HEADER_HARDWARE_TYPE_is_ETHERNET,  0,                            /* No media control routine */#if INSTALL_ATTACHE_IPV6  et_ipv6_send,			/* IPv6 packet send routine, if installed */#else  0,#endif#if INSTALL_ATTACHE_IPV4  et_ipv4_send			/* IPv4 send routine, if installed */#else  0#endif /* INSTALL_ATTACHE_IPV4 */};/* * Routines for finding SNOOP interface devices. * This is just a wrapper to add the Attache-specific things onto snoop_find(). */struct snoop_driver_find_state {  void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t);  int instance;};static void snoop_driver_find_one(char *name, void *cookie){  struct snoop_driver_find_state *state = cookie;  state->config(name, &snoop_driver, state->instance++, NF_ARP,		snoop_driver.maxlen - snoop_driver.lnh - snoop_driver.lnt,		TEN_MEGABITS);}void snoop_driver_find  (void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t)){  struct snoop_driver_find_state state;  state.config = config;  state.instance = 0;  snoop_find(snoop_driver_find_one, &state);}

⌨️ 快捷键说明

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