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

📄 proxylib.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
字号:
/* proxyLib.c - proxy Address Resolution Protocol (ARP) client library *//* Copyright 1984-1997 Wind River Systems, Inc. *//*modification history--------------------01f,26aug97,spm  removed compiler warnings (SPR #7866)01e,11aug93,jmm  Changed ioctl.h and socket.h to sys/ioctl.h and sys/socket.h01d,22sep92,jdi  documentation cleanup.01c,15jun92,elh  changed parameters to proxyReg & proxyUnreg,		 renamed to proxyLib, general cleanup.01b,26may92,rrr  the tree shuffle		  -changed includes to have absolute path from h/01a,20sep91,elh	  written.*//*DESCRIPTIONThis library implements the client side of the proxy Address ResolutionProtocol (ARP).  It allows a VxWorks target to register itself as a proxyclient by calling proxyReg() and to unregister itself by callingproxyUnreg().Both commands take an interface name and an IP address as arguments.  The interface, <ifName>, specifies the interface through which to send themessage.  <ifName> must be a backplane interface.  <proxyAddr> is theIP address associated with the interface <ifName>.INCLUDE FILES: proxyArpLib.hSEE ALSO: proxyArpLib,.pG "Network"INTERNALThis registration process is pretty simple.  Basically the client broadcastsa PROXY_MSG message on the proxy network.  The client retries sendingthe message until it either times out or it receives an ACK from the server.There are currently three types of messages: PROXY_REG, to add the clientas a proxy client, PROXY_UNREG to delete the client as a proxy client,and a PROXY_PROBE message, to probe the server.    proxyReg 	proxyUnreg			v	|	  |			proxyACKRecvHook	v	  v     proxyMsgSend*//* includes */#include "vxWorks.h"#include "proxyArpLib.h"#include "netinet/in.h"#include "sys/socket.h"#include "net/if_arp.h"#include "net/if.h"#include "netinet/if_ether.h"#include "errno.h"#include "arpLib.h"#include "etherLib.h"#include "stdio.h"#include "string.h"#include "sysLib.h"#include "inetLib.h"#include "taskLib.h"/* globals */int			proxyXmitMax 	 = XMIT_MAX;	/* max rexmits      */int			proxyVerbose     = FALSE;	/* debug messages   *//* locals */LOCAL BOOL		proxyAckReceived = FALSE;	/* got ack	    */LOCAL PROXY_MSG 	proxyMsg;			/* proxy message    *//* forward declarations */STATUS proxyMsgSend (char * ifName, char * proxyAddr, int op);LOCAL BOOL proxyACKRecvHook (struct ifnet * pIf, char * einput, int length);/* imports */IMPORT struct ifnet * ifunit ();/********************************************************************************* proxyReg - register a proxy client** This routine sends a message over the network interface <ifName> to register* <proxyAddr> as a proxy client. ** RETURNS: OK, or ERROR if unsuccessful.*/STATUS proxyReg    (    char *			ifName,		/* interface name */    char *  			proxyAddr	/* proxy address  */    )    {    if (proxyMsgSend (ifName, proxyAddr, PROXY_REG) == ERROR)	return (ERROR);    arpFlush ();    return (OK);    }/********************************************************************************* proxyUnreg - unregister a proxy client** This routine sends a  message over the network interface <ifName> to* unregister <proxyAddr> as a proxy client.** RETURNS: OK, or ERROR if unsuccessful.*/STATUS proxyUnreg    (    char *			ifName,		/* interface name */    char * 			proxyAddr	/* proxy address  */    )    {    if (proxyMsgSend (ifName, proxyAddr, PROXY_UNREG) == ERROR)	return (ERROR);    arpFlush ();    return (OK);    }/********************************************************************************* proxyMsgSend - send a proxy message** This routine creates a proxy message with operation type <op>. It then* broadcasts this message over the proxy interface identified by <proxyAddr>.** NOMANUAL** RETURNS: OK, or ERROR if unsuccessful.** ERRNO*   S_proxyArpLib_INVALID_PARAMETER*   S_proxyArpLib_INVALID_INTERFACE*   S_proxyArpLib_INVALID_ADDRESS*   S_proxyArpLib_TIMEOUT** INTERNAL* This routine is global but no manual because it is useful for debugging* purposes.*/STATUS proxyMsgSend    (    char *			ifName,		/* interface name */    char * 			proxyAddr,	/* proxy interface addr */    int				op 		/* operation		*/    )    {    struct ether_header 	eh; 		/* ethernet header	*/    int				ix;		/* index variable	*/    int				delay;		/* xmit delay value 	*/    struct ifnet *		pIf;    if (op < PROXY_PROBE || op >= PROXY_ACK)	{	errno = S_proxyArpLib_INVALID_PARAMETER;	return (ERROR);				/* invalid op */	}					    if ((pIf = ifunit (ifName)) == NULL)	{	errno = S_proxyArpLib_INVALID_INTERFACE;	return (ERROR);                 	/* interface not attached */	}    if ((strcmp (pIf->if_name, "bp") != 0) &&	(strcmp (pIf->if_name, "sm") != 0))	{	printf ("%s:not a backplane device\n", pIf->if_name);	errno = S_proxyArpLib_INVALID_INTERFACE;	return (ERROR);				/* only over backplane */	}    /* fill in proxy message */    bzero ((caddr_t ) &proxyMsg, sizeof (proxyMsg));    proxyMsg.op = htonl (op);    if ((proxyMsg.clientAddr.s_addr = inet_addr (proxyAddr)) == ERROR)	{	errno = S_proxyArpLib_INVALID_ADDRESS;	return (ERROR);	}    bcopy ((caddr_t) ((struct arpcom *)pIf)->ac_enaddr,	   (caddr_t) proxyMsg.clientHwAddr, sizeof (proxyMsg.clientHwAddr));    /* fill in ethernet header */    bzero ((caddr_t) &eh, sizeof (eh));    eh.ether_type = PROXY_TYPE;		/* htons is in ether_output */    bcopy ((char *) etherbroadcastaddr, (char *) eh.ether_dhost,	   sizeof (etherbroadcastaddr));    proxyAckReceived = FALSE;    etherInputHookAdd (proxyACKRecvHook);    if (proxyVerbose)    	printf ("sending <%d> client %s\n", op, proxyAddr);    for (ix = 0; ix < proxyXmitMax; ix++)        {	printf (".");	if (etherOutput (pIf, &eh, (char *) &proxyMsg,		         sizeof (proxyMsg)) == ERROR)	    break;	delay = sysClkRateGet () * XMIT_DELAY;		/* rexmit delay */	while (delay-- > 0)	    {	    if (proxyAckReceived)		{    		etherInputHookDelete ();		return (OK);		}	    taskDelay (1);	    }	}    if (ix == proxyXmitMax)       errno = S_proxyArpLib_TIMEOUT;    etherInputHookDelete ();    return (ERROR);    }/********************************************************************************* proxyACKRecvHook - input hook routine to receive an ACK for proxy message** This module is the hook routine used to receive the ACK for a* previous operation sent to the proxy server via proxyMsgSend.** RETURNS:* TRUE indicating the ethernet frame is handled by this routine and* no further processing need be done by the network interface driver.* FALSE indicating the ethernet frame is to be handled by the network* interface driver.*/LOCAL BOOL proxyACKRecvHook    (    struct ifnet *      	pIf,		/* network interface    */    FAST char *         	einput, 	/* input data frame     */    FAST int            	length         /* input data length    */    )    {    struct ether_header * 	eh;           	/* ethernet header      */    char			inputBuffer [ 2176 ];/* frame buffer 	*/    PROXY_MSG *			pMsg;		/* pointer to message	*/    eh = (struct ether_header *) einput;      if ((length <=  SIZEOF_ETHERHEADER) ||	/* validate type */        (ntohs (eh->ether_type) != PROXY_TYPE))        return (FALSE);							/* copy to buffer */    bcopyBytes ((caddr_t) ((u_char *) einput + SIZEOF_ETHERHEADER),                inputBuffer, length - SIZEOF_ETHERHEADER);    pMsg = (PROXY_MSG *) inputBuffer;    /*  check to make sure I sent out the original message  */    if ((ntohl (pMsg->op) == PROXY_ACK) &&        (pMsg->clientAddr.s_addr == proxyMsg.clientAddr.s_addr) &&        (bcmp ((caddr_t) pMsg->clientHwAddr,(caddr_t) proxyMsg.clientHwAddr,               sizeof (pMsg->clientHwAddr)) == 0))        proxyAckReceived = TRUE;    return (TRUE);    }

⌨️ 快捷键说明

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