📄 wtxrpc.c
字号:
/* wtxrpc.c - tornado rpc transport library *//* Copyright 1984-1996 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02q,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 <netdb.h>#include <arpa/inet.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 *//* locals */LOCAL RPC_SERVICE * (*rpcSvcTable)[] = NULL;LOCAL UINT32 rpcSvcTableSize = 0;/* 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 */ );/******************************************************************************** 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); 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 */ ) { char * newKey; /* final key (malloc'd) */ char ipAddrStr [24]; /* string IP addr (a.b.c.d) */ UINT32 rpcProgNum; /* hunted rpc program num */ SVCXPRT * newXprt = NULL; /* transport we make */ char buf [256]; /* accumulates key string */ char hostName [MAXHOSTNAMELEN]; /* our host name */ UINT32 svc_protocol; /* protocol sent to the svc_register () */#ifdef HOST struct hostent * pHostEnt; /* contains our IP addr */#else struct in_addr ina;#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))) return (NULL); 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! */ return (NULL); /* * 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) return (NULL); /* let's give up */ 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 if ((pHostEnt = gethostbyname (hostName))) /* know our IP addr? */ { struct in_addr ina; ina.s_addr = * ((u_long *) pHostEnt->h_addr_list [0]); strcpy (ipAddrStr, inet_ntoa (ina)); } else strcpy (ipAddrStr, "");#else ina.s_addr = hostGetByName (hostName); strcpy (ipAddrStr, inet_ntoa (ina));#endif /* HOST */ /* If we cannot get the port used, don't write it. */ if(ppNewXprt == NULL) { sprintf (buf, "rpc/%s/%s/%d/%d/%s", hostName, ipAddrStr, progNum, version, (protocol == IPPROTO_TCP) ? "tcp" : "udp"); } else { sprintf (buf, "rpc/%s/%s/%d/%d/%s/%d", hostName, ipAddrStr, progNum, version, (protocol == IPPROTO_TCP) ? "tcp" : "udp", (*ppNewXprt)->xp_port); } if ((newKey = malloc (strlen (buf) + 1)) == NULL) /* allocate key */ return (NULL); strcpy (newKey, buf); /* copy string */ return (newKey); /* return key */ }/******************************************************************************** wtxRpcKeySplit - split an RPC key string into its component parts** The given RPC key string is decoded and the various fields are placed* into the WTX_RPC_SPLIT_KEY structure provided (by reference).** RETURNS:* WTX_OK, if the key was split successfully and pSplitKey is filled, or* WTX_ERROR if the key could not be decoded.*/STATUS wtxRpcKeySplit ( const char * rpcKey, WTX_RPC_SPLIT_KEY * pSplitKey ) { char progNum[10]; /* program number in string format */ char version[10]; /* transport version in string format */ char protocol[10]; /* tcp or udp */ int nMatchedPatterns; /* number of matched patterns */ char portNum[10] = " 0"; /* port number in string format */ char keyPat[] = "rpc/%[^/]/%[.0-9a-fA-F]/%[0-9a-fA-F]/%[0-9a-fA-F]/%[tcpudp]/%[0-9a-fA-F]"; int nPatternsToMatch = 6; /* type/host/ipaddr/prognum/vers/protocol/portnum */ memset (pSplitKey, 0, sizeof (*pSplitKey));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -