From 35b0e4aaba299bc0e2dbd2ab29e7e203a79b9eab Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Thu, 16 Feb 1995 22:34:06 +0000 Subject: [PATCH] NT changes and (long) cast problem fixed --- src/ca/BUILD_VMS.COM | 6 +- src/ca/access.c | 8 +- src/ca/conn.c | 2 +- src/ca/convert.c | 12 ++- src/ca/iocinf.c | 3 +- src/ca/netdb_depen.c | 13 +-- src/ca/os_depen.h | 7 +- src/ca/windows_depen.c | 230 ++++++++++++++++++++++++++++++++++++++--- 8 files changed, 243 insertions(+), 38 deletions(-) diff --git a/src/ca/BUILD_VMS.COM b/src/ca/BUILD_VMS.COM index f4ef27ca0..c82d96f14 100644 --- a/src/ca/BUILD_VMS.COM +++ b/src/ca/BUILD_VMS.COM @@ -52,10 +52,9 @@ IF_DEPEN, - VMS_DEPEN, - ELLLIB, - BUCKETLIB, - -NEXTFIELDSUBR, - ENVSUBR, - TSSUBR, - -GENSUBR, - +NEXTFIELDSUBR, - CATIME, - ACCTST $ endif @@ -76,10 +75,9 @@ IF_DEPEN, - VMS_DEPEN, - BSD_DEPEN, - BUCKETLIB, - -NEXTFIELDSUBR, - TSSUBR, - ENVSUBR, - -GENSUBR, - +NEXTFIELDSUBR, - ELLLIB $! Link the test programs $ call link acctst diff --git a/src/ca/access.c b/src/ca/access.c index 7233957fc..c073e1f68 100644 --- a/src/ca/access.c +++ b/src/ca/access.c @@ -559,7 +559,7 @@ int ca_os_independent_init (void) sec = (unsigned) CA_RECAST_DELAY; ca_static->ca_conn_retry_delay.tv_sec = sec; ca_static->ca_conn_retry_delay.tv_usec = - (long) (CA_RECAST_DELAY-sec)*USEC_PER_SEC; + (long) ((CA_RECAST_DELAY-sec)*USEC_PER_SEC); ellInit(&ca_static->ca_iiuList); ellInit(&ca_static->ca_ioeventlist); @@ -1109,7 +1109,7 @@ int APIENTRY ca_search_and_connect sec = (int) CA_RECAST_DELAY; ca_static->ca_conn_retry_delay.tv_sec = sec; ca_static->ca_conn_retry_delay.tv_usec = - (long) (CA_RECAST_DELAY-sec)*USEC_PER_SEC; + (long) ((CA_RECAST_DELAY-sec)*USEC_PER_SEC); UNLOCK; @@ -2722,11 +2722,11 @@ int APIENTRY ca_pend(ca_real timeout, int early) /* * Allow for CA background labor */ - remaining = (long) min(SELECT_POLL, remaining); + remaining = min(SELECT_POLL, remaining); } tmo.tv_sec = (long) remaining; - tmo.tv_usec = (long) (remaining-tmo.tv_sec)*USEC_PER_SEC; + tmo.tv_usec = (long) ((remaining-tmo.tv_sec)*USEC_PER_SEC); cac_block_for_io_completion(&tmo); } } diff --git a/src/ca/conn.c b/src/ca/conn.c index d4b01e4c6..507ed0a0a 100644 --- a/src/ca/conn.c +++ b/src/ca/conn.c @@ -469,7 +469,7 @@ void mark_server_available(struct in_addr *pnet_addr) delay += CA_RECAST_DELAY; idelay = (long) delay; ca_delay.tv_sec = idelay; - ca_delay.tv_usec = (long) (delay-idelay) * USEC_PER_SEC; + ca_delay.tv_usec = (long) ((delay-idelay) * USEC_PER_SEC); next = cac_time_sum(¤tTime, &ca_delay); diff = cac_time_diff( diff --git a/src/ca/convert.c b/src/ca/convert.c index 5a5789264..5452051a6 100644 --- a/src/ca/convert.c +++ b/src/ca/convert.c @@ -1592,7 +1592,7 @@ void ntohf(float *pNet, float *pHost) #endif /*CA_FLOAT_MIT*/ -#if !defined(CA_FLOAT_MIT) +#if defined(CA_FLOAT_IEEE) && 0 /* * htond () @@ -1600,6 +1600,7 @@ void ntohf(float *pNet, float *pHost) */ void htond (double *IEEEhost, double *IEEEnet) { +#ifdef CA_LITTLE_ENDIAN ca_uint32_t *pHost = (ca_uint32_t *) IEEEhost; ca_uint32_t *pNet = (ca_uint32_t *) IEEEnet; ca_uint32_t tmp; @@ -1612,6 +1613,9 @@ void htond (double *IEEEhost, double *IEEEnet) tmp = pHost[0]; pNet[0] = htonl (pHost[1]); pNet[1] = htonl (tmp); +#else + *IEEEnet = *IEEEhost; +#endif } /* @@ -1620,6 +1624,7 @@ void htond (double *IEEEhost, double *IEEEnet) */ void ntohd (double *IEEEnet, double *IEEEhost) { +#ifdef CA_LITTLE_ENDIAN ca_uint32_t *pHost = (ca_uint32_t *) IEEEhost; ca_uint32_t *pNet = (ca_uint32_t *) IEEEnet; ca_uint32_t tmp; @@ -1632,6 +1637,9 @@ void ntohd (double *IEEEnet, double *IEEEhost) tmp = pNet[0]; pHost[0] = ntohl (pNet[1]); pHost[1] = htonl (tmp); +#else + *IEEEhost = *IEEEnet; +#endif } /* @@ -1658,7 +1666,7 @@ void htonf (float *IEEEhost, float *IEEEnet) *pNet = htonl (*pHost); } -#endif /* not CA_MIT_FLOAT*/ +#endif /* IEEE float and little endian */ diff --git a/src/ca/iocinf.c b/src/ca/iocinf.c index febf812b0..3ac223bce 100644 --- a/src/ca/iocinf.c +++ b/src/ca/iocinf.c @@ -219,7 +219,7 @@ int net_proto IPPROTO_TCP, TCP_NODELAY, (char *)&true, - sizeof true); + sizeof(true)); if(status < 0){ free(piiu); status = socket_close(sock); @@ -443,7 +443,6 @@ int net_proto piiu->host_name_str, "<>", sizeof(piiu->host_name_str)-1); - break; default: diff --git a/src/ca/netdb_depen.c b/src/ca/netdb_depen.c index 46fd3ee7e..691ff54d0 100644 --- a/src/ca/netdb_depen.c +++ b/src/ca/netdb_depen.c @@ -40,13 +40,14 @@ static char *sccsId = "@(#) $Id$"; #include #ifdef _WINDOWS -#include +# include +#else +# include +# include +# include +# include +# include #endif -#include -#include -#include -#include -#include /* diff --git a/src/ca/os_depen.h b/src/ca/os_depen.h index 800a9d667..8cd488b3d 100644 --- a/src/ca/os_depen.h +++ b/src/ca/os_depen.h @@ -134,11 +134,8 @@ static char *os_depenhSccsId = "$Id$"; #endif /* - * Big endin architecture is assumed. Otherwise set "CA_LITTLE_ENDIAN". - * - * IEEE floating point architecture assumed. Set "CA_FLOAT_MIT" if - * appropriate. No other floating point formats currently - * supported. + * Here are the definitions for architecture dependent byte ordering + * and floating point format */ #if defined(VAX) # define CA_FLOAT_MIT diff --git a/src/ca/windows_depen.c b/src/ca/windows_depen.c index 9d07ff333..5a74ce5c5 100644 --- a/src/ca/windows_depen.c +++ b/src/ca/windows_depen.c @@ -2,6 +2,7 @@ * $Id$ * Author: Jeffrey O. Hill, Chris Timossi * hill@luke.lanl.gov + * CATimossi@lbl.gov * (505) 665 1831 * Date: 9-93 * @@ -31,12 +32,24 @@ * */ +/* + * Windows includes + */ +#include + +#define ENV_PRIVATE_DATA + #include "iocinf.h" #ifndef _WINDOWS #error This source is specific to DOS/WINDOS #endif +static int get_subnet_mask ( char SubNetMaskStr[256]); +static int RegTcpParams (char IpAddr[256], char SubNetMask[256]); +static int RegKeyData (CHAR *RegPath, HANDLE hKeyRoot, LPSTR lpzValueName, + LPDWORD lpdwType, LPBYTE lpbData, LPDWORD lpcbData ); + /* * cac_gettimeval @@ -135,7 +148,8 @@ void cac_block_for_sg_completion(CASG *pcasg, struct timeval *pTV) */ int cac_os_depen_init(struct ca_static *pcas) { - int status; + int status; + WSADATA WsaData; ca_static = pcas; @@ -146,16 +160,17 @@ int cac_os_depen_init(struct ca_static *pcas) * allow error to be returned to sendto() * instead of handling disconnect at interrupt */ - signal(SIGPIPE,SIG_IGN); + + /* signal(SIGPIPE,SIG_IGN); */ # ifdef _WINSOCKAPI_ - status = WSAStartup(MAKEWORD(1,1), &WsaData)); + status = WSAStartup(MAKEWORD(1,1), &WsaData); assert (status==0); # endif status = ca_os_independent_init (); - return status; + return status; } @@ -180,12 +195,12 @@ void cac_os_depen_exit (struct ca_static *pcas) */ char *localUserName() { - int length; - char *pName; - char *pTmp; + int length; + char *pName; + char *pTmp; - pName = "Joe PC"; - length = strlen(pName)+1; + pName = getenv("USERNAME"); + length = strlen(pName)+1; pTmp = malloc(length); if(!pTmp){ @@ -211,8 +226,13 @@ void ca_spawn_repeater() * running in the repeater process * if here */ - pImageName = "caRepeater"; - status = system(pImageName); + pImageName = "caRepeater.exe"; + //status = system(pImageName); + //Need to check if repeater is already loaded + //For now, start Repeater from a command line, not here + status = 0; + //status = _spawnlp(_P_DETACH,pImageName,""); + if(status<0){ ca_printf("!!WARNING!!\n"); ca_printf("Unable to locate the executable \"%s\".\n", @@ -235,9 +255,192 @@ void caSetDefaultPrintfHandler () /* - * DllMain () + * + * Network interface routines + * */ -BOOL APIENTRY DllMain (HANDLE hModule, DWORD dwReason, LPVOID lpReserved) + +/* + * local_addr() + * + * return 127.0.0.1 + * (the loop back address) + */ +int local_addr (SOCKET s, struct sockaddr_in *plcladdr) +{ + ca_uint32_t loopBackAddress = 0x7f000001; + + plcladdr->sin_family = AF_INET; + plcladdr->sin_port = 0; + plcladdr->sin_addr.s_addr = ntohl (loopBackAddress); + return OK; +} + + +/* + * caDiscoverInterfaces() + * + * This routine is provided with the address of an ELLLIST a socket + * and a destination port number. When the routine returns there + * will be one additional inet address (a caAddrNode) in the list + * for each inet interface found that is up and isnt a loop back + * interface. If the interface supports broadcast then I add its + * broadcast address to the list. If the interface is a point to + * point link then I add the destination address of the point to + * point link to the list. In either case I set the port number + * in the address node to the port supplied in the argument + * list. + * + * LOCK should be applied here for (pList) + * (this is also called from the server) + */ +void caDiscoverInterfaces(ELLLIST *pList, SOCKET socket, int port) +{ + struct sockaddr_in localAddr; + struct sockaddr_in InetAddr; + struct in_addr bcast_addr; + caAddrNode *pNode; + int status; + + pNode = (caAddrNode *) calloc(1,sizeof(*pNode)); + if(!pNode){ + return; + } + broadcast_addr(&bcast_addr); + pNode->destAddr.inetAddr.sin_addr.s_addr = bcast_addr.s_addr; //broadcast addr + pNode->destAddr.inetAddr.sin_port = htons(port); + pNode->destAddr.inetAddr.sin_family = AF_INET; + //pNode->srcAddr.inetAddr = 0 ;//localAddr; + + /* + * LOCK applied externally + */ + ellAdd(pList, &pNode->node); +} + +int +broadcast_addr( struct in_addr *pcastaddr ) +{ + char netmask[256], lhostname[80]; + static struct in_addr castaddr; + int status; + static char init = FALSE; + struct hostent *phostent; + unsigned long laddr; + + if (init) { + *pcastaddr = castaddr; + return OK; + } + gethostname(lhostname,sizeof(lhostname)); + phostent = gethostbyname(lhostname); + if (!phostent) { + return MYERRNO; + } + + if (status = get_subnet_mask(netmask)) + return ERROR; + + laddr = *( (unsigned long *) phostent->h_addr_list[0]); + castaddr.s_addr = (laddr & inet_addr(netmask)) | ~inet_addr(netmask); + + if (!init){ + init = TRUE; + *pcastaddr = castaddr; + } + return OK; +} + +static int get_subnet_mask ( char SubNetMaskStr[256]) +{ + char localadr[256]; + + return RegTcpParams (localadr, SubNetMaskStr); +} + +static int RegTcpParams (char IpAddrStr[256], char SubNetMaskStr[256]) +{ +#define MAX_VALUE_NAME 128 + static CHAR ValueName[MAX_VALUE_NAME]; + static CHAR RegPath[256]; + DWORD cbDataLen; + CHAR cbData[256]; + DWORD dwType; + int status; + static char IpAddr[256], SubNetMask[256]; + + cbDataLen = sizeof(cbData); + strcpy(RegPath,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\1"); + status = RegKeyData (RegPath, HKEY_LOCAL_MACHINE, "ServiceName", &dwType, cbData, &cbDataLen); + if (status) { + strcpy(RegPath,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\01"); + status = RegKeyData (RegPath, HKEY_LOCAL_MACHINE, "ServiceName", &dwType, cbData, &cbDataLen); + if (status) + return status; + } + + strcpy(RegPath,"SYSTEM\\CurrentControlSet\\Services\\"); + strcat(RegPath,cbData); + strcat(RegPath,"\\Parameters\\Tcpip"); + + cbDataLen = sizeof(IpAddr); + status = RegKeyData (RegPath, HKEY_LOCAL_MACHINE, "IPAddress", &dwType, IpAddr, &cbDataLen); + if (status) + return status; + strcpy(IpAddrStr,IpAddr); + + cbDataLen = sizeof(SubNetMask); + status = RegKeyData (RegPath, HKEY_LOCAL_MACHINE, "SubnetMask", &dwType, SubNetMask, &cbDataLen); + if (status) + return status; + + strcpy(SubNetMaskStr,SubNetMask); + + return 0; +} + + +static int RegKeyData (CHAR *RegPath, HANDLE hKeyRoot, LPSTR lpzValueName, + LPDWORD lpdwType, LPBYTE lpbData, LPDWORD lpcbData ) + { + HKEY hKey; + DWORD retCode; + + DWORD dwcClassLen = MAX_PATH; + + // OPEN THE KEY. + + retCode = RegOpenKeyEx (hKeyRoot, // Key handle at root level. + RegPath, // Path name of child key. + 0, // Reserved. + KEY_QUERY_VALUE, // Requesting read access. + &hKey); // Address of key to be returned. + + if (retCode) + { + //wsprintf (Buf, "Error: RegOpenKeyEx = %d", retCode); + return -1; + } + + + retCode = RegQueryValueEx (hKey, // Key handle returned from RegOpenKeyEx. + lpzValueName, // Name of value. + NULL, // Reserved, dword = NULL. + lpdwType, // Type of data. + lpbData, // Data buffer. + lpcbData); // Size of data buffer. + + if (retCode) + { + //wsprintf (Buf, "Error: RegQIK = %d, %d", retCode, __LINE__); + return -2; + } + + return 0; + + } + +BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) { int status; WSADATA WsaData; @@ -276,4 +479,3 @@ BOOL APIENTRY DllMain (HANDLE hModule, DWORD dwReason, LPVOID lpReserved) return TRUE; } -