- logFile = fopen(pLogName, "a+");
- bLogToSock = (servAddr && logPort && (serverlevel>=0));
- if(bLogToSock)
- initlogSocket(servAddr, logPort);
-}
-
-static void initlogSocket(char* servAddr, char* logPort)
-{
-#ifndef __NT__
- bLogToSock = 0;
-#else
- // init winsock
- // check and prepare WinSock DLL
- WORD wVersionRequested = MAKEWORD( 2, 2 );
- WSADATA wsaData;
- if ( WSAStartup(wVersionRequested, &wsaData) != 0 )
- {
- bLogToSock = false;
- return;
- }
- // Confirm that the WinSock DLL supports 2.2.
- // Note that if the DLL supports versions greater
- // than 2.2 in addition to 2.2, it will still return
- // 2.2 in wVersion since that is the version we
- // requested.
-
- if ( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 )
- {
- bLogToSock = false;
- return;
- }
-
- struct hostent *hp;
- hp = gethostbyname(servAddr);
- if (hp == NULL) // we don't know who this host is
- {
- bLogToSock = false;
- return;
- }
-
- // connect socket
- sockaddr_in SocketAddress;
-
- memset(&SocketAddress, 0, sizeof(SocketAddress));
- memcpy((char*)&SocketAddress.sin_addr, hp->h_addr, hp->h_length); // set address
- SocketAddress.sin_family = hp->h_addrtype;
- SocketAddress.sin_port = htons((u_short)atoi(logPort));
-
- logSocket = socket(hp->h_addrtype, SOCK_STREAM, 0);
- if (logSocket == INVALID_SOCKET)
- {
- bLogToSock = false;
- return;
- }
-
- // try to connect to the specified socket
- if ( connect(logSocket, (struct sockaddr*)&SocketAddress, sizeof (SocketAddress)) == SOCKET_ERROR) {
- bLogToSock = false;
- return;
- }
- bLogToSock = true;
-#endif