Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 99619 Details for
Bug 165409
IPv6 Support
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Org.eclipse.tptp.platform.agentcontroller - IPv6 patch
org.eclipse.tptp.platform.agentcontroller-ipv6.patch (text/plain), 100.68 KB, created by
Jonathan West
on 2008-05-10 16:08:08 EDT
(
hide
)
Description:
Org.eclipse.tptp.platform.agentcontroller - IPv6 patch
Filename:
MIME Type:
Creator:
Jonathan West
Created:
2008-05-10 16:08:08 EDT
Size:
100.68 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.tptp.platform.agentcontroller >Index: src-native-new/src/transport/TPTPClientCompTL/Connect2AC.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/Connect2AC.c,v >retrieving revision 1.75 >diff -u -r1.75 Connect2AC.c >--- src-native-new/src/transport/TPTPClientCompTL/Connect2AC.c 29 Apr 2008 19:19:25 -0000 1.75 >+++ src-native-new/src/transport/TPTPClientCompTL/Connect2AC.c 10 May 2008 19:32:58 -0000 >@@ -23,6 +23,10 @@ > #include "Connect2AC.h" > #include "RACClientSupport.h" > >+#ifdef _WIN32 >+ #include "ws2tcpip.h" >+#endif >+ > #define CMD_BUFFER_LENGTH 8192 /* TODO: Use a universal definition */ > #define MAX_AGENT_NAME 1024 /* TODO: Use a universal definition */ > >@@ -957,8 +961,9 @@ > tptp_int32 flags = TPTP_DATA_PATH_TWOWAY; > tptp_int32 dataConnectionID; > SOCKET dataSock; >- tptp_int32 clientIP; >- tptp_int32 clientIPLen; >+ >+ struct sockaddr_storage * addr; >+ > client_data_connection_block_t *dcb; > tptp_int32 rc; > TID threadId; >@@ -971,9 +976,14 @@ > status = getAgent(ccb->stateData, ccb, "ProcessController", &processControllerDestID); > } > >- getClientIP(ccb, (unsigned char*)&clientIP, &clientIPLen); >- dataSock = openClientDataSocket(clientIP, remoteConsolePort); >+ getClientIPAddr(ccb, &addr); >+ >+ dataSock = openClientDataSocketAddr(addr, remoteConsolePort); >+ >+ tptp_free(addr); >+ > if (dataSock != -1) { >+ > dcb = (client_data_connection_block_t*)tptp_malloc( sizeof(client_data_connection_block_t) ); > if ( dcb == NULL ) { > return FALSE; >@@ -1470,12 +1480,12 @@ > { > char* localIPStr; > >- if (getSocketIPString( ccb->sock, &localIPStr) < 0) { >+ if (getSocketIPStringIPv4M( ccb->sock, &localIPStr) < 0) { > TPTP_LOG_ERROR_MSG(stateData, "Unable to get local IP address"); > return -1; > } > >- convertIPAddressStringToArray( localIPStr, localAddr); >+ convertIPAddressStringToArrayIPv4M( localIPStr, localAddr); > ra_createRASTRING3( &command->info.controller_request_monitor_port.node, localAddr, 4); > > /* We're done with this now, so let's free it */ >@@ -1487,7 +1497,7 @@ > command->info.controller_request_monitor_port.port = strtoul(peerPort, 0, 10); > > /* Convert the peer address */ >- convertIPAddressStringToArray( peerHost, peerAddr ); >+ convertIPAddressStringToArrayIPv4M( peerHost, peerAddr ); > ra_createRASTRING3( &command->info.controller_request_monitor_port.peerNode, peerAddr, 4 ); > > /* Fill in the source agent's information */ >@@ -1559,12 +1569,12 @@ > { > char* localIPStr; > >- if (getSocketIPString( ccb->sock, &localIPStr) < 0) { >+ if (getSocketIPStringIPv4M( ccb->sock, &localIPStr) < 0) { > TPTP_LOG_ERROR_MSG(stateData, "Unable to get local IP address"); > return -1; > } > >- convertIPAddressStringToArray( localIPStr, localAddr); >+ convertIPAddressStringToArrayIPv4M( localIPStr, localAddr); > ra_createRASTRING3( &command->info.controller_request_monitor_port.node, localAddr, 4); > > /* We're done with this now, so let's free it */ >@@ -1576,7 +1586,7 @@ > command->info.controller_request_monitor_port.port = strtoul(peerPort, 0, 10); > > /* Convert the peer address */ >- convertIPAddressStringToArray( peerHost, command->info.controller_request_monitor_port.peerNode.data ); >+ convertIPAddressStringToArrayIPv4M( peerHost, command->info.controller_request_monitor_port.peerNode.data ); > command->info.controller_request_monitor_port.peerNode.length = 4; > > /* Fill in the peer agent's information */ >Index: src-native-new/src/transport/TPTPClientCompTL/RACClientSupport.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/RACClientSupport.c,v >retrieving revision 1.21 >diff -u -r1.21 RACClientSupport.c >--- src-native-new/src/transport/TPTPClientCompTL/RACClientSupport.c 14 Nov 2006 22:40:24 -0000 1.21 >+++ src-native-new/src/transport/TPTPClientCompTL/RACClientSupport.c 10 May 2008 19:32:59 -0000 >@@ -34,6 +34,13 @@ > #include "secureServer.h" > #include "Connect2AC.h" > >+// Added for IPv6 support >+#ifdef _WIN32 >+ #include <winsock2.h> >+ #include <ws2tcpip.h> >+#endif >+ >+ > #ifndef _WIN32 > #include <signal.h> // Used by ra_killProcess > #endif >@@ -740,12 +747,73 @@ > } > } > >+ >+int getClientIPAddr(client_connection_block_t* ccb, struct sockaddr_storage ** addr) { >+ >+ if (ccb->connectionType == CCTL_NATIVE_SOCKET) { >+ *addr = getPeerAddrOfSocket(ccb->sock); >+ >+ } >+ else if(ccb->connectionType == CCTL_JAVA_SOCKET) { >+ JNIEnv *env; >+ >+ if(!ATTACH_THREAD(env)) { >+ jclass clazz = fndclsid(env, INTERFACE_CLIENT_HANDLER); >+ if(clazz) { >+ jmethodID method = getmthdid(env, clazz, "getRemoteAddress", "()[B"); >+ if(method) { >+ jbyteArray result=(jbyteArray)ENV(env)->CallObjectMethod(ENVPARM(env) ccb->javaObj, method); >+ if(result) { >+ jbyte *elements; >+ jsize size = ENV(env)->GetArrayLength(ENVPARM(env) result); >+ elements = ENV(env)->GetByteArrayElements(ENVPARM(env) result, JNI_FALSE); >+#ifdef _LP64 >+ assert(size<=INT_MAX); >+#endif >+ getSockAddrFromByteFormat(elements, size == 4 ? PF_INET : PF_INET6, addr ); >+ >+ } >+ } >+ } >+ DETACH_THREAD(); >+ } >+ } >+ >+ return 0; >+} >+ > int getClientIP(client_connection_block_t* ccb, unsigned char *buffer, int *length) { > //if(client->connection->type==RA_SOCKET_CONNECTION) { kevin we need to store this type info. > if (ccb->connectionType == CCTL_NATIVE_SOCKET) { >- /* Retrieve the IP address of the remote client */ >- getPeerName(ccb->sock, buffer); >- *length=4; >+ >+ struct sockaddr_storage * addr; >+ unsigned char *value; >+ int family = 0; >+ addr = getPeerAddrOfSocket(ccb->sock); >+ >+ if(addr == NULL) { >+ *length = 0; >+ return -1; >+ } >+ >+ getByteFormatFromSockAddr(addr, (void **)&value, &family); >+ >+ if(addr->ss_family == PF_INET) { >+ memcpy(buffer, value, sizeof(struct in_addr)); >+ *length = sizeof(struct in_addr); >+ tptp_free(value); >+ } else if(addr->ss_family == PF_INET6) { >+ memcpy(buffer, value, sizeof(struct in6_addr)); >+ *length = sizeof(struct in6_addr); >+ tptp_free(value); >+ } else { >+ tptp_free(addr); >+ *length = 0; >+ return -1; >+ } >+ >+ tptp_free(addr); >+ > } > else if(ccb->connectionType == CCTL_JAVA_SOCKET) { > JNIEnv *env; >@@ -774,14 +842,44 @@ > > return 0; > } >+#ifndef _WIN32 >+ #define INVALID_SOCKET -1 >+#endif >+ >+SOCKET openClientDataSocketAddr(struct sockaddr_storage *addr, int port) { >+ char hostname[260]; >+ tptp_int32 rc = -1; >+ SOCKET outSocket; >+ >+ hostname[0] = 0; >+ >+ // Resolve the host name >+ rc = getnameinfo((struct sockaddr *)addr, sizeof(struct sockaddr_storage), hostname, 260, NULL, 0, 0); >+ if(rc == 0) { >+ >+ // Attempt to connect to the server by resolving the various addreses of the hostname >+ connectToTCPServer(hostname, port, &outSocket); >+ >+ if(outSocket != INVALID_SOCKET) { >+ return outSocket; >+ } >+ } >+ >+ // If we weren't able to resolve the host name, or couldn't succeed, try the IP address itself >+ connectToTCPServerAddr(addr, port, &outSocket); >+ >+ return outSocket; >+ >+} > >+/** IPV4-ONLY */ > SOCKET openClientDataSocket(tptp_int32 ip, tptp_int32 port) > { > > SOCKET sock = -1 ; > tptp_int32 rc = -1; > >- rc = connectToTCPServer(ip, (unsigned short) port, &sock); >+ rc = connectToTCPServerIPv4M(ip, (unsigned short) port, &sock); > > if (rc == -1) { > return -1; >Index: src-native-new/src/transport/TPTPClientCompTL/RACClientSupport.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/RACClientSupport.h,v >retrieving revision 1.8 >diff -u -r1.8 RACClientSupport.h >--- src-native-new/src/transport/TPTPClientCompTL/RACClientSupport.h 10 Feb 2006 18:37:23 -0000 1.8 >+++ src-native-new/src/transport/TPTPClientCompTL/RACClientSupport.h 10 May 2008 19:32:59 -0000 >@@ -147,6 +147,11 @@ > /* computes a sockets ip address using getpeername */ > int getClientIP(client_connection_block_t* ccb, unsigned char *buffer, int *length); > >+ >+int getClientIPAddr(client_connection_block_t* ccb, struct sockaddr_storage ** addr); >+ > SOCKET openClientDataSocket(tptp_int32 ip, tptp_int32 port); > >+SOCKET openClientDataSocketAddr(struct sockaddr_storage *addr, int port); >+ > #endif /* __RACPROCESSLIST_H__ */ >Index: src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.c,v >retrieving revision 1.6 >diff -u -r1.6 nativeFileServer.c >--- src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.c 29 Apr 2008 19:19:25 -0000 1.6 >+++ src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.c 10 May 2008 19:33:00 -0000 >@@ -252,19 +252,20 @@ > int d, rc; > SOCKET testSocket; > unsigned long ipAddr; >- >+ struct addrinfo *AI = NULL; >+ > host = readStringIntoBuffer(con); > if (host == NULL) return -1; > > readInt (con->socket, &port); >- >+ >+ testSocket = connectToHostWithHostname(host, port, &AI); >+ > d = 0; >- rc = convertIPAddressStringToUlong(host, &ipAddr); // reverse call >- if (rc == 0) { >- if (!connectToTCPServer(ipAddr, (unsigned short) port, &testSocket)) { >- d = 1; >- closeSocket(testSocket); >- } >+ >+ if(testSocket != INVALID_SOCKET) { >+ d = 1; >+ closeSocket(testSocket); > } > > writeByte(con->socket, d); // "server is reachable" responce >@@ -502,33 +503,36 @@ > > static SOCKET serverSocket; > >+static SOCKET * serverSockets; >+static int numServerSockets; >+static socket_accept_t socketAccept; >+ > THREAD_USER_FUNC_RET_TYPE startNativeFileServer(LPVOID args){ > int rc, port; >- struct sockaddr_in fsSockAddr; > SOCKET clientSock; > fs_connection_block_t* con; > tl_state_data_t* stateData; > TID threadId; > HANDLE threadHandle; >+ >+ serverSockets = (SOCKET *) tptp_malloc(sizeof(SOCKET) * FD_SETSIZE); >+ >+ initSocketAccept(&socketAccept); > > stateData = (tl_state_data_t*) args; > port = ((cctl_state_data_t*)stateData->implData)->filePort; > if (port <= 0) port = RA_FILE_PORT_NUM_SERVER; >- >- serverSocket = getTheSocket(port, &fsSockAddr); >- if (serverSocket < 0) { >- TPTP_LOG_ERROR_MSG(stateData, "NFS: unable to create the file server socket."); >- return 0; >- } >+ >+ rc = getTheSocket(port, serverSockets, &numServerSockets); > >- rc = bindAndListen(serverSocket, (struct sockaddr*)&fsSockAddr); >- if (rc != 0) { >- TPTP_LOG_ERROR_MSG(stateData, "NFS: cannot bind to server socket"); >+ //serverSocket = getTheSocket(port, &fsSockAddr); >+ if (rc < 0 || numServerSockets == 0) { >+ TPTP_LOG_ERROR_MSG(stateData, "NFS: unable to create the file server socket."); > return 0; > } >- >+ > while(1) { >- clientSock = acceptSocketConnection(serverSocket); >+ clientSock = acceptSocketConnections(serverSockets, numServerSockets, &socketAccept); > if (clientSock < 0) break; > > con = (fs_connection_block_t*) tptp_malloc(sizeof(fs_connection_block_t)); >Index: src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.h,v >retrieving revision 1.1 >diff -u -r1.1 nativeFileServer.h >--- src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.h 5 Feb 2008 14:34:58 -0000 1.1 >+++ src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.h 10 May 2008 19:33:00 -0000 >@@ -24,6 +24,10 @@ > #include <sys/types.h> > #endif > >+#ifndef _WIN32 >+ #define INVALID_SOCKET (-1) >+#endif >+ > #include "tptp/TPTPTypes.h" > #include "tptp/TPTPSupportTypes.h" > #include "tptp/TransportSupport.h" >Index: src-native-new/src/transport/TPTPClientCompTL/ClientCTL.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/ClientCTL.h,v >retrieving revision 1.25 >diff -u -r1.25 ClientCTL.h >--- src-native-new/src/transport/TPTPClientCompTL/ClientCTL.h 5 Feb 2008 14:34:58 -0000 1.25 >+++ src-native-new/src/transport/TPTPClientCompTL/ClientCTL.h 10 May 2008 19:32:57 -0000 >@@ -22,9 +22,18 @@ > #include "secureServer.h" > #include "tptp/TPTPUtils.h" > >+#include "tptp/TransportSupport.h" >+// I added the above header file for access to IPv4/IPv6 functions - jwest >+ > typedef struct > { >+ // IPV4-ONLY > SOCKET sock; >+ >+ SOCKET * sockets; // List of servers sockets we are listening on >+ tptp_uint32 numSockets; // Number of sockets we are listening on >+ socket_accept_t sockAccept; // State of server socket listening struct >+ > tptp_uint32 port; > tptp_uint32 filePort; > tptp_uint32 acProtocolPort; >Index: src-native-new/src/transport/TPTPClientCompTL/RACmdHandlers.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/RACmdHandlers.c,v >retrieving revision 1.58 >diff -u -r1.58 RACmdHandlers.c >--- src-native-new/src/transport/TPTPClientCompTL/RACmdHandlers.c 8 Apr 2008 04:45:05 -0000 1.58 >+++ src-native-new/src/transport/TPTPClientCompTL/RACmdHandlers.c 10 May 2008 19:33:00 -0000 >@@ -185,8 +185,6 @@ > PID real_pid; > ra_array_t finalEnvironment; > >- tptp_int32 buffer; >- int bufferLen=6; > SOCKET consoleSock; /* 9707 */ > ra_string_t uuid; > >@@ -203,19 +201,17 @@ > * In addition to launching the process, we need to look for any agents that > * the client expects to be associated with this process and attach to them > */ >- >- getClientIP(ccb, (unsigned char*)&buffer, &bufferLen); >- >+ > //ra_logServiceMessage(__FILE__, __LINE__, RA_DEBUG, "Console publish 0x%x, desired 0x%x socket=%d", command->info.launch_process.consoleIP, buffer, client->connection->handle.socket); > > real_pid=0; >- >+ > /* Launch Process */ > real_pid=startProcess(ccb, &command->info.launch_process.executable, > &command->info.launch_process.arguments, > &command->info.launch_process.location, > &command->info.launch_process.environment, >- buffer, >+ 0 /* This value isn't used. */, > (unsigned short)command->info.launch_process.consolePort, > &finalEnvironment, > &consoleSock, >@@ -739,8 +735,7 @@ > tptp_int32 rc = -1; > tptp_int32 flags; > tptp_int32 dataConnectionID; >- tptp_int32 clientIP; >- tptp_int32 clientIPLen; >+ struct sockaddr_storage * addr; > client_data_connection_block_t *dcb; > SOCKET dataSock; > >@@ -796,9 +791,10 @@ > flags = TPTP_DATA_PATH_RECEIVE | TPTP_DATA_PATH_DIRECT_SOCKET; > > if (agent->IPCBufCreated == FALSE) { >- getClientIP(ccb, (unsigned char*)&clientIP, &clientIPLen); >- dataSock = openClientDataSocket(clientIP, command->info.start_monitor_remote.port); > >+ getClientIPAddr(ccb, &addr); >+ dataSock = openClientDataSocketAddr(addr, command->info.start_monitor_remote.port); >+ > if (dataSock == -1) { > sendErrorMessage("RAC009", > "Start Monitoring failed due to data channel socket connection failure.", >Index: src-native-new/src/transport/TPTPClientCompTL/ClientCTL.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/ClientCTL.c,v >retrieving revision 1.49 >diff -u -r1.49 ClientCTL.c >--- src-native-new/src/transport/TPTPClientCompTL/ClientCTL.c 29 Apr 2008 19:19:25 -0000 1.49 >+++ src-native-new/src/transport/TPTPClientCompTL/ClientCTL.c 10 May 2008 19:32:57 -0000 >@@ -79,6 +79,8 @@ > return TPTP_ERROR_OUT_OF_MEMORY; > } > cctlData = (cctl_state_data_t*)stateData->implData; >+ >+ initSocketAccept(&(cctlData->sockAccept)); > > /* Read the TL configuration */ > rc = getConfigurationString(pTransportData->configurationData, "IsDataMultiplexed", &isDataMultiplexed); >@@ -538,12 +540,12 @@ > tptp_int32 startTransportListener(tptp_object* tlo) > { > int rc = 0; >- struct sockaddr_in myServerSockAddr ; > tl_state_data_t* stateData; > cctl_state_data_t* cctlData; > TID threadId; > HANDLE threadHandle; >- >+ SOCKET * socketList; >+ > if ( !isValidTPTPBlock(tlo, TPTP_BASETL_MAKE_OBJECT_ID(tlo)) ) > return TPTP_ERROR_INVALID_PARAMETER; > >@@ -560,23 +562,22 @@ > /* Create a pseudo-connection to monitor agent register events */ > startAgentRegistrationListener( stateData ); > >+ socketList = (SOCKET *)tptp_malloc(sizeof(SOCKET) * FD_SETSIZE); >+ >+ cctlData->sockets = socketList; >+ > /* create and initialize the server socket */ >- cctlData->sock = getTheSocket( cctlData->port, &myServerSockAddr ); >+ // cctlData->sock = getTheSocket( cctlData->port, &myServerSockAddr ); > >- if ( cctlData->sock < 0 ) >+ /* create and initialize the server socket */ >+ rc = getTheSocket(cctlData->port, cctlData->sockets, &(cctlData->numSockets)); >+ >+ if ( rc < 0 || cctlData->numSockets == 0 ) > { > TPTP_LOG_ERROR_MSG(stateData, "Error: unable to create the server socket.") ; > return -1; // TODO: Use a more specific error > } >- >- rc = bindAndListen(cctlData->sock, (struct sockaddr*)&myServerSockAddr); >- if ( rc != 0 ) >- { >- TPTP_LOG_SEVERE_MSG(stateData, "ERROR: Cannot start Agent Controller. "); >- TPTP_LOG_SEVERE_MSG1(stateData, "REASON: Cannot bind to socket port %d. Make sure the socket is free and no other Agent Controller is running.", cctlData->port); >- return -1; // TODO: Use a more specific error >- } >- >+ > if ((!cctlData->isJavaUnsecuredFileServer) && !cctlData->securityEnabled) { > rc = tptpStartThread(startNativeFileServer, (LPVOID)stateData, &threadId, &threadHandle); > CLOSE_THREAD_HANDLE(threadHandle); >@@ -643,7 +644,7 @@ > { > int ret; > >- ret = convertIPAddressUlongToString( cctlData->peerAttachAddress, &ipAddrStr ); >+ ret = convertIPAddressUlongToStringIPv4M( cctlData->peerAttachAddress, &ipAddrStr ); > if ( ret != 0 ) > { > return ret; >@@ -653,7 +654,7 @@ > { > /* NOTE: This has problems if there are multiple IP addresses, but in > the case of compatibility mode, this isn't really used anyway */ >- if (getSocketIPString( (SOCKET)NULL, &ipAddrStr) < 0) { >+ if (getSocketIPStringIPv4M( (SOCKET)NULL, &ipAddrStr) < 0) { > TPTP_LOG_ERROR_MSG(stateData, "Unable to get local IP address"); > return -1; > } >@@ -737,7 +738,7 @@ > TPTP_LOG_ERROR_MSG1( stateData, "Unable to find host in sourceConnectionInfo: %s", sourceConnectionInfo ); > return rc; > } >- rc = convertIPAddressStringToUlong( ipAddrStr, &ipAddr ); >+ rc = convertIPAddressStringToUlongIPv4M( ipAddrStr, &ipAddr ); > if ( rc != 0 ) > { > TPTP_LOG_ERROR_MSG1( stateData, "Unable to convert IP address string to unsigned long: %s", ipAddrStr ); >@@ -748,7 +749,7 @@ > /* TODO: Check to see if this is local */ > > /* Connect to the remote AC */ >- rc = connectToTCPServer( ipAddr, (unsigned short)port, &sock); >+ rc = connectToTCPServerIPv4M( ipAddr, (unsigned short)port, &sock); > if ( rc != 0 ) > { > TPTP_LOG_ERROR_MSG2( stateData, "Unable to connect to peer: %s, port %d", ipAddrStr, port ); >Index: src-native-new/src/transport/TPTPClientCompTL/CCTLServer.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/CCTLServer.c,v >retrieving revision 1.28 >diff -u -r1.28 CCTLServer.c >--- src-native-new/src/transport/TPTPClientCompTL/CCTLServer.c 29 Apr 2008 19:19:24 -0000 1.28 >+++ src-native-new/src/transport/TPTPClientCompTL/CCTLServer.c 10 May 2008 19:32:57 -0000 >@@ -465,7 +465,8 @@ > /* accept and process one connection at a time */ > while (stateData->processingThreadState == TPTP_TL_THREAD_RUNNING) > { >- clientSock = acceptSocketConnection(cctlData->sock); >+ // clientSock = acceptSocketConnection(cctlData->sock); >+ clientSock = acceptSocketConnections(cctlData->sockets, cctlData->numSockets, &(cctlData->sockAccept)); > > if (isSocketValid(clientSock) == 0) > { >@@ -478,8 +479,10 @@ > ra_message_t* message; > ra_command_t* command; > char *ipAddr; >- unsigned char address[12]; > tptp_int32 rc; >+ struct sockaddr_storage *sockAddr; >+ >+ sockAddr = getPeerAddrOfSocket(clientSock); > > rc = getPeerIPString(clientSock, &ipAddr); > if (rc != 0) >@@ -487,16 +490,19 @@ > TPTP_LOG_ERROR_MSG(stateData, "Connection refused could not getPeerIPString"); > continue; > } >- convertIPAddressStringToArray(ipAddr, address); > >- if (!tptp_checkHost(cctlData->network_list, address)) { >+ if (!tptp_checkHostIPv6(cctlData->network_list, sockAddr)) { >+ > TPTP_LOG_ERROR_MSG2(stateData, "Connection refused on socket %d on host %s", clientSock, ipAddr); > //printf("Connection refused on socket %d on host %s", clientSock, ipAddr); > tptp_free(ipAddr); >+ tptp_free(sockAddr); > closeThisSocket(clientSock); > continue; > } >+ > tptp_free(ipAddr); >+ tptp_free(sockAddr); > > setHandleInherited((HANDLE) clientSock) ; > >Index: src-native-new/include/tptp/MsgPipeline.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/include/tptp/MsgPipeline.h,v >retrieving revision 1.9 >diff -u -r1.9 MsgPipeline.h >--- src-native-new/include/tptp/MsgPipeline.h 1 Nov 2006 22:47:16 -0000 1.9 >+++ src-native-new/include/tptp/MsgPipeline.h 10 May 2008 19:32:53 -0000 >@@ -74,6 +74,14 @@ > unsigned int peerAttachAddress; > } PeerAttachInfo_t; > >+/* >+typedef struct { >+ char * transportType; >+ tptp_list_t hostList; >+ int port; >+} PeerIPv6Connection_t; >+*/ >+ > /* Optional functions provided by TLs involved in peer monitoring */ > typedef tptp_int32 (*setPeerAttachInfo_ptr_t)( tptp_object* tlo, PeerAttachInfo_t* peerInfo ); > typedef tptp_int32 (*getPeerConnectionInfo_ptr_t)( tptp_object* tlo, tptp_string* type, tptp_string** ci ); >Index: src-native-new/include/tptp/TransportSupportSocket.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/include/tptp/TransportSupportSocket.h,v >retrieving revision 1.9 >diff -u -r1.9 TransportSupportSocket.h >--- src-native-new/include/tptp/TransportSupportSocket.h 14 Jan 2008 07:49:58 -0000 1.9 >+++ src-native-new/include/tptp/TransportSupportSocket.h 10 May 2008 19:32:53 -0000 >@@ -40,7 +40,7 @@ > * non-zero failure code > * > *********************************************************/ >-int convertIPAddressStringToArray( char *addrStr, unsigned char* addrArray ); >+int convertIPAddressStringToArrayIPv4M( char *addrStr, unsigned char* addrArray ); > > /** > ********************************************************* >@@ -54,7 +54,7 @@ > * non-zero failure code > * > *********************************************************/ >-int convertIPAddressStringToUlong( char *addrStr, unsigned long* addr ); >+int convertIPAddressStringToUlongIPv4M( char *addrStr, unsigned long* addr ); > > /** > ********************************************************* >@@ -69,7 +69,7 @@ > * 0 success > * non-zero failure > *********************************************************/ >-int convertIPAddressUlongToString( unsigned long addr, char **addrStr ); >+int convertIPAddressUlongToStringIPv4M( unsigned long addr, char **addrStr ); > > /** > ********************************************************* >@@ -88,7 +88,7 @@ > * non-zero failure code > * > *********************************************************/ >-int getSocketIPString( SOCKET sock, char** ipAddrStr ); >+int getSocketIPStringIPv4M( SOCKET sock, char** ipAddrStr ); > > /** > ********************************************************* >@@ -118,7 +118,9 @@ > * @return > * host info data structure > *********************************************************/ >-struct hostent * getHostInfo() ; >+struct sockaddr_storage* getHostInfo(); >+ >+struct hostent * getHostInfoIPv4M(); > > /** > ********************************************************* >@@ -129,7 +131,7 @@ > * @return > * host info data structure > *********************************************************/ >-struct hostent * getTargetHostInfo(char* hostname) ; >+struct hostent * getTargetHostInfoIPv4M(char* hostname); > > /** > ********************************************************* >@@ -141,7 +143,7 @@ > * the raw unconnected socket > * > *********************************************************/ >-SOCKET getTheSocket(int portNum, struct sockaddr_in *pAddr) ; >+int getTheSocket(int portNum, SOCKET *outResult, int *outNumSockets); > > /** > ********************************************************* >@@ -153,7 +155,7 @@ > * 0 - Success > * nonzero - Error. > *********************************************************/ >-int bindAndListen(SOCKET sock, struct sockaddr *pAddr) ; >+SOCKET bindAndListen(struct addrinfo *AI); > > /** > ********************************************************* >@@ -173,12 +175,24 @@ > * connect to the given system > * > * @return >- * 0 - Success and the socket representing this connection >- * nonzero - Error. >+ * If we were able to connect pSock contans a SOCKET, otherwise, it's INVALID_SOCKET. >+ *********************************************************/ >+int connectToTCPServer(char * hostname, int port, SOCKET *pSock); >+ >+ >+/** >+ ********************************************************* >+ * >+ * @brief >+ * connect to the given system >+ * >+ * @return >+ * If we were able to connect pSock contans a SOCKET, otherwise, it's INVALID_SOCKET. > *********************************************************/ >-int connectToTCPServer(unsigned long ipAddr, >- unsigned short portNum, >- SOCKET *pSock); >+int connectToTCPServerAddr(struct sockaddr_storage * addr, int port, SOCKET *pSock); >+ >+ >+int connectToTCPServerIPv4M(unsigned long ipAddr, unsigned short portNum, SOCKET *pSock); > > /** > ********************************************************* >@@ -198,6 +212,47 @@ > > int closeSocket(int socket); > >+/** SOCKET -> struct sockaddr_storage * for the peer. */ >+struct sockaddr_storage * getPeerAddrOfSocket(SOCKET ConnSocket); >+ >+/** struct sockaddr_storage * => IP address in byte format (e.g. in_addr / in6_addr) + family >+ The bytes are stored in outAddr, and the family is stored in family.*/ >+void getByteFormatFromSockAddr(struct sockaddr_storage *addr, void ** outAddr, int *family); >+ >+void getSockAddrFromByteFormat(void *inAddr, int family, struct sockaddr_storage **outResult); >+ >+void setSockaddrStoragePort(struct sockaddr_storage *addr, int port); >+ >+typedef struct { >+ tptp_list_t serverSocketList; >+ >+ tptp_list_t socketsToProcess; >+ Lock_t sockProcLock; >+ >+} socket_accept_t; >+ >+SOCKET acceptSocketConnections(SOCKET * sockets, int numSockets, socket_accept_t * sockAcceptState); >+void initSocketAccept(socket_accept_t * sat); >+ >+struct sockaddr_storage * cloneSockAddr(struct sockaddr_storage * addr); >+ >+ >+int isAddrLocal(struct sockaddr_storage * addr); >+int compareAddresses(struct sockaddr_storage * one, struct sockaddr_storage * two); >+char * convertAddrToHostname(struct sockaddr_storage *addr); >+ >+void getLocalHostAddresses(struct sockaddr_storage *** arrOfAddr, int * numAddr); >+ >+void freeAddressList(struct sockaddr_storage ** arrOfAddr, int numAddr); >+ >+int convertHostnameToAddrs(char *hostname, struct sockaddr_storage *** outResult, int *outNumResults); >+ >+struct sockaddr_storage * getSelfAddrOfSocket(SOCKET ConnSocket); >+ >+void printSockAddrStorage(struct sockaddr_storage *inAddr); >+ >+SOCKET connectToHostWithHostname(char * hostnameOrIp, int port, struct addrinfo ** sockAddrOut ); >+ > #ifdef __cplusplus > } > #endif >Index: src-native-new/include/tptp/TransportOSCalls.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/include/tptp/TransportOSCalls.h,v >retrieving revision 1.4 >diff -u -r1.4 TransportOSCalls.h >--- src-native-new/include/tptp/TransportOSCalls.h 4 Apr 2006 22:14:57 -0000 1.4 >+++ src-native-new/include/tptp/TransportOSCalls.h 10 May 2008 19:32:53 -0000 >@@ -77,6 +77,7 @@ > * > * @return > * 0 - always >+ * IPV4-ONLY > *********************************************************/ > int printSocketRequest(SOCKET sock, struct sockaddr_in * pRequester) ; > >@@ -110,6 +111,7 @@ > *********************************************************/ > int closeThisSocket(SOCKET sock) ; > >+/** IPV4-ONLY */ > void extractAddressFromSockAddr(struct sockaddr_in *connection, unsigned char *address); > > >Index: src-native-new/include/tptp/TransportSupport.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/include/tptp/TransportSupport.h,v >retrieving revision 1.9 >diff -u -r1.9 TransportSupport.h >--- src-native-new/include/tptp/TransportSupport.h 2 Jun 2006 00:42:45 -0000 1.9 >+++ src-native-new/include/tptp/TransportSupport.h 10 May 2008 19:32:53 -0000 >@@ -95,6 +95,10 @@ > > BOOL tptp_checkHost(network_list_t *list, unsigned char *address); > >+SOCKET connectToHostWithAddr(struct sockaddr_storage *addr); >+ >+BOOL tptp_checkHostIPv6(network_list_t *list, struct sockaddr_storage * addr); >+ > #ifdef __cplusplus > } > #endif >Index: src-native-new/include/tptp/TPTPUtils.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/include/tptp/TPTPUtils.h,v >retrieving revision 1.24 >diff -u -r1.24 TPTPUtils.h >--- src-native-new/include/tptp/TPTPUtils.h 5 Feb 2008 14:30:09 -0000 1.24 >+++ src-native-new/include/tptp/TPTPUtils.h 10 May 2008 19:32:53 -0000 >@@ -98,6 +98,12 @@ > unsigned char net[4]; /* The network address information in network byte order. Note that this is IPV4 specific */ > unsigned char mask[4]; /* the subnet mask information in network byte order. Note that this is IPV4 specific */ > char *hostname; >+ >+ unsigned char netipv6[16]; >+ unsigned char maskipv6[16]; >+ >+ int netAndMaskAreIpv4; >+ > }network_t; > > typedef struct _network_list_node { >@@ -234,6 +240,7 @@ > int tptp_deleteSemaphore(Semaphore_t *pSem); > int tptp_waitSemaphore(Semaphore_t *pSem); > int tptp_postSemaphore(Semaphore_t *pSem); >+/*int tptp_waitSemaphoreTimeout(Semaphore_t *pSem, int timeoutInSecs);*/ > > int getFileSize(char *fileName); > int validateDirectory(char* dirName); >Index: src-native-new/src/transport/RASocket/RASocket.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/RASocket/RASocket.c,v >retrieving revision 1.5 >diff -u -r1.5 RASocket.c >--- src-native-new/src/transport/RASocket/RASocket.c 11 Apr 2008 06:33:35 -0000 1.5 >+++ src-native-new/src/transport/RASocket/RASocket.c 10 May 2008 19:32:56 -0000 >@@ -126,6 +126,7 @@ > * @returns 0 - create server was successful. > * <>0 - create failed, call ra_getlastErrorMajor/Minor > * to get the failure details. >+ * IPV4-ONLY > */ > int ra_createBoundUDPServer(short portNum, > ra_serverInfo_t *result) { >@@ -380,8 +381,8 @@ > * @returns 0 - create server was successful. > * <>0 - create failed, call ra_getlastErrorMajor/Minor > * to get the failure details. >+ * IPV4-ONLY > */ >- > int ra_createTCPServer(unsigned short portNum, > ra_serverInfo_t *result) { > >@@ -660,6 +661,7 @@ > * @returns 0 - connect was successful > * <0 - connect failed, can ra_getLastErrorMajor/Minor > * to get the failure details. >+ * IPV4-ONLY > */ > int ra_connectToTCPServer(ra_uint_t remoteIP, > unsigned short remotePortNum, >@@ -828,6 +830,7 @@ > * The number of characters written to the parameter buffer (excluding > * null terminator character. Otherwise, -1 if a severe error occurred. > * Call ra_getLastErrorMajor/Minor() to determine the error conditions. >+ * IPV4-ONLY > */ > short ra_getFormattedLocalIPAddress(char *ipAddressBuffer){ > >@@ -886,6 +889,7 @@ > * -1 - severe error occured getting the IP address. Call > * ra_getLastErrorMajor/Minor to determine the > * error conditions. >+ * IPV4-ONLY > */ > long ra_getLocalIPAddress() { > char localhost[MAX_HOST_NAME_LENGTH]; >@@ -916,6 +920,7 @@ > > return result; > } >+ > > /** GET_LOCAL_IP_ADDRESSES ******************************************* > * Get all the IP addresses associated with this physical host. >@@ -927,6 +932,7 @@ > * -1 - severe error occured getting the IP address. Call > * ra_getLastErrorMajor/Minor to determine the > * error conditions. >+ * IPV4-ONLY > */ > short ra_getLocalIPAddresses(ra_IPAddresses_t *addr) { > char localhost[MAX_HOST_NAME_LENGTH]; >@@ -1092,7 +1098,7 @@ > WORD wVersionRequested; > WSADATA wsaData; > int err; >- wVersionRequested = MAKEWORD(1, 1); >+ wVersionRequested = MAKEWORD(2, 2); > > err = WSAStartup(wVersionRequested, &wsaData); > >@@ -1109,8 +1115,8 @@ > /* 1.1 in wVersion since that is the version we */ > /* requested. */ > >- if ( LOBYTE( wsaData.wVersion ) != 1 || >- HIBYTE( wsaData.wVersion ) != 1 ) { >+ if ( LOBYTE( wsaData.wVersion ) != 2 || >+ HIBYTE( wsaData.wVersion ) != 2 ) { > /* Tell the user that we couldn't find a useable */ > /* winsock.dll. */ > ra_setLastError(SOCKET_INITIALIZE_FAILED, err); >Index: src-native-new/src/transport/RASocket/RASocket.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/RASocket/RASocket.h,v >retrieving revision 1.3 >diff -u -r1.3 RASocket.h >--- src-native-new/src/transport/RASocket/RASocket.h 19 Mar 2007 03:14:37 -0000 1.3 >+++ src-native-new/src/transport/RASocket/RASocket.h 10 May 2008 19:32:56 -0000 >@@ -71,6 +71,7 @@ > * @returns 0 - create server was successful. > * <>0 - create failed, call ra_getlastErrorMajor/Minor > * to get the failure details. >+ * IPV4-ONLY > */ > extern int ra_createBoundUDPServer(short portNum, > ra_serverInfo_t *resultSet); >@@ -89,6 +90,7 @@ > * @returns 0 - create server was successful. > * <>0 - create failed, call ra_getlastErrorMajor/Minor > * to get the failure details. >+ * IPV4-ONLY > */ > extern int ra_createTCPServer(unsigned short portNum, > ra_serverInfo_t *resultSet); >@@ -148,6 +150,7 @@ > * The number of characters written to the parameter buffer (excluding > * null terminator character. Otherwise, -1 if a severe error occurred. > * Call ra_getLastErrorMajor/Minor() to determine the error conditions. >+ * IPV4-ONLY > */ > extern short ra_getFormattedLocalIPAddress(char *ipAddressBuffer); > >Index: src-native-new/src/transport/transportSupport/TransportSupport.def >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/transportSupport/TransportSupport.def,v >retrieving revision 1.19 >diff -u -r1.19 TransportSupport.def >--- src-native-new/src/transport/transportSupport/TransportSupport.def 14 Jan 2008 07:49:59 -0000 1.19 >+++ src-native-new/src/transport/transportSupport/TransportSupport.def 10 May 2008 19:33:01 -0000 >@@ -25,7 +25,7 @@ > ipcMemWrite @22 > ipcFlushToFunc @23 > ipcStopFlushing @24 >- getTargetHostInfo @25 >+ convertHostnameToAddrs @25 > setHandleInherited @26 > isSocketValid @27 > destroyNamedPipe @28 >@@ -39,18 +39,36 @@ > ipcMemWriteWithDIME @36 > isValidTPTPBlock @37 > getPeerName @38 >- convertIPAddressStringToArray @39 >- convertIPAddressStringToUlong @40 >+ convertIPAddressStringToArrayIPv4M @39 > getSocketIPString @41 > ipcFlushToFD @42 > tptp_checkHost @43 > openNonCriticalWriteOnlyNamedPipe @44 > getPeerIPString @45 >- convertIPAddressUlongToString @46 >+ convertIPAddressUlongToStringIPv4M @46 > getSocketPort @47 > ipcStopFlusher @48 > ipcCloseMem @49 > isMemOpen @50 > ipcMemDetach @51 > closeSocket @52 >- >\ No newline at end of file >+ getHostInfoIPv4M @53 >+ convertIPAddressStringToUlongIPv4M @54 >+ getSocketIPStringIPv4M @55 >+ freeAddressList @56 >+ getTargetHostInfoIPv4M @57 >+ getPeerAddrOfSocket @58 >+ getByteFormatFromSockAddr @59 >+ getSockAddrFromByteFormat @60 >+ connectToHostWithAddr @61 >+ setSockaddrStoragePort @62 >+ connectToTCPServerAddr @63 >+ connectToTCPServerIPv4M @64 >+ acceptSocketConnections @65 >+ initSocketAccept @66 >+ cloneSockAddr @67 >+ getLocalHostAddresses @68 >+ tptp_checkHostIPv6 @69 >+ getSelfAddrOfSocket @70 >+ printSockAddrStorage @71 >+ connectToHostWithHostname @72 >\ No newline at end of file >Index: src-native-new/src/transport/transportSupport/TransportSupportSocket.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/transportSupport/TransportSupportSocket.c,v >retrieving revision 1.25 >diff -u -r1.25 TransportSupportSocket.c >--- src-native-new/src/transport/transportSupport/TransportSupportSocket.c 14 Jan 2008 11:16:47 -0000 1.25 >+++ src-native-new/src/transport/transportSupport/TransportSupportSocket.c 10 May 2008 19:33:02 -0000 >@@ -21,24 +21,149 @@ > > #include "tptp/NoLog.h" > >+// The following if-else was added for IPv6 support >+#ifdef _WIN32 >+ #include <ws2tcpip.h> >+#else >+ #define INVALID_SOCKET -1 >+ #define SOCKET_ERROR -1 >+#endif >+ >+static void convertAddrToIpString(struct sockaddr_storage * addr, char **hostname); >+static SOCKET getSocketFromAddrList(struct addrinfo *AddrInfo, struct addrinfo **sockAddrOut); > > /** > ********************************************************* > * > * @brief >- * get the localhost socket connection >+ * get the localhost (server) socket connection > * >- * @return >- * the raw unconnected socket >+ * @param portNum The port number of the local host to listen on. >+ * @param outResult A pointer to an array of SOCKETS to be listened on >+ * @param outNumSockets The integer that is passed in as a pointer to this function is set to the number of sockets of the outResult array >+ *********************************************************/ >+int getTheSocket(int portNum, SOCKET *outResult, int *outNumSockets) { >+ int Family = PF_UNSPEC; >+ int SocketType = SOCK_STREAM; >+ char PortStr[8]; >+ char *Address = NULL; >+ int i, RetVal; >+ >+ struct addrinfo Hints, *AddrInfo, *AI; >+ SOCKET* sockArr; >+ >+ SOCKET serverSocket; >+ >+ int ServSockSize = 0; >+ >+ sprintf(PortStr, "%d", portNum); >+ >+ sockArr = outResult; >+ >+ // MS' description of the following call: >+ // By setting the AI_PASSIVE flag in the hints to getaddrinfo, we're >+ // indicating that we intend to use the resulting address(es) to bind >+ // to a socket(s) for accepting incoming connections. This means that >+ // when the Address parameter is NULL, getaddrinfo will return one >+ // entry per allowed protocol family containing the unspecified address >+ // for that family. >+ // >+ memset(&Hints, 0, sizeof (Hints)); >+ Hints.ai_family = Family; >+ Hints.ai_socktype = SocketType; >+ Hints.ai_flags = AI_NUMERICHOST | AI_PASSIVE; >+ RetVal = getaddrinfo(Address, PortStr, &Hints, &AddrInfo); >+ if (RetVal != 0) { >+ return -1; >+ } >+ >+ // First check for IPv6 connections >+ for (i = 0, AI = AddrInfo; AI != NULL; AI = AI->ai_next) { >+ >+ // Highly unlikely, but check anyway. >+ if (i == FD_SETSIZE) { >+ TPTP_LOG_ERROR_MSG("getaddrinfo exceeded the number of available addrs"); >+ return -1; >+ } >+ >+ // PF_INET6 only >+ if (!(AI->ai_family == PF_INET6)) { >+ continue; >+ } >+ >+ serverSocket = bindAndListen(AI); >+ if(serverSocket >= 0) { >+ sockArr[ServSockSize++] = serverSocket; >+ } >+ i++; >+ } >+ >+ // Then check IPv4 >+ for (i = 0, AI = AddrInfo; AI != NULL; AI = AI->ai_next) { >+ >+ // Highly unlikely, but check anyway. >+ if (i == FD_SETSIZE) { >+ TPTP_LOG_ERROR_MSG("getaddrinfo returned more addresses than we could use."); >+ return -1; >+ } >+ >+ if (!(AI->ai_family == PF_INET)) { >+ continue; >+ } >+ >+ // jwest: On our Linux machines, listening on IPv6 also listened on IPv4. So if we get an error here, "Address already in Use", we can ignore it. >+ serverSocket = bindAndListen(AI); >+ if(serverSocket >= 0) { >+ sockArr[ServSockSize++] = serverSocket; >+ } >+ >+ i++; >+ } >+ >+ freeaddrinfo(AddrInfo); >+ >+ *outNumSockets = ServSockSize; >+ >+ if (ServSockSize == 0) { >+ TPTP_LOG_ERROR_MSG("Fatal error: unable to serve on any address.") ; >+ return -1; >+ } >+ >+ return 0; >+} >+ >+/** >+ ********************************************************* >+ * >+ * @brief >+ * bind and prepare the server socket > * >+ * @return >+ * 0 - Success >+ * nonzero - Error. > *********************************************************/ >-SOCKET getTheSocket(int portNum, struct sockaddr_in *pAddr) >-{ >- pAddr->sin_family = AF_INET; >- pAddr->sin_port = htons((u_short) portNum); >- pAddr->sin_addr.s_addr = htonl(INADDR_ANY); >+SOCKET bindAndListen(struct addrinfo *AI) { >+ >+ SOCKET ServSock; >+ >+ // Open a socket with the correct address family for this address. >+ ServSock = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol); >+ if (ServSock == INVALID_SOCKET) { >+ return -1; >+ } >+ >+ if (bind(ServSock, AI->ai_addr, (int)AI->ai_addrlen) == SOCKET_ERROR) { >+ closeThisSocket(ServSock); >+ return (-1); >+ } >+ >+ if (listen(ServSock, 5) == SOCKET_ERROR) { >+ closeThisSocket(ServSock); >+ return (-1); >+ } >+ >+ return (ServSock); > >- return socket(AF_INET, SOCK_STREAM, 0) ; > } > > /** >@@ -49,7 +174,7 @@ > * > * @return > * the port number >- * >+ * IPV4-ONLY > *********************************************************/ > int getSocketPort(SOCKET sock) > { >@@ -66,12 +191,48 @@ > ********************************************************* > * > * @brief >- * get the localhost info >- * >+ * Gets the localhost info. >+ * >+ * Note: When resolving the addresses of the local host, this function will always return the >+ * first in the list of addresses given to it by the operating system. For the actual list of local addresses, >+ * use a different function. >+ * >+ * Returns NULL if no address could be obtained. >+ * > * @return > * host info data structure > *********************************************************/ >-struct hostent * getHostInfo() >+struct sockaddr_storage* getHostInfo() >+{ >+ int RetVal; >+ char *Address = NULL; >+ char *Port = "10002"; // Hardcoded because we need a port >+ >+ struct addrinfo Hints, *AddrInfo; >+ struct sockaddr_storage *result = NULL; >+ >+ >+ int Family = PF_UNSPEC; // Give us both the IPv4 and IPv6 addresses >+ int SocketType = SOCK_STREAM; >+ >+ memset(&Hints, 0, sizeof (Hints)); >+ Hints.ai_family = Family; >+ Hints.ai_socktype = SocketType; >+ Hints.ai_flags = AI_NUMERICHOST; >+ >+ RetVal = getaddrinfo(Address, Port, &Hints, &AddrInfo); >+ >+ if(RetVal == 0) { >+ >+ result = cloneSockAddr((struct sockaddr_storage *)AddrInfo->ai_addr); >+ >+ freeaddrinfo(AddrInfo); >+ } >+ >+ return (result); >+} >+ >+struct hostent * getHostInfoIPv4M() > { > char localhost[MAX_HOST_NAME_LENGTH+1]; > >@@ -92,7 +253,7 @@ > * 0 success > * non-zero failure > *********************************************************/ >-int convertIPAddressStringToUlong( char *addrStr, unsigned long* addr ) >+int convertIPAddressStringToUlongIPv4M( char *addrStr, unsigned long* addr ) > { > *addr = inet_addr( addrStr ); > if ( *addr == INADDR_NONE ) >@@ -123,13 +284,36 @@ > *********************************************************/ > int getSocketIPString( SOCKET sock, char** ipAddrStr ) > { >+ struct sockaddr_storage *sockAddrPtr = NULL; >+ >+ if ( sock == (SOCKET)NULL ) >+ { >+ sockAddrPtr = getHostInfo(); >+ } >+ else >+ { >+ sockAddrPtr = getSelfAddrOfSocket(sock); >+ } >+ >+ if (sockAddrPtr == NULL) return -1; >+ >+ convertAddrToIpString(sockAddrPtr, ipAddrStr); >+ if ( *ipAddrStr == NULL ) >+ { >+ return TPTP_SYS_NO_MEM; >+ } >+ return 0; >+} >+ >+int getSocketIPStringIPv4M( SOCKET sock, char** ipAddrStr ) >+{ > char* temp; > > if ( sock == (SOCKET)NULL ) > { > struct hostent* hinfo; > >- hinfo = getHostInfo(); >+ hinfo = getHostInfoIPv4M(); > if (hinfo == NULL) return -1; > > /* The socket code owns 'temp' as returned below, so we need to copy it */ >@@ -164,6 +348,7 @@ > return 0; > } > >+ > /** > ********************************************************* > * >@@ -183,53 +368,31 @@ > *********************************************************/ > int getPeerIPString( SOCKET sock, char** ipAddrStr ) > { >- char* temp; >+ struct sockaddr_storage *sockAddrPtr = NULL; > > if ( sock == (SOCKET)NULL ) > { > return -1; > } >- else >- { >- int saSize; >- struct sockaddr_in saddr; > >- saddr.sin_family = AF_INET; >- saddr.sin_port = htons(0); >- saddr.sin_addr.s_addr = INADDR_ANY; >- BZERO(&saddr.sin_zero,8); >+ sockAddrPtr = getPeerAddrOfSocket(sock); > >- saSize = sizeof(struct sockaddr); >- //getsockname returns the local address to get the address >- //of the clinet we need to call getpeername. >- getpeername(sock,(struct sockaddr *)&saddr,&saSize); >- >- /* The socket code owns 'temp' as returned below, so we need to copy it */ >- temp = inet_ntoa(saddr.sin_addr); >+ if(sockAddrPtr == NULL) { >+ TPTP_LOG_ERROR_MSG("Error: Unable to get the address information for the remote peer.") ; > } > >- //Need to add 1 to strlen so free doesn't crash! >- *ipAddrStr = (char *)tptp_malloc( strlen(temp) +1); >+ convertAddrToIpString(sockAddrPtr, ipAddrStr); >+ tptp_free(sockAddrPtr); > if ( *ipAddrStr == NULL ) > { > return TPTP_SYS_NO_MEM; > } > >- strcpy( *ipAddrStr, temp ); >- > return 0; > } > >-/** >- ********************************************************* >- * >- * @brief >- * get the localhost info >- * >- * @return >- * host info data structure >- *********************************************************/ >-struct hostent * getTargetHostInfo(char* hostname) >+ >+struct hostent * getTargetHostInfoIPv4M(char* hostname) > { > struct hostent *pInfo = NULL ; > >@@ -239,56 +402,66 @@ > return ( pInfo ); > } > >- > /** > ********************************************************* > * > * @brief >- * bind and prepare the server socket >+ * get the localhost info > * > * @return >- * 0 - Success >- * nonzero - Error. >+ * host info data structure > *********************************************************/ >-int bindAndListen(SOCKET sock, struct sockaddr *pAddr) >-{ >- int rc = 0 ; >+int convertHostnameToAddrs(char *hostname, struct sockaddr_storage *** outResult, int *outNumResults) { >+ int RetVal; >+ int i; > >- setsockopt(sock, >- SOL_SOCKET, >- SO_REUSEADDR, >- 0, >- 0); >+ struct addrinfo Hints, *AddrInfo, *AI; > >+ int Family = PF_UNSPEC; // Give us both the IPv4 and IPv6 addresses >+ int SocketType = SOCK_STREAM; // TCP only > >- rc = bind(sock, pAddr, sizeof(struct sockaddr)) ; >+ struct sockaddr_storage ** result; > >- if (rc < 0) >- { >- TPTP_LOG_ERROR_MSG("Error: cannot bind to the socket.") ; >- //printCurrentSysError() ; >+ // malloc an array of pointers to struct sockaddr_storages >+ result = (struct sockaddr_storage **)tptp_malloc(sizeof(struct sockaddr_storage *) * 128); >+ >+ memset(&Hints, 0, sizeof (Hints)); >+ Hints.ai_family = Family; >+ Hints.ai_socktype = SocketType; >+ >+ // This was originally in the code, but it prevents lookups of host names, e.g. www.google.com. It only works with numeric hosts. >+ // Hints.ai_flags = AI_NUMERICHOST; >+ >+ RetVal = getaddrinfo(hostname, NULL, &Hints, &AddrInfo); >+ >+ for (i = 0, AI = AddrInfo; AI != NULL; AI = AI->ai_next, i++) { >+ result[i] = cloneSockAddr((struct sockaddr_storage *)AI->ai_addr); > } >- else >- { >- int result; >+ freeaddrinfo(AddrInfo); > >- result = setHandleInherited((HANDLE)sock) ; >- if ( result == 0 ) >- { >- TPTP_LOG_ERROR_MSG("Error: unable to set handle info.") ; >- rc = - 1; >- } >- else >- { >- rc = listen(sock, 100) ; >- if (rc < 0) >- { >- TPTP_LOG_ERROR_MSG("Error: unable to listen.") ; >- } >- } >+ *outResult = result; >+ *outNumResults = i; >+ >+ return RetVal; >+} >+ >+ >+/** >+ ********************************************************* >+ * >+ * @brief >+ * frees acquired addresses list >+ * >+ * @return >+ * host info data structure >+ *********************************************************/ >+void freeAddressList(struct sockaddr_storage ** arrOfAddr, int numAddr) { >+ int x = 0; >+ >+ for(x = 0; x < numAddr; x++) { >+ tptp_free(arrOfAddr[x]); > } > >- return ( rc ) ; > } > > /** >@@ -300,6 +473,7 @@ > * @return > * 0 - Success > * nonzero - Error. >+ * IPV4-ONLY > *********************************************************/ > int getPeerName(SOCKET sock, unsigned char* pAddr) > { >@@ -329,7 +503,7 @@ > SOCKET acceptSocketConnection(SOCKET serverSock) > { > SOCKET clientSock ; >- struct sockaddr_in clientAddress; >+ struct sockaddr_storage clientAddress; > size_t clientLen=sizeof(clientAddress); > int rc = 0 ; > int enable=1; >@@ -385,7 +559,25 @@ > * 0 - Success and the socket representing this connection > * nonzero - Error. > *********************************************************/ >-int connectToTCPServer(unsigned long ipAddr, >+int connectToTCPServer(char * hostname, int port, SOCKET *pSock) >+{ >+ int rc = 0 ; >+ SOCKET sock ; >+ struct addrinfo *AI = NULL; >+ >+ TPTP_LOG_DEBUG_MSG("connectToTCPServer...") ; >+ >+ sock = connectToHostWithHostname(hostname, port, &AI); >+ >+ freeaddrinfo(AI); >+ >+ *pSock = sock ; >+ >+ return ( rc ) ; >+} >+ >+ >+int connectToTCPServerIPv4M(unsigned long ipAddr, > unsigned short portNum, > SOCKET *pSock) > { >@@ -446,6 +638,35 @@ > ********************************************************* > * > * @brief >+ * connect to the given system >+ * >+ * @return >+ * 0 - Success and the socket representing this connection >+ * nonzero - Error. >+ *********************************************************/ >+int connectToTCPServerAddr(struct sockaddr_storage * addr, int port, SOCKET *pSock) >+{ >+ int rc = 0 ; >+ SOCKET sock ; >+ >+ TPTP_LOG_DEBUG_MSG("connectToTCPServerAddr...") ; >+ >+ setSockaddrStoragePort(addr, port); >+ >+ sock = connectToHostWithAddr(addr); >+ >+ *pSock = sock ; >+ >+ return ( rc ) ; >+} >+ >+ >+ >+ >+/** >+ ********************************************************* >+ * >+ * @brief > * common interface to terminate the given connection > * (socket). > * >@@ -480,3 +701,641 @@ > return closeThisSocket(socket); > } > #endif >+ >+struct sockaddr_storage * cloneSockAddr(struct sockaddr_storage * addr) { >+ struct sockaddr_storage* result; >+ >+ if(addr->ss_family == PF_INET){ >+ result = (struct sockaddr_storage *)tptp_malloc(sizeof(struct sockaddr_in)); >+ memcpy(result, (struct sockaddr_in *)addr,sizeof(struct sockaddr_in)); >+ >+ } else if(addr->ss_family == PF_INET6) { >+ result = (struct sockaddr_storage *) tptp_malloc(sizeof(struct sockaddr_in6)); >+ memcpy(result, (struct sockaddr_in6 *)addr, sizeof(struct sockaddr_in6)); >+ } else { >+ result = (struct sockaddr_storage *) NULL; >+ } >+ >+ return result; >+} >+ >+static void convertAddrToIpString(struct sockaddr_storage * addr, char **hostname) { >+ int r; >+ >+ *hostname = (char *)tptp_malloc(sizeof(char) * NI_MAXHOST); >+ if(*hostname == NULL) return; >+ >+ memset(*hostname, 0, sizeof(char) * NI_MAXHOST); >+ // hostname[0] = 0; >+ >+ r = getnameinfo((struct sockaddr *)addr, sizeof(struct sockaddr_storage), *hostname, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); >+} >+ >+/** SOCKET -> struct sockaddr_storage * for the peer. */ >+struct sockaddr_storage * getPeerAddrOfSocket(SOCKET ConnSocket) { >+ int result = 0; >+ int addrLen = 0; >+ struct sockaddr_storage * addr; >+ >+ addrLen = sizeof(struct sockaddr_storage); >+ addr = (struct sockaddr_storage *)tptp_malloc(sizeof(struct sockaddr_storage)); >+ >+ result = getpeername(ConnSocket, (struct sockaddr *) addr, &addrLen); >+ >+ if(result == SOCKET_ERROR) { >+ TPTP_LOG_ERROR_MSG("getpeername call failed to get peer address") ; >+ return NULL; >+ } >+ >+ return addr; >+} >+ >+/** SOCKET => struct sockaddr_storage *, of the host's side of the socket. For the peer's address, use getPeerAddrOfSocket. */ >+struct sockaddr_storage * getSelfAddrOfSocket(SOCKET ConnSocket) { >+ struct sockaddr_storage Addr; >+ struct sockaddr_storage *result; >+ int r = 0; >+ >+ socklen_t AddrLen = 0; >+ >+ AddrLen = sizeof (Addr); >+ >+ r = getsockname(ConnSocket, (struct sockaddr *) & Addr, &AddrLen); >+ >+ if(r != 0) return NULL; >+ >+ result = (struct sockaddr_storage *)tptp_malloc(sizeof(struct sockaddr_storage)); >+ >+ memcpy(result, &Addr, sizeof(struct sockaddr_storage)); >+ >+ return result; >+} >+ >+/** Creates a client socket connection to the given hostname/ip, on the given port. The sockAddrOut variable is set to the particular >+ struct addrinfo that was used to create the connection. This allows you to determine the family, either IPV4 of IPV6 (if needed.) >+ >+ If a hostname is specified in 'hostnameOrIp', this method will try to connect on both the IPv4 and IPv6 addresses of the hostname, where available. It >+ returns the first successful SOCKET connection as a result. >+ >+ If an IP address is specified in 'hostnameOrIp', this method will only connect on either the IPv4 (x.x.x.x) or IPv6 (xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx) >+ address of that host (based on the format of the ip address that is based in). >+ */ >+SOCKET connectToHostWithHostname(char * hostnameOrIp, int port, struct addrinfo ** sockAddrOut ) { >+ int Family = PF_UNSPEC; >+ int SocketType = SOCK_STREAM; // TCP >+ int RetVal; >+ char portStr[8]; >+ struct addrinfo Hints, *AddrInfo; >+ SOCKET ConnSocket; >+ >+ // Convert the integer port to a string for getaddrinfo >+ sprintf(portStr, "%d", port); >+ >+ // >+ // By not setting the AI_PASSIVE flag in the hints to getaddrinfo, we're >+ // indicating that we intend to use the resulting address(es) to connect >+ // to a service. This means that when the Server parameter is NULL, >+ // getaddrinfo will return one entry per allowed protocol family >+ // containing the loopback address for that family. >+ // >+ >+ memset(&Hints, 0, sizeof (Hints)); >+ Hints.ai_family = Family; >+ Hints.ai_socktype = SocketType; >+ RetVal = getaddrinfo(hostnameOrIp, portStr, &Hints, &AddrInfo); >+ >+ if (RetVal != 0) { >+ return -1; >+ } >+ >+ if (AddrInfo == NULL) { >+ return -1; >+ } >+ >+ ConnSocket = getSocketFromAddrList(AddrInfo, sockAddrOut); >+ >+ return ConnSocket; >+} >+ >+/** Connects to the given address, and returns a SOCKET for that conncetion. If a socket could not be created, >+ then INVALID_SOCKET is returned. Note: The struct sockaddr_storage must have a port specified. */ >+SOCKET connectToHostWithAddr(struct sockaddr_storage *addr) { >+ SOCKET sock; >+ int enable = 1 ; >+ BOOL nagle = FALSE; >+ struct linger linger; >+ int rc = 0 ; >+ int loopcnt = 0; >+ >+ // Open a socket with the correct address family for this address. >+ sock = socket(addr->ss_family, SOCK_STREAM, 0); >+ >+ setsockopt(sock, >+ SOL_SOCKET, >+ SO_KEEPALIVE, >+ (const char*)&enable, >+ sizeof(enable)); >+ >+ linger.l_onoff=1; >+ linger.l_linger=3; >+ setsockopt(sock, >+ SOL_SOCKET, >+ SO_LINGER, >+ (const char*)&linger, >+ sizeof(linger)); >+ >+ setsockopt(sock, >+ IPPROTO_TCP, >+ TCP_NODELAY, >+ (const char*)&nagle, >+ sizeof(nagle)); >+ >+ /* go make the connection */ >+#ifndef _WIN32 >+ do { >+ rc = connect(sock, (struct sockaddr*)addr, sizeof(struct sockaddr_storage)); >+ loopcnt++; >+ } while (rc == -1 && errno == EINTR && loopcnt < 50); >+#else >+ rc = connect(sock, (struct sockaddr*)addr, sizeof(struct sockaddr_storage)) ; >+#endif >+ >+ /* >+ if (connect(sock, (struct sockaddr *)addr, sizeof(struct sockaddr_storage)) == SOCKET_ERROR) { >+ closeThisSocket(sock); >+ return INVALID_SOCKET; >+ }*/ >+ >+ return sock; >+} >+ >+/** Sets the port of a struct sockaddr_storage. */ >+void setSockaddrStoragePort(struct sockaddr_storage *addr, int port) { >+ if(addr->ss_family == PF_INET) { >+ struct sockaddr_in *saddr = (struct sockaddr_in *)addr; >+ saddr->sin_port = htons(port); >+ >+ } else if(addr->ss_family == PF_INET6) { >+ struct sockaddr_in6 *saddr = (struct sockaddr_in6 *) addr; >+ >+ saddr->sin6_port = htons(port); >+ } >+} >+ >+/** Given a list of addresses (AddrInfo), it returns a SOCKET for the first one it is able to successfully connect to. The socket is returned >+ as the return value from this function, and the the address of that socket is returned in sockAddrOut. >+ Note: If a connection cannot be made, INVALID_SOCKET is returned. */ >+static SOCKET getSocketFromAddrList(struct addrinfo *AddrInfo, struct addrinfo **sockAddrOut) { >+ struct addrinfo *AI; >+ SOCKET ConnSocket = INVALID_SOCKET; >+ char AddrName[NI_MAXHOST]; >+ >+ if(sockAddrOut != NULL) { >+ *sockAddrOut = 0; >+ } >+ >+ // >+ // Try each address getaddrinfo returned, until we find one to which >+ // we can successfully connect. >+ // >+ for (AI = AddrInfo; AI != NULL; AI = AI->ai_next) { >+ >+ // Open a socket with the correct address family for this address. (on error -1 is returned) >+ ConnSocket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol); >+ >+ if (ConnSocket == INVALID_SOCKET) { >+ continue; >+ } >+ >+ // printf("Attempting to connect to: %s\n", Server ? Server : "localhost"); >+ if (connect(ConnSocket, AI->ai_addr, (int)AI->ai_addrlen) != SOCKET_ERROR) { >+ if(sockAddrOut != NULL) { >+ *sockAddrOut = AI; >+ } >+ break; >+ } >+ >+ if (getnameinfo(AI->ai_addr, (socklen_t)AI->ai_addrlen, AddrName, sizeof (AddrName), NULL, 0, NI_NUMERICHOST) != 0) { >+ } >+ >+ closeThisSocket(ConnSocket); >+ ConnSocket = INVALID_SOCKET; >+ } >+ >+ return ConnSocket; >+} >+ >+/** struct sockaddr_storage * => IP address in byte format (e.g. in_addr / in6_addr) + family >+ The bytes are stored in outAddr, and the family is stored in family.*/ >+void getByteFormatFromSockAddr(struct sockaddr_storage *addr, void ** outAddr, int *family) { >+ >+ if(addr->ss_family == PF_INET) { >+ >+ struct sockaddr_in * sin = (struct sockaddr_in *) addr; >+ struct in_addr ia = sin->sin_addr; >+ >+ struct in_addr *result = (struct in_addr *)tptp_malloc(sizeof(struct in_addr)); >+ memcpy(result, &ia, sizeof(ia)); >+ >+ *family = PF_INET; >+ >+ *outAddr = result; >+ >+ } else { // PF_INET6 >+ >+ struct sockaddr_in6 * sin6 = (struct sockaddr_in6 *) addr; >+ struct in6_addr ia = sin6->sin6_addr; >+ struct in6_addr *result = (struct in6_addr *)tptp_malloc(sizeof(struct in6_addr)); >+ memset(result, 0, sizeof(struct in6_addr)); >+ >+ memcpy(result, &ia, sizeof(struct in6_addr)); >+ *family = PF_INET6; >+ >+ *outAddr = result; >+ >+ } >+} >+ >+/** Given the IP Address in byte format (e.g. in_addr/inaddr_6) and the family >+ => struct sockaddr_storage * (either sockaddr_in or sockaddr_in6) */ >+void getSockAddrFromByteFormat(void *inAddr, int family, struct sockaddr_storage **outResult) { >+ >+ if(family == PF_INET) { >+ struct in_addr * ia = (struct in_addr *)inAddr; >+ struct sockaddr_in * result = (struct sockaddr_in *)tptp_malloc(sizeof(struct sockaddr_in)); >+ >+ memcpy(&result->sin_addr, ia, sizeof(struct in_addr)); >+ result->sin_family = family; >+ result->sin_port = htons(0); >+ memset(result->sin_zero, 0, 8); >+ >+ *outResult = (struct sockaddr_storage*)result; >+ >+ } else { // PF_INET6 >+ >+ struct in6_addr * ia = (struct in6_addr *)inAddr; >+ struct sockaddr_in6 * result = (struct sockaddr_in6 *) tptp_malloc(sizeof(struct sockaddr_in6)); >+ >+ memcpy(&result->sin6_addr, ia, sizeof(struct in6_addr)); >+ result->sin6_family = family; >+ result->sin6_port = htons(0); >+ result->sin6_flowinfo = 0; >+ result->sin6_scope_id = 0; >+ >+ *outResult = (struct sockaddr_storage*)result; >+ } >+} >+ >+void initSocketAccept(socket_accept_t * sat) { >+ tptp_list_init(&(sat->serverSocketList)); >+ tptp_list_init(&(sat->socketsToProcess)); >+ >+ tptp_initializeLock(&sat->sockProcLock); >+ >+} >+ >+typedef struct { >+ socket_accept_t * sat; >+ SOCKET * serverSocket; >+ >+} listenOnSocket_parameters_t; >+ >+/** Used by acceptSocketConnections. Parameter is a listenOnSocket_parameters_t pointer. */ >+THREAD_USER_FUNC_RET_TYPE listenAcceptSocketConnections(LPVOID args) >+{ >+ SOCKET *serverSock; >+ SOCKET clientSock; >+ SOCKET *outClientSock; >+ socket_accept_t * sat; >+ struct sockaddr_storage clientAddress; >+ size_t clientLen=sizeof(clientAddress); >+ >+ listenOnSocket_parameters_t *lpt; >+ >+ lpt = (listenOnSocket_parameters_t *) args; >+ >+ serverSock = lpt->serverSocket; >+ sat = lpt->sat; >+ >+ while(1) { >+ // Listen on the socket that we have been passed >+ clientSock = accept(*serverSock, (struct sockaddr * ) & clientAddress, (int *)&clientLen); >+ >+ if(clientSock == INVALID_SOCKET) { >+ TPTP_LOG_ERROR_MSG("An invalid socket was returned by an accept() call.") ; >+ continue; >+ } >+ >+ // Add the socket to the list of sockets >+ >+ tptp_getWriteLock(&(sat->sockProcLock)); >+ >+ outClientSock = (SOCKET *) tptp_malloc(sizeof(SOCKET)); >+ *outClientSock = clientSock; >+ >+ tptp_list_add(&(sat->socketsToProcess), outClientSock); >+ >+ tptp_releaseWriteLock(&(sat->sockProcLock)); >+ >+ } >+ >+ return 0; >+ >+} >+ >+ >+/** >+Spawns threads to accept() on a list of given sockets, and returns the SOCKET from those threads. >+*/ >+SOCKET acceptSocketConnections(SOCKET * sockets, int numSockets, socket_accept_t * sockAcceptState) { >+ int i = 0; >+ tptp_node_t * node; >+ tptp_list_t * socketsMonitored = &(sockAcceptState->serverSocketList); >+ SOCKET * s; >+ SOCKET result; >+ int matchFound = 0; >+ TID threadID; >+ HANDLE threadHandle; >+ int socketsWaiting = 0; >+ >+ listenOnSocket_parameters_t *params; >+ >+ // Given the list of sockets, scan through and see if we are being asked to listen on any new ones >+ for(i = 0; i < numSockets; i++) { >+ s = &(sockets[i]); >+ matchFound = 0; >+ >+ // Scan through the list of sockets that we're already monitoring: check if there are any new additions >+ node = socketsMonitored->head; >+ while(node != NULL) { >+ if(node->data == s) { >+ matchFound = 1; >+ break; >+ } >+ node = node->next; >+ } >+ >+ if(!matchFound) { >+ tptp_list_add(socketsMonitored, s); >+ params = (listenOnSocket_parameters_t*) tptp_malloc(sizeof(listenOnSocket_parameters_t)); >+ params->sat = sockAcceptState; >+ params->serverSocket = s; >+ >+ tptpStartThread(listenAcceptSocketConnections, params, &threadID, &threadHandle) ; >+ } >+ } >+ >+ do { >+ // Check if there are any client sockets waiting... >+ tptp_getReadLock(&(sockAcceptState->sockProcLock)); >+ >+ socketsWaiting = (sockAcceptState->socketsToProcess).count; >+ >+ tptp_releaseReadLock(&(sockAcceptState->sockProcLock)); >+ >+ if(!socketsWaiting) { >+ Sleep(10); >+ } >+ >+ } while(!socketsWaiting); // While (there are no new sockets) >+ >+ tptp_getWriteLock(&(sockAcceptState->sockProcLock)); >+ >+ // Get the value at the top of the list. >+ node = sockAcceptState->socketsToProcess.head; >+ >+ result = *((SOCKET *)node->data); >+ >+ s = (SOCKET*)(node->data); >+ tptp_list_remove(&(sockAcceptState->socketsToProcess), s); // This calls frees the malloced socket. >+ >+ tptp_releaseWriteLock(&(sockAcceptState->sockProcLock)); >+ >+ return result; >+ >+} >+ >+ >+/** A (binary) comparison of the contents of two addresses. >+Note, it does not compare the port value, or any of the other sockaddr_in/sockaddr_in6 fields, merely the address field. >+Also note, if the family of the two addresses differs, then this function will return FALSE. If you're looking for a way to compare IPv4 and >+IPv6 addresses together, try comparing their resolved hostnames. */ >+int compareAddresses(struct sockaddr_storage * one, struct sockaddr_storage * two) { >+ struct sockaddr_in * a4; >+ struct sockaddr_in * b4; >+ >+ struct sockaddr_in6 *a6; >+ struct sockaddr_in6 *b6; >+ int x = 0; >+ >+ unsigned char a; >+ unsigned char b; >+ >+ if(one->ss_family != two->ss_family) return 0; >+ >+ if(one->ss_family == PF_INET) { >+ a4 = (struct sockaddr_in *)one; >+ b4 = (struct sockaddr_in *)two; >+ >+ if(sizeof(a4->sin_addr) != sizeof(b4->sin_addr)) return 0; >+ >+ for(x = 0; x < sizeof(a4->sin_addr); x++) { >+ a = ((unsigned char*)&a4->sin_addr)[x]; >+ b = ((unsigned char*)&b4->sin_addr)[x]; >+ >+ if(a != b) return 0; >+ } >+ >+ } else if(one->ss_family == PF_INET6) { >+ a6 = (struct sockaddr_in6 *)one; >+ b6 = (struct sockaddr_in6 *)two; >+ >+ if(sizeof(a6->sin6_addr) != sizeof(b6->sin6_addr)) return 0; >+ >+ for(x = 0; x < sizeof(a6->sin6_addr); x++) { >+ a = ((unsigned char*)&a6->sin6_addr)[x]; >+ b = ((unsigned char*)&b6->sin6_addr)[x]; >+ >+ if(a != b) return 0; >+ >+ } >+ >+ } else { >+ return 0; >+ } >+ >+ return 1; >+} >+ >+/** sockaddr_storage -> "www.google.com" */ >+char * convertAddrToHostname(struct sockaddr_storage *addr) { >+ char * hostname; >+ hostname = (char *)tptp_malloc(sizeof(char) * 260); >+ hostname[0] = 0; >+ >+ getnameinfo((struct sockaddr *)addr, sizeof(struct sockaddr_storage), hostname, 260, NULL, 0, 0); >+ >+ return hostname; >+ >+} >+ >+/** This method uses a number of tricks to determine whether or not the given address is local. */ >+int isAddrLocal(struct sockaddr_storage * addr) { >+ int foundMatch = 0; >+ int x = 0; >+ struct sockaddr_storage ** addrList; >+ int addrListSize = 0; >+ >+ char *hostName; >+ char *localHostName = NULL; >+ >+ getLocalHostAddresses(&addrList, &addrListSize); >+ for(x = 0; x < addrListSize; x++) { >+ >+ if(!foundMatch) { >+ foundMatch = compareAddresses(addrList[x], addr); >+ >+ if(localHostName == NULL) { >+ localHostName = convertAddrToHostname(addrList[x]); >+ } >+ } >+ } >+ >+ // If we couldn't match using binary comparison, resolve both hostnames and compare those, also try standard localhost addrs >+ if(!foundMatch) { >+ >+ hostName = convertAddrToHostname(addr); >+ >+ if(hostName != NULL && (strcmp(hostName, "::1") == 0 || strcmp(hostName, "127.0.0.1") == 0 || strcmp(hostName, "localhost") == 0)) { >+ foundMatch = 1; >+ } >+ >+ if(localHostName != NULL && hostName != NULL && strcmp(localHostName, hostName) == 0 ) { >+ foundMatch = 1; >+ } >+ tptp_free(hostName); >+ } >+ >+ freeAddressList(addrList, addrListSize); >+ tptp_free(localHostName); >+ >+ return foundMatch; >+} >+ >+ >+ >+/** Get localhost addresses in sockaddr_storage form. Note that sockaddr_storages received from this method use port >+10002, and this will need to change if they are being listened on. */ >+void getLocalHostAddresses(struct sockaddr_storage *** arrOfAddr, int * numAddr) { >+ int RetVal; >+ char *Address = NULL; >+ char *Port = "10002"; // One needs to specify a port, so I'm giving it this one. >+ int i = 0, size = 0, x = 0, y = 0; >+ struct sockaddr_storage ** addrs; >+ int matchFound = 0; >+ >+ char hostname[260]; >+ >+ struct sockaddr_storage ** resultArr = (struct sockaddr_storage **)tptp_malloc(sizeof(struct sockaddr_storage) * 64); >+ >+ struct addrinfo Hints, *AddrInfo = NULL, *AI; >+ >+ int Family = PF_UNSPEC; // Give us both the IPv4 and IPv6 addresses >+ int SocketType = SOCK_STREAM; >+ >+ *numAddr = 0; >+ >+ memset(&Hints, 0, sizeof (Hints)); >+ Hints.ai_family = Family; >+ Hints.ai_socktype = SocketType; >+ Hints.ai_flags = AI_NUMERICHOST; >+ >+ RetVal = getaddrinfo(Address, Port, &Hints, &AddrInfo); >+ >+ if(RetVal != 0) return; >+ >+ for (i = 0, AI = AddrInfo; AI != NULL; AI = AI->ai_next) { >+ resultArr[i] = cloneSockAddr((struct sockaddr_storage *)AI->ai_addr); >+ >+ i++; >+ } >+ >+ freeaddrinfo(AddrInfo); >+ >+ // Grab the user's hostname >+ if(gethostname(hostname, 260) == 0) { >+ >+ // Resolve it to a list of IP addresses >+ convertHostnameToAddrs(hostname, &addrs, &size); >+ >+ // For each address... >+ for(x = 0; x< size; x++) { >+ matchFound = 0; >+ >+ // Verify that that address is not already in the list >+ for(y = 0; y < i; y++) { >+ if(compareAddresses(addrs[x], resultArr[y])) { >+ matchFound = 1; >+ break; >+ } >+ } >+ >+ // If it's not found, add it to the list >+ if(!matchFound) { >+ resultArr[i] = addrs[x]; >+ i++; >+ } else { >+ // Otherwise, that address is already in the list, so free it >+ tptp_free(addrs[x]); >+ } >+ } >+ } >+ >+ >+ >+ *numAddr = i; >+ *arrOfAddr = resultArr; >+} >+ >+ >+/** Given a range of bytes, print their int value. */ >+void printChars(unsigned char *b, int l) { >+ int x = 0; >+ >+ for(x = 0; x < l; x++) { >+ printf("[%d]", (*b)); >+ b++; >+ } >+} >+ >+/** For debug purposes, prints the values of the fields of sockaddr_storage.*/ >+void printSockAddrStorage(struct sockaddr_storage *inAddr) { >+ >+ if(inAddr->ss_family == PF_INET) { >+ struct sockaddr_in * ia = (struct sockaddr_in *)inAddr; >+ >+ printf("addr: "); >+ printChars((unsigned char*)&(ia->sin_addr), 4); >+ printf("\r\n"); >+ >+ printf("family: %d\r\n", ia->sin_family); >+ printf("port: %d\r\n", ia->sin_port); >+ printf("zero: %s\r\n", ia->sin_zero); >+ >+ >+ } else { // PF_INET6 >+ >+ struct sockaddr_in6 * ia = (struct sockaddr_in6 *)inAddr; >+ >+ printf("addr: "); >+ printChars((unsigned char*)&(ia->sin6_addr), 16); >+ printf("\r\n"); >+ >+ printf("family: %d\r\n", (int)ia->sin6_family); >+ printf("flowinfo: %d\r\n", (int)ia->sin6_flowinfo); >+ printf("port: %d\r\n", (int)ia->sin6_port); >+ printf("scope_id: %d\r\n", (int)ia->sin6_scope_id); >+ >+ } >+ >+} >Index: src-native-new/src/transport/transportSupport/TransportSupport.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/transportSupport/TransportSupport.c,v >retrieving revision 1.19 >diff -u -r1.19 TransportSupport.c >--- src-native-new/src/transport/transportSupport/TransportSupport.c 21 Nov 2007 15:43:37 -0000 1.19 >+++ src-native-new/src/transport/transportSupport/TransportSupport.c 10 May 2008 19:33:01 -0000 >@@ -323,7 +323,7 @@ > return (isValid) ; > } > >- >+/* IPV4-ONLY */ > long tptp_getLocalIPAddress() { > char localhost[MAX_HOST_NAME_LENGTH]; > struct hostent *hpLocal; >@@ -352,7 +352,7 @@ > return result; > } > >-short tptp_getLocalIPAddresses(tptp_IPAddresses_t *addr) { >+short tptp_getLocalIPAddressesIPv4M(tptp_IPAddresses_t *addr) { > char localhost[MAX_HOST_NAME_LENGTH]; > struct hostent *hpLocal; > int count, i; >@@ -399,7 +399,7 @@ > return 0; > } > >-int isLocalHost(char* name) { >+int isLocalHostIPv4M(char* name) { > tptp_IPAddresses_t localAddresses; > struct hostent *he; > unsigned char *addr, *cur; >@@ -412,7 +412,7 @@ > > addr = he->h_addr_list[0]; > >- if(tptp_getLocalIPAddresses(&localAddresses) != 0) return 0; >+ if(tptp_getLocalIPAddressesIPv4M(&localAddresses) != 0) return 0; > > res = 0; > len = localAddresses.addressLength; >@@ -432,6 +432,7 @@ > return res; > } > >+/** IPV4-ONLY */ > BOOL tptp_checkHost(network_list_t *list, unsigned char *address) { > network_list_node_t *current; > >@@ -464,7 +465,7 @@ > /* We need to continuously recheck the IP address of the local machine as this can change > on modern operating systems without a reboot > */ >- if(tptp_getLocalIPAddresses(&localAddresses)==0) { >+ if(tptp_getLocalIPAddressesIPv4M(&localAddresses)==0) { > int len=localAddresses.addressLength; > unsigned char *current; > current=localAddresses.addresses; >@@ -545,7 +546,7 @@ > aliases++; > } > >- if (isLocalHost(hostnameAllowed) && isLocalHost(hostnameEntry)) { >+ if (isLocalHostIPv4M(hostnameAllowed) && isLocalHostIPv4M(hostnameEntry)) { > return entry->allow ? TRUE : FALSE; > } > } >@@ -556,3 +557,133 @@ > > return FALSE; > } >+ >+BOOL tptp_checkHostIPv6(network_list_t *list, struct sockaddr_storage * addr) { >+ network_list_node_t *current; >+ int x = 0; >+ unsigned char * ipaddr; >+ int family = 0; >+ int r = 0; >+ >+ //If the list or host address is not specified then return TRUE. >+ //this means configuration is not specified. >+ if (list == NULL) { >+ return TRUE; >+ } >+ >+ if (addr == NULL) { >+ return TRUE; >+ } >+ >+ current = list->head; >+ >+ /* Look at the host list in order and find a matching rule */ >+ while(current) { >+ network_t *entry=current->entry; >+ /* Is this an allow rule */ >+ >+ switch(entry->wildcard) { >+ >+ case TPTP_HW_ALL: >+ if(entry->allow) { >+ return TRUE; >+ } >+ return FALSE; >+ break; >+ case TPTP_HW_LOCAL: >+ >+ if(isAddrLocal(addr)) { >+ if(entry->allow) { >+ return TRUE; >+ } >+ return FALSE; >+ } >+ break; >+ /* We are currently going to ignore UNKNOWN, and KNOWN posibilities */ >+ case TPTP_HW_UNKNOWN: >+ break; >+ case TPTP_HW_KNOWN: >+ break; >+ case TPTP_HW_MAX_VALUE: >+ break; >+ case TPTP_HW_NET: >+ { >+ getByteFormatFromSockAddr(addr, (void **)&ipaddr, &family); >+ if(entry->netAndMaskAreIpv4 && addr->ss_family == PF_INET) { >+ /* Check to see if the host is OK based upon net and mask. If the mask and the remote address >+ and-ed together equal the net then it is a match */ >+ if((entry->mask[0] & ipaddr[0]) == entry->net[0] >+ && (entry->mask[1] & ipaddr[1]) == entry->net[1] >+ && (entry->mask[2] & ipaddr[2]) == entry->net[2] >+ && (entry->mask[3] & ipaddr[3]) == entry->net[3]) { >+ if(entry->allow) { >+ return TRUE; >+ } >+ return FALSE; >+ } >+ } else if(!entry->netAndMaskAreIpv4 && addr->ss_family == PF_INET6){ >+ >+ r = 1; >+ for(x = 0; x < 16; x++) { >+ if( (entry->maskipv6[x] & ipaddr[x]) == entry->netipv6[x]) { >+ // No mismatch, this is good. >+ } else { >+ // We've found a mismatch. Set false and break. >+ r = 0; >+ break; >+ } >+ } >+ if(r) { >+ if(entry->allow) { >+ return TRUE; >+ } >+ return FALSE; >+ } >+ } >+ >+ } >+ break; >+ case TPTP_HW_NAMED: >+ { >+ char *hostname; >+ >+ struct sockaddr_storage ** addrs; >+ int numAddrs = 0; >+ int x = 0; >+ >+ // Convert the config host name to a list of addresses and compare them >+ convertHostnameToAddrs(entry->hostname, &addrs, &numAddrs); >+ for(x = 0; x < numAddrs; x++) { >+ if(compareAddresses(addr, addrs[x])) { >+ freeAddressList(addrs, numAddrs); >+ >+ if(entry->allow) { >+ return TRUE; >+ } >+ return FALSE; >+ >+ } >+ } >+ freeAddressList(addrs, numAddrs); >+ >+ if(isAddrLocal(addr)) { >+ return (entry->allow) ? TRUE : FALSE; >+ } >+ >+ hostname = convertAddrToHostname(addr); >+ >+ if(strcasecmp(hostname, entry->hostname) == 0) { >+ tptp_free(hostname); >+ return (entry->allow) ? TRUE : FALSE; >+ } >+ >+ tptp_free(hostname); >+ >+ } >+ break; >+ } >+ current=current->next; >+ } >+ >+ return FALSE; >+} >Index: src-native-new/src/transport/transportSupport/TransportOSCalls_win.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/transportSupport/TransportOSCalls_win.c,v >retrieving revision 1.8 >diff -u -r1.8 TransportOSCalls_win.c >--- src-native-new/src/transport/transportSupport/TransportOSCalls_win.c 1 Nov 2006 22:47:16 -0000 1.8 >+++ src-native-new/src/transport/transportSupport/TransportOSCalls_win.c 10 May 2008 19:33:01 -0000 >@@ -33,13 +33,13 @@ > WSADATA wsaData; > int rc = 0 ; > >- wVersionRequested = MAKEWORD(1, 1); >+ wVersionRequested = MAKEWORD(2, 2); > > rc = WSAStartup(wVersionRequested, &wsaData); > > if (rc == 0) > { >- if ( LOBYTE( wsaData.wVersion ) != 1 || HIBYTE( wsaData.wVersion ) != 1 ) >+ if ( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 ) > { > WSACleanup(); > rc = -1 ; >@@ -91,6 +91,7 @@ > * > * @return > * 0 - always >+ * IPV4-ONLY > *********************************************************/ > int printSocketRequest(SOCKET sock, struct sockaddr_in *pRequester) > { >@@ -174,7 +175,7 @@ > * 0 success > * non-zero failure > *********************************************************/ >-int convertIPAddressStringToArray( char *addrStr, unsigned char* addrArray ) >+int convertIPAddressStringToArrayIPv4M( char *addrStr, unsigned char* addrArray ) > { > struct in_addr addr; > >@@ -205,7 +206,7 @@ > * 0 success > * non-zero failure > *********************************************************/ >-int convertIPAddressUlongToString( unsigned long addr, char **addrStr ) >+int convertIPAddressUlongToStringIPv4M( unsigned long addr, char **addrStr ) > { > char* tempAddrStr; > struct in_addr saddr; >@@ -230,6 +231,7 @@ > return 0; > } > >+/** IPV4-ONLY */ > void extractAddressFromSockAddr(struct sockaddr_in *connection, unsigned char *address) > { > address[0]=connection->sin_addr.S_un.S_un_b.s_b1; >Index: src-native-new/src/transport/transportSupport/TransportOSCalls_linux.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/transportSupport/TransportOSCalls_linux.c,v >retrieving revision 1.10 >diff -u -r1.10 TransportOSCalls_linux.c >--- src-native-new/src/transport/transportSupport/TransportOSCalls_linux.c 16 May 2007 15:16:22 -0000 1.10 >+++ src-native-new/src/transport/transportSupport/TransportOSCalls_linux.c 10 May 2008 19:33:01 -0000 >@@ -84,6 +84,7 @@ > * > * @return > * 0 - always >+ * IPV4-ONLY > *********************************************************/ > int printSocketRequest(SOCKET sock, struct sockaddr_in *pRequester) > { >@@ -169,7 +170,7 @@ > * 0 success > * non-zero failure > *********************************************************/ >-int convertIPAddressStringToArray( char *addrStr, unsigned char* addrArray ) >+int convertIPAddressStringToArrayIPv4M( char *addrStr, unsigned char* addrArray ) > { > struct in_addr addr; > int rc; >@@ -205,7 +206,7 @@ > * 0 success > * non-zero failure > *********************************************************/ >-int convertIPAddressUlongToString( unsigned long addr, char **addrStr ) >+int convertIPAddressUlongToStringIPv4M( unsigned long addr, char **addrStr ) > { > char* tempAddrStr; > struct in_addr saddr; >@@ -230,6 +231,7 @@ > return 0; > } > >+/** IPV4-ONLY */ > void extractAddressFromSockAddr(struct sockaddr_in *connection, unsigned char *address) > { > unsigned long tmpAddr; >Index: src-native-new/src/shared/TPTPUtil/TPTPSemaphore.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/shared/TPTPUtil/TPTPSemaphore.c,v >retrieving revision 1.3 >diff -u -r1.3 TPTPSemaphore.c >--- src-native-new/src/shared/TPTPUtil/TPTPSemaphore.c 2 May 2007 17:43:27 -0000 1.3 >+++ src-native-new/src/shared/TPTPUtil/TPTPSemaphore.c 10 May 2008 19:32:54 -0000 >@@ -20,6 +20,12 @@ > #include <errno.h> > #endif > >+/* >+#ifndef _WIN32 >+ #include <semaphore.h> >+ #include <time.h> >+#endif >+*/ > /* Semaphore utilities */ > > /* >@@ -114,3 +120,41 @@ > > return 0; > } >+/* >+int tptp_waitSemaphoreTimeout(Semaphore_t *pSem, int timeoutInSecs) { >+ // Note this code is a placeholder that hasn't been tested. >+ // Keep this in mind when using it. - jwest >+#ifdef _WIN32 >+ unsigned long rc; >+ if (pSem->hSem == NULL) >+ return -1; >+ >+ rc = WaitForSingleObject(pSem->hSem, timeoutInSecs*1000); >+ if(rc == WAIT_TIMEOUT) { >+ return -2; >+ } else >+ if (rc != WAIT_OBJECT_0) >+ return -1; >+ >+#else >+ struct timespec waitTime; >+ if (clock_gettime(CLOCK_REALTIME, &waitTime) == -1) { >+ return -1; >+ } >+ waitTime.tv_sec += timeoutInSecs; >+ >+ while (1) { >+ int rc = sem_timedwait(&(pSem->sem), &waitTime); >+ if (rc == 0) break; >+ >+ if(errno == ETIMEDOUT) { >+ return -2; >+ } >+ if (errno != EINTR) return -1; >+ } >+#endif >+ >+ return 0; >+} >+*/ >+ >Index: src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp,v >retrieving revision 1.40 >diff -u -r1.40 TPTPUtil.cpp >--- src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp 9 May 2008 16:01:30 -0000 1.40 >+++ src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp 10 May 2008 19:32:55 -0000 >@@ -1685,6 +1685,77 @@ > #define ELEMENT_TRANS_LYR_VARIABLE "TransportLayer" > #define ELEMENT_CONFIGURATION_VARIABLE "Configuration" > >+ >+/** Converts an ASCII hex character to an int. */ >+int getcharhexval(char c) { >+ if(c >= '0' && c <= '9') { >+ return c - '0'; >+ } >+ >+ if(c >= 'A' && c <= 'F') { >+ return c - 'A' + 10; >+ } >+ >+ if(c >= 'a' && c <= 'f') { >+ return c - 'a' + 10; >+ } >+ >+ return -1; >+ >+} >+ >+void parseStringIntoBlock(char *str, unsigned char *result) { >+ unsigned int val = 0; >+ >+ val = getcharhexval(str[2])*16 + getcharhexval(str[3]); >+ result[1] = (unsigned char)val; >+ >+ >+ val = getcharhexval(str[0]) * 16 + getcharhexval(str[1]); >+ result[0] = (unsigned char)val; >+ >+} >+ >+void parseIPv6IP(char *str, unsigned char *result) { >+ >+ char *nameTemp = 0; >+ int i; >+ >+ nameTemp = (char *)tptp_malloc(strlen(str)+10); >+ strcpy(nameTemp, str); >+ >+ if(strcmp(str, "::1") == 0) { >+ for(int x = 0; x < 16; x++) { >+ result[x] = 0; >+ } >+ result[15] = 1; >+ >+ return; >+ } >+ >+ /* start at the back of the string and calculate the address*/ >+ for(i=14; i>0; i-=2) { >+ char *current=strrchr(nameTemp, ':'); >+ if(current == NULL) { >+ // The IP address is of an improper format, so bail. >+ tptp_free(nameTemp); >+ for(int x = 0; x < 16; x++) { >+ result[x] = 0; >+ } >+ return; >+ } >+ // result[i]=(char)atoi(current+1); >+ parseStringIntoBlock(current+1, &(result[i])); >+ >+ *current='\0'; >+ } >+ parseStringIntoBlock(nameTemp, &(result[0])); >+ // result[0]=atoi(nameTemp); >+ >+ tptp_free(nameTemp); >+ >+} >+ > void tptp_addNetwork(network_list_t *list, int allow, tptp_host_wildcard_t wildcard, char *name, char *mask) > { > char *nameTemp = NULL; >@@ -1699,12 +1770,13 @@ > > /* set the type in the node */ > network->allow=allow; >- >+ > /* copy name to a temporary buffer */ > if (name != NULL) { > nameTemp = (char *) tptp_malloc(strlen(name) +1); > strcpy(nameTemp, name); > } >+ > /* copy mask to a temporary buffer */ > if (mask != NULL) { > maskTemp = (char *) tptp_malloc(strlen(mask) +1); >@@ -1713,23 +1785,12 @@ > > /* If the wildcard in TPTP_HW_NAMED then we need to copy the address information */ > if(wildcard==TPTP_HW_NAMED) { >- >- /* If the first character is a digit then we have a numeric address. This >- is effectively the same as a TPTP_HW_NET with a mask of 255.255.255.255 >- */ >- if(isdigit((int)*nameTemp)) { >- maskTemp = (char*)tptp_malloc(sizeof(char) * 16); /* one extra char for null char */ >- strcpy(maskTemp, "255.255.255.255"); >- wildcard=TPTP_HW_NET; >- } >- else { >- network->hostname = (char *) tptp_malloc(strlen(nameTemp) +1); >- strcpy(network->hostname, nameTemp); >- } >+ network->hostname = (char *) tptp_malloc(strlen(nameTemp) +1); >+ strcpy(network->hostname, nameTemp); > } > >- /* If this is a network then we need to copy the address information */ >- if(wildcard==TPTP_HW_NET) { >+ /* If this is a network then we need to copy the IPv4 address information */ >+ if(wildcard==TPTP_HW_NET && strstr(name, ".") != NULL) { > int i; > > /* start at the back of the string and calculate the address*/ >@@ -1746,6 +1807,16 @@ > *current='\0'; > } > network->mask[0]=atoi(maskTemp); >+ >+ network->netAndMaskAreIpv4 = 1; >+ >+ } // TPTP_HW_NET - IPv6 address >+ else if(wildcard==TPTP_HW_NET && strstr(name, ":") != NULL) { >+ >+ parseIPv6IP(name, network->netipv6); >+ parseIPv6IP(mask, network->maskipv6); >+ >+ network->netAndMaskAreIpv4 = 0; > } > > if(nameTemp) tptp_free(nameTemp); nameTemp = NULL; >Index: src-native-new/src/transport/socketTL/SocketListener.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/socketTL/SocketListener.c,v >retrieving revision 1.49 >diff -u -r1.49 SocketListener.c >--- src-native-new/src/transport/socketTL/SocketListener.c 29 Apr 2008 19:19:26 -0000 1.49 >+++ src-native-new/src/transport/socketTL/SocketListener.c 10 May 2008 19:33:00 -0000 >@@ -115,6 +115,14 @@ > int setSSL(request_block_ptr_t pBlk); > int handleAUTHENTICATE(request_block_ptr_t pBlk, char *pMsg); > >+THREAD_USER_FUNC_RET_TYPE serveRequestThread(LPVOID args); >+ >+typedef struct { >+ SOCKET serverSock; >+ server_block_ptr_t pServerData; >+} serve_request_params_t; >+ >+ > /** > ********************************************************* > * >@@ -658,6 +666,14 @@ > return ( pRequestDataBlock ) ; > } > >+THREAD_USER_FUNC_RET_TYPE serveRequestThread(LPVOID args) { >+ >+ serve_request_params_t * params = (serve_request_params_t *)args; >+ serveRequest(params->serverSock, params->pServerData); >+ >+ return 0; >+} >+ > > /** > ********************************************************* >@@ -678,6 +694,8 @@ > TID threadId; > HANDLE threadHandle ; > >+ // struct sockaddr_storage *selfaddr; >+ > /* initial status before the thread is running */ > pServerData->threadStatus = RUNNING ; > pServerData->serverSock = serverSock ; >@@ -687,6 +705,8 @@ > { > clientSock = acceptSocketConnection(serverSock); > >+// selfaddr = getSelfAddrOfSocket(clientSock); >+ > if (isSocketValid(clientSock) == 0) > { > TPTP_LOG_ERROR_MSG(pServerData, "Accept() receives invalid socket request. ") ; >@@ -761,29 +781,37 @@ > THREAD_USER_FUNC_RET_TYPE doListening(LPVOID args) > { > int rc = 0; >- SOCKET serverSock ; >+ SOCKET serverSockets[FD_SETSIZE]; >+ int socketNum = 0; >+ int i; >+ unsigned long pthreadId; >+ HANDLE pthreadHandle; > >- struct sockaddr_in myServerSockAddr ; >- >+ serve_request_params_t * params; >+ > server_block_ptr_t pParam = (server_block_ptr_t) args ; > > /* create and initialize the server socket */ >- serverSock = getTheSocket(pParam->port, &myServerSockAddr) ; >+ rc = getTheSocket(pParam->port, serverSockets, &socketNum) ; > >- if (serverSock < 0) >+ if (socketNum == 0) > { > TPTP_LOG_ERROR_MSG(pParam, "Error: unable to create the server socket.") ; > } > >- else >- rc = bindAndListen(serverSock, (struct sockaddr*)&myServerSockAddr) ; >- >- > /* ready to accept incoming connection requests */ >- if (rc == 0) >+ if (socketNum != 0 && rc == 0) > { > TPTP_LOG_DEBUG_MSG1(pParam, "Socket server is running at port number of %d.", pParam->port) ; >- serveRequest(serverSock, pParam) ; >+ for (i=0; i < socketNum; ++i) { >+ >+ params = (serve_request_params_t *)tptp_malloc(sizeof(serve_request_params_t)); >+ params->pServerData = pParam; >+ params->serverSock = serverSockets[i]; >+ >+ tptpStartThread(serveRequestThread, params, &pthreadId, &pthreadHandle); >+ >+ } > } > > return ( 0 ); >@@ -1111,7 +1139,7 @@ > /* NOTE: This has problems if there are multiple IP addresses, but in > the case of compatibility mode, this isn't really used anyway */ > >- if (getSocketIPString( (SOCKET)NULL, &ipAddrStr) < 0) { >+ if (getSocketIPStringIPv4M( (SOCKET)NULL, &ipAddrStr) < 0) { > TPTP_LOG_ERROR_MSG(pServerData, "Unable to get local IP address"); > return -1; > } >@@ -1169,7 +1197,7 @@ > TPTP_LOG_ERROR_MSG1( pServerData, "Unable to find host in connection info: %s", sourceConnectionInfo ); > return rc; > } >- rc = convertIPAddressStringToUlong( ipAddrStr, &ipAddr ); >+ rc = convertIPAddressStringToUlongIPv4M( ipAddrStr, &ipAddr ); > if ( rc != 0 ) > { > TPTP_LOG_ERROR_MSG1( pServerData, "Unable to convert IP address string to unsigned long: %s", ipAddrStr ); >@@ -1180,7 +1208,7 @@ > /* TODO: Check to see if this is local */ > > /* Connect to the remote AC */ >- rc = connectToTCPServer( ipAddr, (unsigned short)port, &sock); >+ rc = connectToTCPServerIPv4M( ipAddr, (unsigned short)port, &sock); > if ( rc != 0 ) > { > TPTP_LOG_ERROR_MSG2( pServerData, "Unable to connect to peer: %s, port %d", ipAddrStr, port ); >Index: src-native-new/src/shared/TPTPLogUtils/TPTPCBE.cpp >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/shared/TPTPLogUtils/TPTPCBE.cpp,v >retrieving revision 1.7 >diff -u -r1.7 TPTPCBE.cpp >--- src-native-new/src/shared/TPTPLogUtils/TPTPCBE.cpp 21 Oct 2005 23:54:26 -0000 1.7 >+++ src-native-new/src/shared/TPTPLogUtils/TPTPCBE.cpp 10 May 2008 19:32:54 -0000 >@@ -155,25 +155,16 @@ > if ( formattedLocalIPAddress[0] == '\0' ) > { > char hostname[CBE_HOSTNAME_SIZE+1]; >- struct hostent *host; > > // TODO: Make WSAStartup call on Windows > > if ( gethostname(hostname, CBE_HOSTNAME_SIZE) == 0 ) > { >- host = gethostbyname(hostname); >- if(host == NULL) >- { >- sprintf(formattedLocalIPAddress, "%s", hostname); >- } >- else >- { >- sprintf(formattedLocalIPAddress, "%s", host->h_name); >- } >+ sprintf(formattedLocalIPAddress, "%s", hostname); > } > else > { >- sprintf(formattedLocalIPAddress, "127.0.0.1"); >+ sprintf(formattedLocalIPAddress, "localhost"); > } > } > >Index: src-native-new/src/shared/TPTPLogUtils/TPTPLogUtils.cpp >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/shared/TPTPLogUtils/TPTPLogUtils.cpp,v >retrieving revision 1.1 >diff -u -r1.1 TPTPLogUtils.cpp >--- src-native-new/src/shared/TPTPLogUtils/TPTPLogUtils.cpp 12 Sep 2005 17:52:55 -0000 1.1 >+++ src-native-new/src/shared/TPTPLogUtils/TPTPLogUtils.cpp 10 May 2008 19:32:54 -0000 >@@ -35,7 +35,7 @@ > { > WSADATA wsaData; > >- WSAStartup( MAKEWORD(1, 1), &wsaData); >+ WSAStartup( MAKEWORD(2, 2), &wsaData); > } > break; > >Index: src-native-new/src/client/TCPDataServer.cpp >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/client/TCPDataServer.cpp,v >retrieving revision 1.24 >diff -u -r1.24 TCPDataServer.cpp >--- src-native-new/src/client/TCPDataServer.cpp 29 Apr 2008 19:19:26 -0000 1.24 >+++ src-native-new/src/client/TCPDataServer.cpp 10 May 2008 19:32:54 -0000 >@@ -576,6 +576,59 @@ > > > >+ >+/** >+ ********************************************************* >+ * >+ * @brief >+ * Given a hostname, get the current host IP address. An array of sockaddr_storages are stored in outResult, and the size >+ * of that array is stored in outNumResults. >+ * @return >+ * the IP address number >+ * >+ *********************************************************/ >+/* >+void TCPDataServer::getIPAddresses(char *hostname, struct sockaddr_storage *** outResult, int *outNumResults) { >+ int RetVal; >+ int i; >+ >+ struct addrinfo Hints, *AddrInfo, *AI; >+ >+ int Family = PF_UNSPEC; // Give us both the IPv4 and IPv6 addresses >+ int SocketType = SOCK_STREAM; // TCP only >+ >+ struct sockaddr_storage ** result; >+ >+ int rc = 0 ; >+ >+ rc = initForSocketCalls(); >+ if(rc != 0) { >+ *outNumResults = 0; >+ } >+ >+ result = (struct sockaddr_storage **)tptp_malloc(sizeof(struct sockaddr_storage *) * 128); >+ >+ memset(&Hints, 0, sizeof (Hints)); >+ Hints.ai_family = Family; >+ Hints.ai_socktype = SocketType; >+ >+ // This was originally in the code, but it prevents lookups of host names, e.g. www.google.com. It only works with numeric hosts. >+ // Hints.ai_flags = AI_NUMERICHOST; >+ >+ RetVal = getaddrinfo(hostname, NULL, &Hints, &AddrInfo); >+ >+ for (i = 0, AI = AddrInfo; AI != NULL; AI = AI->ai_next, i++) { >+ result[i] = cloneSockAddr((struct sockaddr_storage *)AI->ai_addr); >+ } >+ freeaddrinfo(AddrInfo); >+ >+ *outResult = result; >+ *outNumResults = i; >+ >+ return RetVal; >+}*/ >+ >+ > /** > ********************************************************* > * >@@ -586,7 +639,7 @@ > * the IP address number > * > *********************************************************/ >- >+/* > unsigned long TCPDataServer::getLocalIPAddress() { > struct hostent *hpLocal = NULL; > unsigned long result = 0 ; >@@ -595,7 +648,7 @@ > rc = initForSocketCalls() ; > if (rc == 0) > { >- hpLocal = getHostInfo() ; >+ hpLocal = getHostInfoIPv4M() ; > > if (hpLocal != NULL) > memcpy(&result, hpLocal->h_addr_list[0], sizeof(long)); >@@ -605,8 +658,9 @@ > > return result; > } >+*/ > >- >+#define MAX_HOST_NAME_LENGTH 128 > > void TCPDataServer::connect() > { >@@ -614,9 +668,17 @@ > char buffer[1024] ; > int bufferLength = 1024 ; > int bytesRead = 0 ; >+ >+ char hostname[MAX_HOST_NAME_LENGTH]; >+ >+ // Get the local host informantion >+ if (gethostname(hostname,MAX_HOST_NAME_LENGTH) < 0) { >+ TPTP_LOG_DEBUG_MSG("Error: Unable to resolve local host name."); >+ return; >+ } > > /* go make connection */ >- rc = connectToTCPServer(getLocalIPAddress(), _port, &_sock) ; >+ rc = connectToTCPServer(hostname, _port, &_sock) ; > > if (rc != 0) > { >Index: src-native-new/src/client/ConnectionImpl.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/client/ConnectionImpl.h,v >retrieving revision 1.15 >diff -u -r1.15 ConnectionImpl.h >--- src-native-new/src/client/ConnectionImpl.h 1 Apr 2006 01:05:31 -0000 1.15 >+++ src-native-new/src/client/ConnectionImpl.h 10 May 2008 19:32:54 -0000 >@@ -72,7 +72,8 @@ > > void init(); > unsigned long getLocalIPAddress(); >- unsigned long getIPAddress(char* hostname); >+ void getIPAddresses(char *hostname, struct sockaddr_storage *** outResult, int *outNumResults); >+ unsigned long getIPAddressIPv4(char* hostname); > int sendControlCommand(SOCKET sockconn, int commandflags); > int sendCONNECT_DATACommand(SOCKET datasock, int direction, int commandflags); > int processControlMessage(char buffer[], int length); >Index: src-native-new/src/client/ConnectionImpl.cpp >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/client/ConnectionImpl.cpp,v >retrieving revision 1.30 >diff -u -r1.30 ConnectionImpl.cpp >--- src-native-new/src/client/ConnectionImpl.cpp 29 Apr 2008 19:19:26 -0000 1.30 >+++ src-native-new/src/client/ConnectionImpl.cpp 10 May 2008 19:32:54 -0000 >@@ -32,7 +32,9 @@ > using namespace std; > using namespace TPTP::Client; > >- >+#ifdef _WIN32 >+ #include <Ws2tcpip.h> >+#endif > > ConnectionImpl::ConnectionImpl() > { >@@ -219,8 +221,8 @@ > * @return > * the IP address number > * >+ * IPV4-ONLY > *********************************************************/ >- > unsigned long ConnectionImpl::getLocalIPAddress() { > struct hostent *hpLocal = NULL; > unsigned long result = 0 ; >@@ -229,7 +231,7 @@ > rc = initForSocketCalls() ; > if (rc == 0) > { >- hpLocal = getHostInfo() ; >+ hpLocal = getHostInfoIPv4M() ; // TODO replace with portable impl > > if (hpLocal != NULL) > memcpy(&result, hpLocal->h_addr_list[0], sizeof(long)); >@@ -245,14 +247,61 @@ > ********************************************************* > * > * @brief >- * get the current host IP address >- * >+ * Given a hostname, get the current host IP address. An array of sockaddr_storages are stored in outResult, and the size >+ * of that array is stored in outNumResults. > * @return > * the IP address number > * > *********************************************************/ >+void ConnectionImpl::getIPAddresses(char *hostname, struct sockaddr_storage *** outResult, int *outNumResults) { >+ int RetVal; >+ int i; >+ >+ struct addrinfo Hints, *AddrInfo, *AI; >+ >+ int Family = PF_UNSPEC; // Give us both the IPv4 and IPv6 addresses >+ int SocketType = SOCK_STREAM; // TCP only >+ >+ struct sockaddr_storage ** result; >+ >+ int rc = 0 ; >+ >+ rc = initForSocketCalls(); >+ if(rc != 0) { >+ *outNumResults = 0; >+ } >+ >+ result = (struct sockaddr_storage **)tptp_malloc(sizeof(struct sockaddr_storage *) * 128); >+ >+ memset(&Hints, 0, sizeof (Hints)); >+ Hints.ai_family = Family; >+ Hints.ai_socktype = SocketType; >+ >+ // This was originally in the code, but it prevents lookups of host names, e.g. www.google.com. It only works with numeric hosts. >+ // Hints.ai_flags = AI_NUMERICHOST; >+ >+ RetVal = getaddrinfo(hostname, NULL, &Hints, &AddrInfo); > >-unsigned long ConnectionImpl::getIPAddress(char* hostname) { >+ for (i = 0, AI = AddrInfo; AI != NULL; AI = AI->ai_next, i++) { >+ result[i] = cloneSockAddr((struct sockaddr_storage *)AI->ai_addr); >+ } >+ freeaddrinfo(AddrInfo); >+ >+ if(i == 0) { >+ tptp_free(result); >+ result = NULL; >+ } >+ >+ *outResult = result; >+ *outNumResults = i; >+ >+} >+ >+ >+ >+ >+ >+unsigned long ConnectionImpl::getIPAddressIPv4(char* hostname) { > struct hostent *hpHost = NULL; > unsigned long result = 0 ; > int rc = 0 ; >@@ -260,7 +309,7 @@ > rc = initForSocketCalls() ; > if (rc == 0) > { >- hpHost = getTargetHostInfo(hostname) ; >+ hpHost = getTargetHostInfoIPv4M(hostname) ; > > if (hpHost != NULL) > memcpy(&result, hpHost->h_addr_list[0], sizeof(long)); >@@ -270,7 +319,6 @@ > } > > >- > int ConnectionImpl::connect(INode* node, int port) > { > int rc = 0; >@@ -279,7 +327,9 @@ > _port = port; > /* go make connection */ > init(); >- rc = connectToTCPServer(getIPAddress(_node->getName()), port, &sock) ; >+ >+ >+ rc = connectToTCPServer(_node->getName(), port, &sock) ; > > if (rc != 0) > { >@@ -307,7 +357,7 @@ > _port = connInfo->getPortNum(); > /* go make connection */ > init(); >- rc = connectToTCPServer(getIPAddress(connInfo->getHostName()), _port, &sock) ; >+ rc = connectToTCPServer(connInfo->getHostName(), _port, &sock) ; > > if (rc != 0) > { >@@ -513,7 +563,7 @@ > SOCKET datasock = 0; > int dataConnectionId; > >- rc = connectToTCPServer(getIPAddress(this->_node->getName()), _port, &datasock) ; >+ rc = connectToTCPServer(this->_node->getName(), _port, &datasock) ; > > if (rc != 0) > { >Index: src-native-new/src/client/TPTP_INetAddress.cpp >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/client/TPTP_INetAddress.cpp,v >retrieving revision 1.5 >diff -u -r1.5 TPTP_INetAddress.cpp >--- src-native-new/src/client/TPTP_INetAddress.cpp 12 Sep 2005 18:01:40 -0000 1.5 >+++ src-native-new/src/client/TPTP_INetAddress.cpp 10 May 2008 19:32:54 -0000 >@@ -21,6 +21,7 @@ > > #ifdef _WIN32 > >+/* IPV4-ONLY */ > int TPTP_INetAddress::getAddress(char* hostname,char** inetaddr) > { > hostent* remote_hostname; >@@ -28,7 +29,7 @@ > WSAData wsaData; > WSACleanup(); > >- if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) >+ if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) > { > return -1; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 165409
:
80048
|
91219
|
91220
|
92067
|
96037
|
96378
|
96379
|
99618
| 99619 |
99622
|
99735