📄 pktd.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/pktd.c,v 1.3 2003/01/15 14:04:33 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 1992-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. *****************************************************************************//* * $Log: pktd.c,v $ * Revision 1.3 2003/01/15 14:04:33 josh * directory structure shifting * * Revision 1.2 2001/11/08 15:56:24 tneale * Updated for newest file layout * * Revision 1.1.1.1 2001/11/05 17:48:42 tneale * Tornado shuffle * * Revision 2.10 2001/01/19 22:23:48 paul * Update copyright. * * Revision 2.9 2000/03/17 00:12:42 meister * Update copyright message * * Revision 2.8 1998/09/04 04:00:09 sar * modified some #if statements to use #ifdef as they were testing * items that might not be defined - INSTALL_on_* options. * * Revision 2.7 1998/02/25 04:57:30 sra * Update copyrights. * * Revision 2.6 1998/02/20 23:07:23 sra * Add multicast and IPv6 support. * * Revision 2.5 1998/02/19 07:46:08 sra * Preliminary multicast support. * * Revision 2.4 1997/03/20 06:53:02 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 1996/03/22 10:05:39 sra * Update copyrights prior to Attache 3.2 release. * * Revision 2.1 1996/03/14 16:34:57 dab * Workaround for bug in Xircom packet drivers. * * Revision 2.0 1995/05/10 22:38:15 sra * Attache release 3.0. * * Revision 1.6 1995/01/06 00:52:48 sra * Update copyright notice for 2.1 release. * * Revision 1.5 1993/08/03 01:28:42 sra * Different install option for MSC. * * Revision 1.4 1993/07/31 02:01:16 sra * Flush boolean_t from this file. * * Revision 1.3 1993/07/31 01:28:33 sra * Get automatic compiler configuration stuff right this time. * * Revision 1.2 1993/07/31 00:53:55 sra * Changes for Borland C++ 3.1. * * Revision 1.1 1993/07/30 02:41:24 sra * Initial revision * *//* [clearcase]modification history-------------------01a,19apr05,job update copyright notices*//* * Low-level interface routines to FTP Software spec packet driver. * This is DAB's pkt.c with very minor cosmetic changes. * * The modularity here is not yet quite what I had in mind, I'd prefer * to move all knowledge of Attache and Snark out of this file, leaving * nothing but packet driver stuff; the Attache/Snark stuff should all be * in pktdrive.c. But we've got a deadline to make, and it's not too bad * as it stands, so this will be left for a future version of this code. *//* * Stuff to configure us for a particular DOS compiler (BCC, MSC, whatever). */#include <wrn/wm/common/install.h>#ifdef INSTALL_on_microsoft#include <wrn/wm/demo/pktd_msc.h>#endif#ifdef INSTALL_on_bcc#include <wrn/wm/demo/pktd_bcc.h>#endif/* * Definitions for this module. */#include <wrn/wm/demo/pktd.h>/* * Error codes from packet drivers. */static char *pd_error_strings[] = { "no error", "bad handle", "no class", "no type", "no number", "bad type", "no multicast", "can't terminate", "bad mode", "no space", "type in use", "bad command", "can't send",};char *pd_perror(int err){ if (err >= 0 && err < sizeof(pd_error_strings)/sizeof(*pd_error_strings)) return pd_error_strings[err]; else if (err == PDE_NO_PKT_DRVR) return "no packet driver"; else return "unknown error";}/* * Returns non-zero if pd_int looks like a packet driver interrupt. */#define DOSGETVECTOR 0x35int pd_check_int(int pd_int){ union REGS r; struct SREGS sr; unsigned char far *fcp; static char word_pkt[] = "PKT ", word_drvr[] = "DRVR"; unsigned long *wordp; unsigned long far *wordfp; if (pd_int < PKTDRVR_MIN_INT || pd_int > PKTDRVR_MAX_INT) return 0; r.h.ah = DOSGETVECTOR; r.h.al = (unsigned char) pd_int; intdosx(&r, &r, &sr); if ((fcp = MK_FP(sr.es, r.x.bx)) == 0 || (*fcp != 0xe9 && *fcp != 0xeb)) return 0; wordfp = (unsigned long far *) (fcp + 3); wordp = (unsigned long *) word_pkt; if (*wordfp != *wordp) return 0; wordfp = (unsigned long far *) (fcp + 7); wordp = (unsigned long *) word_drvr; if (*wordfp != *wordp) return 0; return 1;}/* * Gets the packet driver information, fills in driver information in pd_net. * Returns PDE_NO_ERROR if successful, otherwise a packet driver error code. */int pd_driver_info(int handle, struct pd_net *pdn){ union REGS r; struct SREGS sr; r.h.ah = PF_DRIVER_INFO; r.h.al = 255; int86x(pdn->pd_int, &r, &r, &sr); if (r.x.cflag) /* if error return */ return r.h.dh;#if 0 /* the Xircom packet driver doesn't do this right. */ if (r.h.ah == 255) /* if no packet driver loaded */ return PDE_NO_PKT_DRVR;#endif pdn->drvr_info.version = r.x.bx; pdn->drvr_info.pdtype = r.x.dx; pdn->drvr_info.class = r.h.ch; pdn->drvr_info.number = r.h.cl; pdn->drvr_info.name = MK_FP(sr.ds, r.x.si); pdn->drvr_info.basic_flag = r.h.al; return PDE_NO_ERROR;}/* * Calls the packet driver to pick up packets of type type. Returns a * packet driver error code. The handle is stored in *handle if no error. */int pd_access_type (struct pd_net *pdn, int *handle, unsigned char far *type_field, int type_len){ union REGS r; struct SREGS sr; r.h.ah = PF_ACCESS_TYPE; r.h.al = pdn->drvr_info.class; r.x.bx = pdn->drvr_info.pdtype; r.h.dl = pdn->drvr_info.number; sr.ds = FP_SEG(type_field); r.x.si = FP_OFF(type_field); r.x.cx = type_len; sr.es = FP_SEG(pdn->device_receive_rtn); r.x.di = FP_OFF(pdn->device_receive_rtn); int86x(pdn->pd_int, &r, &r, &sr); if (r.x.cflag) return r.h.dh; /* error code */ *handle = r.x.ax; return PDE_NO_ERROR;}/* * Calls the packet driver to stop getting packets of type type. Returns a * packet driver error code. */int pd_release_type(struct pd_net *pdn, int handle){ union REGS r; struct SREGS sr; r.h.ah = PF_RELEASE_TYPE; r.x.bx = handle; int86x(pdn->pd_int, &r, &r, &sr); if (r.x.cflag) return r.h.dh; /* error code */ return PDE_NO_ERROR;}/* * Calls the packet driver to get the mac addrss of this interface. * Returns a packet driver error code. */int pd_get_address (struct pd_net *pdn, unsigned char far *address_buffer, int buffer_length){ union REGS r; struct SREGS sr; r.h.ah = PF_GET_ADDRESS; r.x.bx = pdn->handle; r.x.cx = buffer_length; sr.es = FP_SEG(address_buffer); r.x.di = FP_OFF(address_buffer); int86x(pdn->pd_int, &r, &r, &sr); if (r.x.cflag) return r.h.dh; /* error code */ return PDE_NO_ERROR;}/* * Calls the packet driver to send a packet. * Returns a packet driver error code. */int pd_send_pkt (struct pd_net *pdn, unsigned char far *address_buffer, unsigned int buffer_length){ union REGS r; struct SREGS sr; r.h.ah = PF_SEND_PKT; r.x.cx = buffer_length; sr.ds = FP_SEG(address_buffer); r.x.si = FP_OFF(address_buffer); int86x(pdn->pd_int, &r, &r, &sr); if (r.x.cflag) return r.h.dh; /* error code */ return PDE_NO_ERROR;}/* * Calls the packet driver to get the current receive mode, stores that * in *mode on success. Returns a packet driver error code. */int pd_get_rcv_mode(struct pd_net *pdn, int *mode){ union REGS r; struct SREGS sr; r.h.ah = PF_GET_RCV_MODE; r.x.bx = pdn->handle; int86x(pdn->pd_int, &r, &r, &sr); if (r.x.cflag) return r.h.dh; /* error code */ *mode = r.x.ax; return PDE_NO_ERROR;}/* * Calls the packet driver to set the current mode. * Returns a packet driver error code. */int pd_set_rcv_mode(struct pd_net *pdn, int mode){ union REGS r; struct SREGS sr; r.h.ah = PF_SET_RCV_MODE; r.x.bx = pdn->handle; r.x.cx = mode; int86x(pdn->pd_int, &r, &r, &sr); if (r.x.cflag) return r.h.dh; /* error code */ return PDE_NO_ERROR;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -