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

📄 nitdrive.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/nitdrive.c,v 1.4 2003/01/15 14:04:32 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: nitdrive.c,v $ * Revision 1.4  2003/01/15 14:04:32  josh * directory structure shifting * * Revision 1.3  2001/11/08 15:56:23  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:42  tneale * Tornado shuffle * * Revision 2.19  2001/01/19 22:23:47  paul * Update copyright. * * Revision 2.18  2000/10/20 18:32:25  paul * Properly conditionalized driver.ip_send * * Revision 2.17  2000/10/16 19:21:54  paul * Restore sockets and mempool code. * * Revision 2.16  2000/03/17 00:12:40  meister * Update copyright message * * Revision 2.15  2000/03/13 21:22:06  paul * Removed some code that we are no longer working on. * * Revision 2.14  1999/11/05 22:29:05  paul * Updated driver structs to reflect conditional backwards-compatibility * fields and new fields. * * Revision 2.13  1998/08/17 22:46:40  wes * Silence purify warning * * Revision 2.12  1998/07/31 19:45:48  wes * Put packet filtering into NIT driver... * * Revision 2.11  1998/04/16 17:29:56  wes * Enable use of ethernet media control * * Revision 2.10  1998/02/25 15:21:48  sra * Finish moving types.h, bug.h, and bugdef.h to common/h/. * * Revision 2.9  1998/02/25 04:57:28  sra * Update copyrights. * * Revision 2.8  1997/05/20 02:21:46  mrf * make snark lib driver code use new ldb arp definitions * * Revision 2.7  1997/05/07 17:23:35  mrf * move ipv6_send function to end of net_if structure * * Revision 2.5  1997/05/02 02:45:51  sra * Support NIT in promiscuous mode, for IPv6 multicast. * * Revision 2.4  1997/03/20 06:53:00  sra * DFARS-safe copyright text.  Zap! * * Revision 2.3  1997/02/25 10:58:16  sra * Update copyright notice, dust under the bed. * * Revision 2.2  1997/02/19 08:10:29  sra * More fun merging snmptalk into snark, general snark cleanup. * * 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*//* * Attache code for interfacing to ethernet via the Network Interface Tap * on SunOS 4.1.2. * * This file contains the Attache driver code for NIT. */#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>#include <wrn/wm/util/layout/arp.h>#include <wrn/wm/demo/nit.h>#include <wrn/wm/demo/bsdif.h>#include <wrn/wm/demo/nitdrive.h>struct nit_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 nit_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, (p->pkt_datalen = buflen));  p->pkt_n = cookie;  et_rcv(p);}static void nit_driver_read (int fd, void *cookie, unsigned flags){  struct net *net = cookie;  if ((net->flags & NF_DRIVER_DOWN) == 0 && (flags & BSDIF_READ) != 0)    (void) nit_read(fd, net->driver->maxlen, nit_driver_rcv, net);}/* * Attache device driver routines for NIT. */static void nit_driver_init (struct net *net){  /* This prefix is from "obsolete" portion of DEC's space (see RFC-1340). */  static bits8_t nit_driver_mac_prefix[3] = { 0xAA, 0x00, 0x00 };  struct bsdif *bif = net->specific;  struct nit_driver_private *private;  char *name = net->s_name + STRLEN(net->driver->prefix);  net->flags |= NF_DRIVER_DOWN;  net->speed = TEN_MEGABITS;  if ((bif->private = private = GLUE_ALLOC(sizeof(*private))) == 0)    return;  /*   * Pick a MAC address to use.  If there's already one specified,   * use it.  Otherwise, if we're in 2.x backwards compatability mode and have   * an IP address, use it, otherwise try to generate something unique.   */  if (!net->h_address) {    net->ha_len = sizeof(private->mac);    net->h_address = private->mac;    MEMCPY(private->mac+0, nit_driver_mac_prefix, 3);    if (net->ip_addr) {      MEMCPY(private->mac + 3, ((bits8_t *) &net->ip_addr) + 1, 3);    } else {      extern int gethostid(void);            pid_t proc = getpid();      bits32_t hostid = gethostid();      private->mac[3] = (bits8_t) (proc      & 0xff);      private->mac[4] = (bits8_t) (proc >> 8 & 0xff);      private->mac[5] = (bits8_t) (hostid    & 0xff);    }  }  if ((bif->fd = nit_open(name, net->driver->maxlen, private->mac)) < 0)    return;  bif->handler = nit_driver_read;  bif->flags |= BSDIF_READ;  net->flags &= ~NF_DRIVER_DOWN;}static void nit_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 &&       nit_write(bif->fd, p->pkt_data, p->pkt_datalen) < 0)    perror("NIT write() failure");  pkt_free(p);}static void nit_driver_close (struct net *net){  struct bsdif *bif = net->specific;  if ((net->flags & NF_DRIVER_DOWN) == 0) {    nit_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 nit_driver = {  nit_driver_init,		/* Interface initialization routine  */  nit_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) */  nit_driver_close,		/* Interface close routine */  "nit",			/* Driver short name */  "Network Interface Tap 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,#if !INSTALL_ATTACHE_ETHERNET_NO_MEDIA_CTL  et_media_ctl,			/* Media control routine, if installed */#else  0,				/* No media_ctl routine */ #endif /* !INSTALL_ATTACHE_ETHERNET_NO_MEDIA_CTL */#if INSTALL_ATTACHE_IPV6  et_ipv6_send,			/* IPv6 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 NIT interface devices. * This is just a wrapper to add the Attache-specific things onto nit_find(). */struct nit_driver_find_state {  void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t);  int instance;};static void nit_driver_find_one(char *name, void *cookie){  struct nit_driver_find_state *state = cookie;  state->config(name, &nit_driver, state->instance++, NF_ARP,		nit_driver.maxlen - nit_driver.lnh - nit_driver.lnt,		TEN_MEGABITS);}void nit_driver_find  (void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t)){  struct nit_driver_find_state state;  state.config = config;  state.instance = 0;  nit_find(nit_driver_find_one, &state);}

⌨️ 快捷键说明

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