toolsandutils/wintunnel/testcode/server/CTcpServer.cpp
branchRCL_3
changeset 1 d4b442d23379
parent 0 83f4b4db085c
child 2 99082257a271
equal deleted inserted replaced
0:83f4b4db085c 1:d4b442d23379
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     7 //
     8 // Initial Contributors:
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
   108 /***************************************************************************************
   108 /***************************************************************************************
   109  *
   109  *
   110  * SECTION: PRIVATE METHODS
   110  * SECTION: PRIVATE METHODS
   111  *
   111  *
   112  **************************************************************************************/
   112  **************************************************************************************/
   113 //
   113 ////////////////////////////////////////////////////////////////////////
   114 //	Method binds the sock to the address. 
   114 //	Method binds the sock to the address. 
   115 //
   115 ////////////////////////////////////////////////////////////////////////
   116 int CTcpServer::connect(SOCKET &aSocket, SOCKADDR_IN &aAddr)
   116 int CTcpServer::connect(SOCKET &aSocket, SOCKADDR_IN &aAddr)
   117 {
   117 {
   118 	int err;
   118 	int err;
   119 	
   119 	
   120 	//Bind the local address with a socket, so it listens to that port.
   120 	//Bind the local address with a socket, so it listens to that port.
   127 	}
   127 	}
   128 
   128 
   129 	return ITS_OK;
   129 	return ITS_OK;
   130 }
   130 }
   131 
   131 
   132 //
   132 ////////////////////////////////////////////////////////////////////////
   133 //  Disoconnect
   133 //  Disoconnect
   134 //
   134 ////////////////////////////////////////////////////////////////////////
   135 int CTcpServer::disconnect()
   135 int CTcpServer::disconnect()
   136 {
   136 {
   137 	shutdown(iLocal_Sock, SD_SEND);
   137 	shutdown(iLocal_Sock, SD_SEND);
   138 	shutdown(iLocal_Sock, SD_RECEIVE);
   138 	shutdown(iLocal_Sock, SD_RECEIVE);
   139 
   139 
   143 		return E_SOCKETCLOSE;
   143 		return E_SOCKETCLOSE;
   144 
   144 
   145 	return ITS_OK;
   145 	return ITS_OK;
   146 }
   146 }
   147 
   147 
   148 //
   148 ////////////////////////////////////////////////////////////////////////
   149 // Method to check if we have IP adress or hostname, and return IP address
   149 // Method to check if we have IP adress or hostname, and return IP address
   150 //
   150 ////////////////////////////////////////////////////////////////////////
   151 SOCKADDR_IN CTcpServer::getSockAddr( const char* aIp, const char* aPort)
   151 SOCKADDR_IN CTcpServer::getSockAddr( const char* aIp, const char* aPort)
   152 {
   152 {
   153 	SOCKADDR_IN sockAddr;
   153 	SOCKADDR_IN sockAddr;
   154 
   154 
   155 	// check params
   155 	// check params
   166 	sockAddr.sin_addr.S_un.S_addr = inet_addr( aIp );
   166 	sockAddr.sin_addr.S_un.S_addr = inet_addr( aIp );
   167 	return sockAddr;
   167 	return sockAddr;
   168 }
   168 }
   169 
   169 
   170 
   170 
   171 //
   171 ////////////////////////////////////////////////////////////////////////
   172 // Method to check if the adress is IP format or is a hostname string.
   172 // Method to check if the adress is IP format or is a hostname string.
   173 //
   173 ////////////////////////////////////////////////////////////////////////
   174 bool CTcpServer::isIPAdress(const char* aAddr)
   174 bool CTcpServer::isIPAdress(const char* aAddr)
   175 {
   175 {
   176 	int c =0;
   176 	int c =0;
   177 
   177 
   178 	char* q=(char *)aAddr;
   178 	char* q=(char *)aAddr;
   188 		return true; //We have IP adrress, nothing to do
   188 		return true; //We have IP adrress, nothing to do
   189 	else 
   189 	else 
   190 		return false;
   190 		return false;
   191 }
   191 }
   192 
   192 
   193 //
   193 ////////////////////////////////////////////////////////////////////////
   194 // Makes a connection, listens, and prints any incoming data.
   194 // Makes a connection, listens, and prints any incoming data.
   195 //
   195 ////////////////////////////////////////////////////////////////////////
   196 int CTcpServer::makeConnection(SOCKET &aLocalSocket, SOCKET &aRemoteSocket, SOCKADDR_IN & aRemoteAddr)
   196 int CTcpServer::makeConnection(SOCKET &aLocalSocket, SOCKET &aRemoteSocket, SOCKADDR_IN & aRemoteAddr)
   197 {
   197 {
   198 	int remote_addr_len;
   198 	int remote_addr_len;
   199 
   199 
   200 	int err = listen( aLocalSocket, 1 );
   200 	int err = listen( aLocalSocket, 1 );
   244 			closesocket(aRemoteSocket);
   244 			closesocket(aRemoteSocket);
   245 	}
   245 	}
   246 	return ITS_OK;
   246 	return ITS_OK;
   247 }
   247 }
   248 
   248 
   249 //
   249 ////////////////////////////////////////////////////////////////////////
   250 // Returns a a TCP/IP socket
   250 // Returns a a TCP/IP socket
   251 //
   251 ////////////////////////////////////////////////////////////////////////
   252 SOCKET CTcpServer::getSocket()
   252 SOCKET CTcpServer::getSocket()
   253 {
   253 {
   254 	SOCKET sock;
   254 	SOCKET sock;
   255 	int err;
   255 	int err;
   256 
   256 
   264 		return NULL;
   264 		return NULL;
   265 	}
   265 	}
   266 	return sock;
   266 	return sock;
   267 }
   267 }
   268 
   268 
   269 //
   269 ////////////////////////////////////////////////////////////////////////
   270 // Initialise use of the dll.
   270 // Initialise use of the dll.
   271 //
   271 ////////////////////////////////////////////////////////////////////////
   272 int CTcpServer::initialise()
   272 int CTcpServer::initialise()
   273 {
   273 {
   274 	WORD version;
   274 	WORD version;
   275 	WSADATA wsaData;
   275 	WSADATA wsaData;
   276 
   276 
   281 
   281 
   282 	return ITS_OK;		
   282 	return ITS_OK;		
   283 }
   283 }
   284 
   284 
   285 
   285 
   286 //
   286 ////////////////////////////////////////////////////////////////////////
   287 // Release.
   287 // Release.
   288 //
   288 ////////////////////////////////////////////////////////////////////////
   289 int CTcpServer::release()
   289 int CTcpServer::release()
   290 {
   290 {
   291 	int err =WSACleanup();
   291 	int err =WSACleanup();
   292 
   292 
   293 	if ( err == SOCKET_ERROR)
   293 	if ( err == SOCKET_ERROR)
   294 		return E_SOCKETSHUTDOWN;
   294 		return E_SOCKETSHUTDOWN;
   295 
   295 
   296 	return ITS_OK;
   296 	return ITS_OK;
   297 }
   297 }
   298 
   298 
   299 //
   299 ////////////////////////////////////////////////////////////////////////
   300 // Set the arguments
   300 // Set the arguments
   301 //
   301 ////////////////////////////////////////////////////////////////////////
   302 int CTcpServer::setArguments(char* li, char* lp)
   302 int CTcpServer::setArguments(char* li, char* lp)
   303 {
   303 {
   304 	if(!lp)
   304 	if(!lp)
   305 	{
   305 	{
   306 		printf("Error: Missing argument - lp argument required.\n");
   306 		printf("Error: Missing argument - lp argument required.\n");