Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Development

Archive::Development Archive area for Development's posts that were moved here after an inactivity period of 90 days.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 02-01-2002, 06:07 AM
alkrun
Sarnak
 
Join Date: Jan 2002
Posts: 66
Default

console.cpp

Code:
bool InitTCP()
{
	struct sockaddr_in address;
	int reuse_addr = 1;
	unsigned long nonblocking = 1;
	struct hostent *phostent = NULL;

#ifdef WIN32
	WORD version = MAKEWORD (1,1);
	WSADATA wsadata;
	WSAStartup (version, &wsadata);
#endif

  /* Setup internet address information.  
     This is used with the bind() call */
	unsigned long lAddr = INADDR_NONE;

	memset((char *) &address, 0, sizeof(address));
	address.sin_family = AF_INET;
	address.sin_port = htons(PORT);
	address.sin_addr.s_addr = htonl(INADDR_ANY);

	//GET WORLD SERVER ADDRESS
	if((lAddr = inet_addr(net.GetWorldAddress())) != INADDR_NONE){
		if((phostent = gethostbyaddr((char*)&lAddr, sizeof(unsigned long), AF_INET)) != NULL){
			memcpy ((char*)&(address.sin_addr), phostent->h_addr, phostent->h_length);
		}
	}else if((phostent = gethostbyname(net.GetWorldAddress())) != NULL){
		memcpy ((char*)&(address.sin_addr), phostent->h_addr, phostent->h_length);
	}

	/* Setting up TCP port for new TCP connections */
	listening_socketTCP = socket(AF_INET, SOCK_STREAM, 0);
	if (listening_socketTCP == INVALID_SOCKET) 
 	{
		return false;
	}

// dont think following is good stuff for TCP, good for UDP
//	setsockopt(listening_socketTCP, SOL_SOCKET, SO_REUSEADDR, (char *) &reuse_addr, sizeof(reuse_addr));

	if (bind(listening_socketTCP, (struct sockaddr *) &address, sizeof(address)) < 0) 
	{
#ifdef WIN32
		cout << "Listening TCP socket failed(bind). Error: " << WSAGetLastError() << endl;
		closesocket(listening_socketTCP);
#else
		cout << "Listening TCP socket failed(bind). Error: " << strerror(errno) << endl;
		close(listening_socketTCP);
#endif
		return false;
	}

#ifdef WIN32
	ioctlsocket (listening_socketTCP, FIONBIO, &nonblocking);
#else
	fcntl(listening_socketTCP, F_SETFL, O_NONBLOCK);
#endif

	if (listen (listening_socketTCP, SOMAXCONN) == SOCKET_ERROR) 
	{
#ifdef WIN32
		cout << "Listening TCP socket failed. Error: " << WSAGetLastError() << endl;
                closesocket (listening_socketTCP);
#else
		cout << "Listening TCP socket failed. Error: " << strerror(errno) << endl;
                close(listening_socketTCP);
#endif
		return false;
	}else{
		char szBuf[128];
		u_char *pAddr = &address.sin_addr.S_un.S_un_b.s_b1;
		sprintf(szBuf, "World Server listening on address:%u.%u.%u.%u port:%u",
			pAddr[0], pAddr[1], pAddr[2], pAddr[3], PORT);
		cout << szBuf << endl;
	}

	return true;
}
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 10:37 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3