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

📄 netrom.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
字号:
/* netrom.c - XLNT Design's netrom backend library *//* Copyright 1984-1995 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01h,01jul98,c_c  Fixed an include Pb on HP.01g,01jul98,c_c  Ported to backend V2 API.01f,20mar98,pcn  Changed FALSE to ERROR.01e,03mar98,c_c  Removed clnt_soc.h for WIN32.01d,03feb98,dbt  corrected clntudp_create() call.01c,28jun96,c_s   just include <fcntl.h>; this is more portable.01b,15jan96,elp	  added external function variable (WIN32)		  + modified netromInit() to initialize this variable.01a,27sep95,tpr	  written, inspired from /backend/wdbrpc/wdbrpc.c version 02m.*//*DESCRIPTIONThis backend utilizes the XLNT Designs NetRom rom emulator to form acommunication path the target running the WDB agent.  It requires aspecial netRom driver to be configured into the target agent.*//* includes */#include <netdb.h>#include <netinet/in.h>#include <arpa/inet.h>#include <rpc/rpc.h>#include <sys/socket.h>#include <sys/time.h>#ifndef WIN32#ifdef SUN4_SOLARIS2#include <rpc/clnt_soc.h>#endif#endif#include "tgtlib.h"#include "wpwrlog.h"#include "host.h"#include "bkendlib.h"/* defines *//* forward declarations */extern STATUS rpcCoreInit (CLIENT *, u_int, u_int, TGT_OPS *);/* locals */LOCAL u_int netromTimeout       = BKEND_TIMEOUT;/* backend timeout */LOCAL u_int netromRetry         = BKEND_RESEND; /* backend resend number */static FLAG_DESC netromFlags [] =    {	{    	"-Btimeout","-Bt", (PARSE_RTN) flagInt,    &netromTimeout,	"-Bt[imeout] value\tNetRom Backend request timeout (default 1 sec.)."	},	{    	"-Bresend", "-Br", (PARSE_RTN) flagInt,    &netromRetry,	"-Br[esend] number\tNetRom Backend request re-send number (default 3)."	},	{NULL, NULL, NULL, NULL, NULL}		/* End Of Record delimiter */    };/********************************************************************************* netromFlagsGet - Get the supported flags for this backend** This function is called by the target server when it wants to get the flags* which are supported by the currently attached backend. The following options* can be set trough command line parameters.** <timeout> is the time out duration to use for the communication with the* WDB target agent. This input argument is set when the target server is* started with the option -Bt. Otherwise set to zero.** <recallNum> is the maximun number of time that a request is re-sent before* to admit the communication link is broken. Set when the target server is* started with the option -Br, otherwise reset to zero.** Here we return our supported flags.**/DLL_EXPORT FLAG_DESC *  netromFlagsGet (void)    {    return (FLAG_DESC *) netromFlags;    }/********************************************************************************* netromInitialize - initialize the backend interface** This function is called by the target server when it wants to attach this* backend. Three input arguments are accepted:** <tgtName> is a pointer to a string that handles either the name or the* internet address (in dotted-decimal * format) of the target board. ** <pTgtOps> is a pointer to TGT_OPS structure (defined in tgtlib.h file).* This structure handles function pointers used by the target server to call* a backend function. The backend attachment is performed by filling this* structure with the backend function address. ** <pBkInfo> is a structure to fill for the target server to know if the backend* exports a selectable file descriptor, a select-like function, or nothing for* the asynchronous event notification. * Remember that the target server now dedicates a thread to the event* notification.** This function initializes the backend. It creates the backend client, resets* the udp datagram sequence number and fills the TGT_OPS structure with* the information describing the backend and returns a pointer to this * structure.** CAVEAT: its name is built from the file name concatenated with the string*         "Initialize". This is compulsory.* * RETURNS: TRUE if the backend is properly initialized, otherwise FALSE.*/DLL_EXPORT STATUS netromInitialize    (    char *		tgtName,	/* target name to connect to */    TGT_OPS *		pTgtOps,	/* backend function */    BKEND_INFO *	pBkInfo		/* Backend info and select method */    )    {    CLIENT *		pClnt;		/* target client */    u_long		addr;		/* target address: long int format */    struct sockaddr_in	dest_addr;	/* target address information */    struct hostent *	dest_host;	/* target address */    int			wdbSocket;	/* backend client socket */    struct timeval 	tv;		/* connection timeout */    u_int		resendCnt;	/* connection re-send counter */    /* clear dest_addr */    memset ((void *) &dest_addr, 0x00, sizeof (dest_addr));    /* convert <tgtName> into the target board Internet address */    if ((dest_host = (struct hostent *) gethostbyname (tgtName)) == NULL)	{	if ((addr = inet_addr (tgtName)) == (u_long) ERROR)	    {	    errno = WTX_ERR_SVR_TARGET_UNKNOWN;	    wpwrLogErr ("Target %s unknown. Attach failed.\n", tgtName);	    return (ERROR);	    }	dest_addr.sin_addr.s_addr = addr;	}    else	dest_addr.sin_addr.s_addr = * ((u_long *) dest_host->h_addr_list[0]);    /* set the socket with the input informaton */    dest_addr.sin_family = AF_INET;    dest_addr.sin_port	 = htons (1235);		/* XXX define 1235! */    wdbSocket		 = RPC_ANYSOCK;    /* set the connection timeout to the current value */    tv.tv_sec  = netromTimeout;    tv.tv_usec = 0;    /*     * set the resendCnt counter with the maximun of time the client creation     * will be re-tried.     */    resendCnt = netromRetry;    do	{    	/* create the backend client and connect the target deamon */	pClnt = clntudp_create (&dest_addr, WDBPROG, WDBVERS, tv, &wdbSocket);	}    while ((pClnt == NULL) && (--resendCnt > 0));    /*     * check the client creation : If the creation failed, log a message with     * the RPC error and return ERROR to stop the target server initialization.     */    if (pClnt == NULL)	{	wpwrLogErr ("%s", clnt_spcreateerror("netrom backend client create"));	return (ERROR);	}    /* initialize the rpc core */    rpcCoreInit (pClnt, netromTimeout, netromRetry, pTgtOps);    /* describe the link used between the backend and the target */    pTgtOps->tgtLink.name		= "WDB NetRom";    pTgtOps->tgtLink.type		= TGT_LINK_ETHERNET_RPC;    pTgtOps->tgtLink.speed		= SPEED_ETHERNET;    pBkInfo->tgtBkVersion = BKEND_VERSION_2;    /* Backend version 2 */    /* We give here our polling method : a selectable socket */    pBkInfo->INFO.POLLING_METHOD.bkEndPollingMethod = POLL_SELECT_MODE;    pBkInfo->INFO.POLLING_METHOD.BKEND_NOTIF_METHOD.pollingFd =		    pTgtOps->tgtEventFd;    return (OK);    }

⌨️ 快捷键说明

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