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

📄 wtxrpc.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* wtxrpc.c - tornado rpc transport library *//* Copyright 1984-1996 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02w,28sep01,fle  SPR#28684 : added usePMap parameter to ExchangeCreate ()                 routines02v,15jun01,pch  Add new WTX_TS_INFO_GET_V2 service to handle WTX_RT_INFO                 change (from BOOL32 hasFpp to UINT32 hasCoprocessor) without                 breaking existing clients.02u,19apr00,fle  SPR#28684 : Win32 port02t,29mar00,fle  SPR#28684 : HPUX port02s,24nov99,fle  SPR#28684 fix : multiple adapters in target server connection02r,10may99,fle  made wtxRpcExchangeFree not use CLIENT anymore02q,24mar99,fle  made WIN32 code also use auth_destroy mechanism (SPR#26002)02p,07jan99,c_c  Let the target use the hard-coded Registry port number (SPR                 #23681 and #23449).02o,21oct98,c_c  replaced a getenv by a wpwrGetEnv to be sure that                 WIND_REGISTRY is set.02n,18aug98,pcn  Re-use xdr_WTX_MSG_EVTPT_LIST_2.02m,11jun98,pcn  Added an input parameter at wtxEventListGet.02l,26may98,pcn  Changed WTX_MSG_EVTPT_LIST_2 in WTX_MSG_EVTPT_LIST_GET.02k,25mar98,dbt  added WTX_CONTEXT_STATUS_GET.02j,24mar98,fle  Adapted wtxrpcKey to NULL transport handle mangement.02i,24mar98,c_c  Get rid of portmapper.02h,17mar98,jmb  merge HPSIM patch by jmb from 19aug97:		 added socket option call to prevent target server sync task		 from hanging when retrieving symbols from host. (SPR 8708)02g,03mar98,fle  got rid of WTX_REGISTRY_PING service		 + got rid of regex uses02f,02mar98,pcn  WTX 2: Removed WTX_UN_REGIS_FOR_EVENT. Added                 WTX_UNREGISTER_FOR_EVENT, WTX_CACHE_TEXT_UPDATE,                 WTX_MEM_WIDTH_READ, WTX_MEM_WIDTH_WRITE, WTX_COMMAND_SEND,                 WTX_OBJ_MODULE_CHECKSUM, WTX_EVENT_LIST_GET,                 WTX_OBJ_MODULE_LOAD_2, WTX_EVENTPOINT_ADD_2,                 WTX_EVENTPOINT_LIST_2, WTX_OBJ_MODULE_UNLOAD_2.02e,06feb98,c_c  Undo the last remove.02d,05feb98,c_c  Removed an extra include "regex.h".02c,04feb98,lcs  relocate #ifdef to repair damages02b,03feb98,lcs  remove static variable declarations02a,03feb98,lcs  use regex.h for WIN32 & </usr/include/regex.h> for UNIX01z,26jan98,fle  added WTX_REGISTRY_PING routine01y,20nov97,fle  added WTX_MEM_DISASSEMBLE service01x,25feb97,elp  added valid machname in authunix_create() call (SPR# 7959).01w,30sep96,elp  put in share, adapted to be compiled on target side SPR# 6775.01v,28jun96,c_s  tweaks for AIX.01u,09dec95,wmd  used authunix_create() call to pass uid explicity for WIN32,                 to fix SPR# 5609.01t,27oct95,p_m  fixed SPR# 5196 by using the pid to generate the base		 RPC program number (Unix only).01s,26oct95,p_m  added WTX_AGENT_MODE_GET and WTX_DIRECT_CALL.01r,24oct95,wmd  fixed so that processing delays caused by timeout in call                 to hostbyname() is eliminated, spr #5084, 01q,14jun95,s_w	 return WTX_ERR_EXCHANGE_NO_SERVER if client create fails.01p,08jun95,c_s  added WTX_TARGET_ATTACH to rpc function list.01o,01jun95,p_m  changed WTX_FUNC_CALL to use xdr_WTX_MSG_CONTEXT_DESC.01n,30may95,p_m  completed WTX_MEM_SCAN and WTX_MEM_MOVE implementation.01m,30may95,c_s  portablity tweak: use struct in_addr with inet_ntoa().01l,30may95,c_s  added dotted-decimal IP address to key01k,23may95,s_w  don't setup or destroy authentication for WIN3201j,23may95,p_m  made missing name changes.01i,22may95,s_w  update RPC server table for new WTX_MSG_OBJ_KILL in args		 and add WTX_MSG_VIO_CHAN_GET/RELEASE messages.01h,22may95,jcf  name revision.01g,19may95,jcf	 changed over to WIND_REGISTRY.01g,18may95,jcf	 changed over to TORNADO_REGISTRY.01f,14may95,s_w	 add in exchange functions for use by C API (wtx.c). Tidy		 up rouintes to use types from host.h and make all routines		 use status and error codes rather than print error messages.01e,23feb95,p_m  took care of WIN32 platform.01d,14feb95,p_m  changed S_wtx_ to WTX_ERR_ .01c,22jan95,c_s  fixed memory leak.01b,20jan95.jcf  made more portable.01a,24dec94,c_s  written.*//* includes */#ifdef HOST#include "wpwrutil.h"#include "wtxrpc.h"#include "private/wtxexchp.h"#include "wtxmsg.h"#include "wtxxdr.h"#if defined(RS6000_AIX4) || defined (RS6000_AIX3)#undef malloc#endif#include <stdlib.h>#include <stdio.h>#include <string.h>#include <errno.h>#include <sys/param.h>#include <sys/socket.h>#include <sys/ioctl.h>#include <netdb.h>#include <arpa/inet.h>#ifdef SUN4_SOLARIS2#   include <sys/sockio.h>#endif /* SUN4_SOLARIS2 */#ifndef WIN32#   include <net/if.h>#endif /* ! WIN32 */#include <netinet/in.h>#include <unistd.h>#else#include "hostLib.h"#include "arpa/inet.h"#include "socket.h"#include "string.h"#include "stdio.h"#include "stdlib.h"#include "errno.h"#include "wtx.h"#include "wtxrpc.h"#include "private/wtxexchp.h"#include "wtxmsg.h"#include "wtxxdr.h"#if (CPU==SIMHPPA)#include "wdb/wdbLibP.h"#include "sockLib.h"#endif /* (CPU==SIMHPPA) */#endif /* HOST *//* typedefs */typedef struct rpc_service    {    xdrproc_t	xdrIn;    xdrproc_t	xdrOut;    } RPC_SERVICE;#ifndef HOST/* globals */UINT32			syncRegistry;	/* inet registry address */struct opaque_auth 	authCred;	/* address of the authentication info */#endif /* HOST */#ifndef MCALL_MSG_SIZE#define MCALL_MSG_SIZE	24		/* marshalled call message */#endif /* MCALL_MSG_SIZE *//* locals */LOCAL RPC_SERVICE * (*rpcSvcTable)[] = NULL;LOCAL UINT32	rpcSvcTableSize = 0;LOCAL XDR	svrXdrs;			/* server XDR struct  */LOCAL char	svrXdrsMCall[MCALL_MSG_SIZE];	/* marshalled callmsg *//* This is the UDP retry timeout used when creating a UDP service connection */LOCAL struct timeval rpcDefaultUdpTimeout = { 5, 0 };/* forward declarations */LOCAL WTX_ERROR_T rpcStatToError	/* convert RPC status to WTX err code */    (    enum clnt_stat	rpcStat		/* status from call */    );LOCAL STATUS rpcSvcTableInstall (void);	/* install initial service table */LOCAL STATUS rpcSvcAdd			/* add new key in exchange svc table */    (    UINT32		svcNum,		/* service number */    xdrproc_t		xdrIn,		/* XDR input procedure */    xdrproc_t		xdrOut		/* XDR output procedure */    );LOCAL char * wtxRpcKeyFromRpcKeySplitGet	/* get rpc key from structure */    (    WTX_RPC_SPLIT_KEY *	pSplitKey	/* splitted key to create key from    */    );LOCAL int wtxRpcKeyIPListSizeGet	/* get the number of IP adapters      */    (    WTX_RPC_SPLIT_KEY *	pSplitKey	/* splitted RPC key desc              */    );/******************************************************************************** wtxRpcSvcUnregister - perform svc_unregister using RPC key string** This routine will unregister the specified RPC service with svc_unregister.* This routine will not destroy the service.** RETURNS: WTX_OK, or WTX_ERROR if invalid key.*/STATUS wtxRpcSvcUnregister    (    const char *	rpcKey	/* service key for service to unregister */    )    {    WTX_RPC_SPLIT_KEY	splitKey;    if (wtxRpcKeySplit (rpcKey, &splitKey) != WTX_OK)	/* split the key */	return (WTX_ERROR);    svc_unregister (splitKey.progNum, splitKey.version);    wtxRpcKeySplitFree (&splitKey);    return (WTX_OK);    }/******************************************************************************** wtxRpcKey - construct an RPC key string given RPC parameters.** An RPC key string is built from the given progNum, version, and protocol* code.  The format of the string is* *     rpc/<hostname>/<ip-addr>/<progNum>/<version>|<tcp|udp>/<port#>** The hostname is found from the OS.** RETURNS:* The constructed RPC key string, or NULL if the input data does not represent* a valid RPC server address or memory for the string could not be allocated.* The storage for the string should be freed with free() when it is no longer* needed.*/char *wtxRpcKey    (    UINT32	progNum,	/* rpc prog number, or NULL TBA */    UINT32	version,	/* rpc version number */    UINT32	protocol,	/* IPPROTO_TCP or IPPROTO_UDP */    void	(* dispatch) 	/* rpc dispatch routine */		(struct svc_req *, SVCXPRT *),    BOOL	register2pmap,	/* Do we register to the local portmapper ? */    SVCXPRT **	ppNewXprt	/* where to return transport */    )    {#if (!defined SUN4_SOLARIS2)    struct in_addr	ina;			/* inet address               */#endif /* ! SUN4_SOLARIS2 */    SVCXPRT *	newXprt = NULL;			/* transport we make          */    UINT32 	rpcProgNum;			/* hunted rpc program num     */    UINT32	svc_protocol;			/* protocol sent to the       */						/* svc_register ()            */    char * 	ipAddrStr = NULL;		/* string IP addr (a.b.c.d)   */    char *	newKey = NULL;			/* final key (malloc'd)       */    char	hostName [MAXHOSTNAMELEN];	/* our host name              */    char	buf [256];			/* accumulates key string     */    int		newKeyLen = 0;			/* new key string length      */#ifdef HOST    BOOL		firstAddress = TRUE;	/* first inet address ?       */    int			inetLen = 0;		/* iet address string length  */    #ifdef WIN32    struct hostent *	pHostEnt;		/* contains our IP addr       */    char **		addrList = NULL;	/* address list               */    char *		inetAddr = NULL;	/* address from inet_ntoa()   */    #else    struct sockaddr_in	addr;			/* socket address definition  */    struct ifconf	ifc;			/* if config result           */    struct ifreq	ifReq;			/* current if config request  */    struct ifreq *	ifr = NULL;		/* if config request result   */    char		ifBuf [BUFSIZ];		/* if config container        */    char		ipAddr [16];		/* current IP string          */    int			addrLen = 0;		/* current address length     */    int			len = 0;		/* adress counter for loop    */    int			s = 0;			/* connection socket          */    #endif /* WIN32 */#endif /* HOST */    /* sanity check progNum >= 0, version > 0, and IPPROTO_TCP or IPPROTO_UDP */    if (((protocol != IPPROTO_TCP) && (protocol != IPPROTO_UDP)) ||	((progNum == 0) && (dispatch == NULL)))	goto error1;    if (progNum == 0)					/* hunt for prog num */	{	if (protocol == IPPROTO_TCP)	    newXprt = svctcp_create (RPC_ANYSOCK, 0, 0);	else	    newXprt = svcudp_create (RPC_ANYSOCK);	if (! newXprt)					/* service kaput! */	    goto error1;	/*	 * In order to limit the number of times a Target Server can	 * get the RPC program number of a just killed (with kill -9)	 * Target Server we introduce a little bit of random here (SPR# 5196).	 */#if defined(WIN32) || !defined(HOST)	rpcProgNum = WTX_SVC_BASE;#else /* WIN32 */	rpcProgNum = WTX_SVC_BASE + ((int) getpid () & 0xff);#endif /* WIN32 */	/*	 * If we don't want to register ourself to the local portmapper, set the	 * protocol to 0 before calling svc_register ().	 */	svc_protocol = register2pmap?protocol:0;	while (!svc_register (newXprt, ++rpcProgNum, version, dispatch,			      svc_protocol))	    if (rpcProgNum >= WTX_SVC_BASE + WTX_MAX_SERVICE_CNT)		goto error1;	if (ppNewXprt)					/* return transport? */	    *ppNewXprt = newXprt;	progNum = rpcProgNum;				/* store prog num */	}    /* Key format: "rpc/host/ip/port/prog/version/{tcp,udp}" */    gethostname (hostName, sizeof (hostName));		/* where are we? */#ifdef HOST    #ifdef WIN32    if ((pHostEnt = gethostbyname (hostName)))		/* know our IP addr? */	{	/* get the size of the cumulative adapters string */	for (addrList = pHostEnt->h_addr_list ; *addrList != NULL ; addrList ++)	    {	    memcpy (&ina.s_addr, *addrList, sizeof (ina.s_addr));	    if ( (inetAddr = inet_ntoa (ina)) != NULL)		inetLen += strlen (inetAddr) + 1;	    }	/* allocate memory for the IP addresses string */	if ( (ipAddrStr = (char *) calloc (inetLen, sizeof (char))) == NULL)	    goto error1;	/* now concat all the IP addresses in one string separeted with ',' */	firstAddress = TRUE;	for (addrList = pHostEnt->h_addr_list ; *addrList != NULL ; addrList ++)	    {	    memcpy (&ina.s_addr, *addrList, sizeof (ina.s_addr));	    if (firstAddress)		{		strcpy (ipAddrStr, inet_ntoa (ina));		firstAddress = FALSE;		}	    else	        {		sprintf (ipAddrStr, "%s,%s", ipAddrStr, inet_ntoa (ina));		}	    }	}    else	if ( (ipAddrStr = strdup ("")) == NULL)	    goto error1;    #else /* WIN32 */    /* init some variables */    memset (&addr, 0, sizeof (struct sockaddr_in));    memset (ifBuf, 0, sizeof (ifBuf));    memset (&ifc, 0, sizeof (struct ifconf));    memset (&ifReq, 0, sizeof (struct ifreq));    /*     * On UNIX hosts, the gethostbyname() routine may not return all the     * available IP addresses for the local host. We use a part of the     * RPC 4.0 get_myaddress.c code to retrieve the list of all IPs registered     * for the local host     */    if ( (s = socket (AF_INET, SOCK_DGRAM, 0)) < 0)	goto error1;    ifc.ifc_len = sizeof (ifBuf);    ifc.ifc_buf = ifBuf;    /* get the if config */    if (ioctl (s, SIOCGIFCONF, (char *)&ifc) < 0)	goto error2;    ifr = ifc.ifc_req;    /* get the list of all the IP addresses */

⌨️ 快捷键说明

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