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

📄 snarkbsd.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/snarkbsd.c,v 1.3 2003/01/15 14:04:35 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 1993-1997 Epilogue Technology Corporation. *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. ****************************************************************************//* * $Log: snarkbsd.c,v $ * Revision 1.3  2003/01/15 14:04:35  josh * directory structure shifting * * Revision 1.2  2001/11/08 15:56:26  tneale * Updated for newest file layout * * Revision 1.1.1.1  2001/11/05 17:48:43  tneale * Tornado shuffle * * Revision 2.45  2001/06/12 08:06:24  paul * Error-check ETC_COND_INIT. * * Revision 2.44  2001/02/09 20:14:05  paul * Trivial cleanup. * * Revision 2.43  2001/01/19 22:23:52  paul * Update copyright. * * Revision 2.42  2000/10/16 19:21:54  paul * Restore sockets and mempool code. * * Revision 2.41  2000/03/17 00:12:45  meister * Update copyright message * * Revision 2.40  2000/03/13 21:22:09  paul * Removed some code that we are no longer working on. * * Revision 2.39  1999/05/21 22:26:34  wes * Add locking around attache_init() * * Revision 2.38  1999/04/26 19:04:59  sra * Fix a few minor warnings, fix a few Solaris-specific problems in the * demo code. * * Revision 2.37  1999/03/04 19:43:25  wes * Make snark_exit really work * * Revision 2.36  1999/03/04 17:53:36  wes * GC some unused code.  Clean up deferred_io_first call, * leaving some asserts behind to catch any mistakes * * Revision 2.35  1999/02/18 04:41:35  wes * Sockets merge: Everything Else *  - memory pools *  - thread support *  - port-specific headers * * Revision 2.34.2.8  1999/01/21 20:46:34  wes * Allow to build again when ATTACHE_THREADS turned off.. * * Revision 2.34.2.7  1999/01/07 22:29:33  wes * avoid dfq initialization race condition; try one other place for the callout * * Revision 2.34.2.6  1998/11/13 18:17:26  wes * Make SNARK_*LOCK*() calls into the "real" attache global lock * ATTACHE_*LOCK*() and make it live in attache-land, not snark-land. * * Revision 2.34.2.5  1998/11/09 20:37:42  paul * break the infinite loop Bill created in tasks_run() * * Revision 2.34.2.4  1998/10/23 20:06:15  wes * Rearrange which threads timer runs in.. now it's in the io thread, so * that timer-based receives (the loopback i/f sets a timer which goes * off immediately) don't cause problems for sockets & the deferral queue.. * * Revision 2.34.2.3  1998/10/22 22:07:19  wes * Rearrange dfq callouts from both snarkbsd/snrkpsos so that `first' * callout is actually guaranteed to happen. * * Revision 2.34.2.2  1998/10/21 22:45:21  wes * Deferral queue is only to be accessed from one thread.  Make sure we * do this right, by adding hooks for pseudo-lock for the dfq * (implemented as a real lock, which is locked once and left that way. * All we do with it is LOCK_ASSERTS that we have in fact locked it. * If all you have is a hammer...) * * Revision 2.34.2.1  1998/09/23 19:17:22  wes * Merge socket-branch-1 changes to socket-branch-2 * * Revision 2.34  1998/09/14 20:13:44  wes * make DLPI driver filenames 8.3 safe.. * * Revision 2.33.4.3  1998/09/11 21:32:03  wes * Rename EPI_ prefix thread primitives to ETC_ prefix * * Revision 2.33.4.2  1998/09/09 18:19:54  wes * First cut deferral queue implementation.  (Good enough for UDP...) * * Revision 2.33.4.1  1998/08/19 13:26:34  wes * Merge sockets-pthreads work to shared branch * * Revision 2.33  1998/07/29 20:54:53  wes * First cut of the Solaris port. * (DLPI support, termios, minor tweaks to libraries and port header files) * * Revision 2.32  1998/07/17 18:58:42  sra * Swap and checksum routines moved to separate files. * * Revision 2.31  1998/07/02 06:55:37  sra * Make Snark restartable under pSOS, and other minor cleanups. * * Revision 2.30  1998/06/11 20:02:37  wes * Add driver for BSD tunnel interface * * Revision 2.29  1998/03/23 17:38:13  sra * Put glue_set_time() under INSTALL_ATTACHE conditional. * * Revision 2.28  1998/03/03 20:38:19  mrf * Change GLUE_SNTP_SET_TIME macro to take packet pointer * * Revision 2.27  1998/02/25 15:21:50  sra * Finish moving types.h, bug.h, and bugdef.h to common/h/. * * Revision 2.26  1998/02/25 04:57:38  sra * Update copyrights. * * Revision 2.25  1998/02/12 20:27:52  mrf * Configure SNTP client code. * * Revision 2.24  1997/11/18 18:05:19  sra * Make PPP work on Purify/SunOS testbed. * * Revision 2.23  1997/11/04 16:11:32  josh * Adding Liaison support files * * Revision 2.22  1997/10/29 22:23:20  sar * moved the call to envoy_init() from snmp_init() in snmpfunc.c to * snark_init() in snarkbsd.c & snarkdos.c * * Revision 2.21  1997/10/28 00:51:54  sra * Convert PPP code to use BUG() macro. * Bang on CHAP and PAP code some more. * Create test driver for PPP under Snark/BSD. * * Revision 2.20  1997/08/21 17:23:48  sra * Begin moving configuration stuff that's common to all products to common.h * Minor cleanups to common/lib/prng.c.  Add pnrg seed function to snarkbsd. * * Revision 2.19  1997/07/17 03:38:42  alan * Add: snark_reset_read_fdproc & snark_reset_write_fdproc.  Like * snark_set_fdprocs, but only makes you mess with the procedure you're * interested in. * * Revision 2.18  1997/06/15 01:46:07  mrf * changed IPADDR_* and related macros to use pointers instead of immediates * as arguments, also changed to GET/SET/PTR forms * * Revision 2.17  1997/05/22 03:39:17  sra * Don't depend on ancient NF_DOWN kludge in if_attach(). * * Revision 2.16  1997/05/20 02:21:49  mrf * make snark lib driver code use new ldb arp definitions * * Revision 2.15  1997/05/20 02:08:07  mrf * ipaddr_t, ldb macro and routing api conversion of media layer and arp code * * Revision 2.14  1997/05/19 04:27:08  alan * Let others have access to the basic file descriptor * select() loop in the task dispatcher. * * Revision 2.13  1997/05/11 06:10:34  alan * Fix buglet where microseconds were confused with milliseconds. * * Revision 2.12  1997/04/19 02:48:02  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 2.11  1997/03/20 06:52:55  sra * DFARS-safe copyright text.  Zap! * * Revision 2.10  1997/03/19 22:05:42  sra * Perhaps we should include install.h before testing install options? * * Revision 2.9  1997/03/19 04:47:35  sra * Get rid of some gratuitous historical dependencies on Attache. * * Revision 2.8  1997/02/25 10:58:16  sra * Update copyright notice, dust under the bed. * * Revision 2.7  1997/02/24 00:56:59  sra * Support for run-time configuration of BUG() macros. * * Revision 2.6  1997/02/19 08:10:29  sra * More fun merging snmptalk into snark, general snark cleanup. * * Revision 2.5  1997/01/08 01:20:46  sar * Moved the glue_pkt_handle routine from snark*.c to loopglue.c * and added loopglue.c to the base object list. * * Revision 2.4  1996/11/13  15:09:16  mrf * Changes necessary to make snoop support work on Irix 5.x include * addition of snoop driver code and port to somewhat wacky Irix * curses implementation. * * Revision 2.3  1996/04/23  22:05:58  lowell * added ARP-for-my-own-address on startup * (to solve problems associated with making up ethernet addresses * out of thin air) * * Revision 2.2  1996/03/22  10:05:39  sra * Update copyrights prior to Attache 3.2 release. * * Revision 2.1  1995/09/21  18:52:57  sra * Fix compile-time initialization to conform to current theory of how * INSTALL_ATTACHE_RESTARTABLE works. * * Revision 2.0  1995/05/10  22:38:15  sra * Attache release 3.0. * * Revision 1.8  1995/03/26  02:46:39  sra * Add vapornet driver. * * Revision 1.7  1995/01/06  00:52:48  sra * Update copyright notice for 2.1 release. * * Revision 1.6  1994/09/05  05:37:27  sra * Disable attempt to start clock at zero, it screws up timers set by * attache_init() and is silly in any case. * * Revision 1.5  1994/09/04  06:13:38  sra * Clean up antique type names and install macros. * * Revision 1.4  1994/01/09  23:57:29  sra * Add support for NIT under SunOS 4.1.2. * * Revision 1.3  1993/07/31  23:36:34  sra * Flush prototype for write(), type conflict. * * Revision 1.2  1993/07/31  23:26:09  sra * Add keyboard_write(). * * Revision 1.1  1993/07/05  21:53:30  sra * Initial revision * *//* [clearcase]modification history-------------------01a,19apr05,job  update copyright notices*//* * Snark for BSD-derived systems.  Currently known to work on FreeBSD * (1.1.5.1 and later) and SunOS 4.1.4, should work on other BSD derived * systems with minor work. */#include <wrn/wm/common/install.h>#include <wrn/wm/common/types.h>#if INSTALL_ATTACHE#include <wrn/wm/attache/config.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/glue.h>#include <wrn/wm/attache/route.h>#include <wrn/wm/attache/ip.h>#include <wrn/wm/attache/loop.h>#if INSTALL_ATTACHE_PPP#include <wrn/wm/attache/ppp.h>#endif#if INSTALL_ATTACHE_THREADS#include <wrn/wm/attache/attthd.h>#else#define ATTACHE_LOCK()#define ATTACHE_UNLOCK()#endif#endif /* INSTALL_ATTACHE */#if INSTALL_ENVOY#include <wrn/wm/snmp/engine/snmpdefs.h>#endif#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/time.h>#if INSTALL_SNARK_TERMIOS#include <termios.h>#else#include <sgtty.h>#endif#include <wrn/wm/demo/snarklib.h>#include <wrn/wm/demo/bsdif.h>#if INSTALL_ATTACHE#include <wrn/wm/demo/netconf.h>#endif#if INSTALL_SNARK_BSD_BPF#include <wrn/wm/demo/bpfdrive.h>#endif#if INSTALL_SNARK_BSD_NIT#include <wrn/wm/demo/nitdrive.h>#endif#if INSTALL_SNARK_DLPI#include <wrn/wm/demo/dlpidrv.h>#endif#if INSTALL_SNARK_BSD_SNOOP#include <wrn/wm/demo/snoopdrv.h>#endif#if INSTALL_SNARK_BSD_SLIP#include <wrn/wm/demo/slipbsd.h>#endif#if INSTALL_SNARK_BSD_PPP#include <wrn/wm/demo/pppbsd.h>#endif#if INSTALL_SNARK_BSD_VAPORNET#include <wrn/wm/demo/vapornet.h>#endif#if INSTALL_SNARK_BSD_TUN#include <wrn/wm/demo/tundrive.h>#endif#if INSTALL_LIAISON#include <liaison/hrmon/rmonapi.h>#endif/* * These are defined here rather than in snark/lib/main.c so that this * code can be used without that module if the customer so desires. */int snark_exit_flag, snark_exit_value;static struct bsdif *bsdif_list;/* Current time in milliseconds, no particular origin. */bits32_t glue_now(){  struct timeval tm;  if (gettimeofday(&tm, 0) < 0)    return 0;  return (tm.tv_sec * 1000UL + tm.tv_usec / 1000UL);}/* * We don't need this, but it's used by Attache in such a way that * turning it into a no-op macro generates compiler warnings.  Sigh. */int glue_intlock(int x){  return x;}#if INSTALL_COMMON_PRNG/* * Seed value for pseduo random number generator. * Snarf some moderately unpredictable bits and jumble them together. */#ifndef PRNG_SEED_CMD#define PRNG_SEED_CMD \  "exec 2>&1; netstat -naA; ps -gauxww; arp -a; uptime; date; echo $$"#endifunsigned glue_seed_prng(bits8_t *buffer, unsigned length){  FILE *f = popen(PRNG_SEED_CMD, "r");  int c, i = 0, n = 0;  BUG_ASSERT(length != 0);  if (f) {    while ((c = getc(f)) != EOF) {      buffer[i] = (c ^ ((buffer[i] << 1) + (!(buffer[i] & 0x80)))) & 0xFF;      i = (i + 1) % length;      n++;    }    fclose(f);  }  return n < length ? n : length;}#endif /* INSTALL_COMMON_PRNG *//* * Low level keyboard handler stuff. * This assumes the keyboard is non-blocking. */#ifdef __NetBSD__/* !!! mit_pthreads select() prototype is missing */int	 select __P((int, fd_set *, fd_set *, fd_set *, struct timeval *));#endifstatic void (*kbd_handler)(unsigned char *, size_t);static int kbd_eof;void keyboard_handler(void (*handler)(unsigned char *, size_t)){  kbd_handler = handler;}static void kbd_rcv(){  unsigned char c;  int r;  ATTACHE_UNLOCK();  r = read(0, &c, 1);    ATTACHE_LOCK();    switch (r)   {   case 0:    kbd_eof = 1;    break;   case 1:    if (kbd_handler)      (*kbd_handler)(&c, 1);    break;  }}#if INSTALL_SNARK_TERMIOSstatic struct termios old_tty;#elsestatic struct sgttyb old_tty;#endifstatic boolean_t old_tty_valid;static void keyboard_init(){  kbd_handler = 0;  kbd_eof = 0;#if INSTALL_SNARK_TERMIOS  old_tty_valid = (tcgetattr(0, &old_tty) == 0);  if (old_tty_valid) {    struct termios tty = old_tty;    tty.c_iflag |= IGNPAR;    tty.c_lflag &= ~(ECHO|ICANON);#ifdef OXTABS    tty.c_oflag &= ~OXTABS;	/* BSD 4.4 termios */#endif#ifdef XTABS    tty.c_oflag &= ~XTABS;	/* solaris termios */#endif    tty.c_cflag &= ~(PARENB|PARODD);    tty.c_cc[VMIN] = 1;    tty.c_cc[VTIME] = 0;    tcsetattr(0, TCSANOW, &tty);  }#else /* INSTALL_SNARK_TERMIOS */  old_tty_valid = ioctl(0, TIOCGETP, &old_tty) != -1;  if (old_tty_valid) {    struct sgttyb tty = old_tty;    tty.sg_flags &= ~(ECHO | XTABS); /* | CRMOD */    tty.sg_flags |= (ANYP | CBREAK);    if (ioctl(0, TIOCSETN, &tty) == -1)      perror("unable to set CBREAK mode, ignoring");  }#endif /* INSTALL_SNARK_TERMIOS */}static void keyboard_shutdown(){#if INSTALL_SNARK_TERMIOS  if (old_tty_valid && tcsetattr(0, TCSANOW, &old_tty) == -1)    perror("unable to restore old tty modes");#else  if (old_tty_valid && ioctl(0, TIOCSETN, &old_tty) == -1)    perror("unable to restore old tty modes");#endif}void keyboard_write(unsigned char *text, size_t length){  if (text && length)    (void) write(1, text, length);}/* * tasks_run() function, using system-independent tasking queue. */static bits32_t glue_callin_when;static void (*glue_callin_who)(void);#if INSTALL_ATTACHE_THREADSint hack_pipe[2];etc_cond_t task_queue;etc_thread_t io_runner_thd;etc_thread_t kbd_runner_thd;void task_kick_init(void){  if (ETC_COND_INIT(&task_queue, &attache_lock) != 0)    printf("task_kick_init: ETC_COND_INIT failed!\n");}void task_kick(){  ETC_COND_WAKEUP(&task_queue, &attache_lock);}void io_kick(){  if (hack_pipe[1]) {    write(hack_pipe[1], "x", 1);

⌨️ 快捷键说明

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