// initialize everything, if the socket isn't open. static bool wsa_init() { if (wsa_socket != INVALID_SOCKET) return true; int r; WSADATA wd; BOOL bc=true; if (0 != WSAStartup(0x101, &wd)) goto error; wsa_socket=socket(PF_INET, SOCK_DGRAM, 0); if (wsa_socket == INVALID_SOCKET) goto error; r=setsockopt(wsa_socket, SOL_SOCKET, SO_BROADCAST, (char*)&bc, sizeof(bc)); if (r!=0) goto error; if (wsa_bind(9998)) return true; // bind to default port. error: if (wsa_socket != INVALID_SOCKET) closesocket(wsa_socket); #ifdef DEBUG OutputDebugString(TEXT("nclog: TCP/IP Problem")); #endif return false; }
// initialize everything, if the socket isn't open. static bool wsa_init() { if (wsa_socket != INVALID_SOCKET) return true; int r; WSADATA wd; BOOL bc=true; if (0 != WSAStartup(0x101, &wd)) { MessageBox(0, L"WSAStartup failed", L"ERROR", 0); goto error; } wsa_socket=socket(PF_INET, SOCK_DGRAM, 0); if (wsa_socket == INVALID_SOCKET) { MessageBox(0, L"socket failed", L"ERROR", 0); goto error; } r=setsockopt(wsa_socket, SOL_SOCKET, SO_BROADCAST, (char*)&bc, sizeof(bc)); if (r!=0) { MessageBox(0, L"setsockopt failed", L"ERROR", 0); goto error; } if (wsa_bind(9998)) return true; // bind to default port. MessageBox(0, L"Can Not Bind To Port", L"ERROR", 0); error: if (wsa_socket != INVALID_SOCKET) closesocket(wsa_socket); return false; }
// can be called externally to select a different port for operations bool set_nclog_port(unsigned short x) { return wsa_bind(x); }