Browse Source

Windows code cleanup: WSAStartup() -> init_winsock()

pull/41/head
Bram Matthys 11 months ago
parent
commit
c02eb3f16c
No known key found for this signature in database
GPG Key ID: BF8116B163EAAE98
  1. 3
      include/h.h
  2. 7
      src/ircd.c
  3. 13
      src/socket.c
  4. 5
      src/unrealircdctl.c
  5. 8
      src/windows/gui.c
  6. 9
      src/windows/service.c

3
include/h.h

@ -948,6 +948,9 @@ extern int unreal_bind(int fd, const char *ip, int port, SocketType socket_type)
extern int unreal_connect(int fd, const char *ip, int port, int ipv6);
extern int is_valid_ip(const char *str);
extern int ipv6_capable(void);
#ifdef _WIN32
extern void init_winsock(void);
#endif
extern MODVAR Client *remote_rehash_client;
extern MODVAR int debugfd;
extern void convert_to_absolute_path(char **path, const char *reldir);

7
src/ircd.c

@ -500,10 +500,7 @@ int main(int argc, char *argv[])
int InitUnrealIRCd(int argc, char *argv[])
#endif
{
#ifdef _WIN32
WORD wVersionRequested = MAKEWORD(1, 1);
WSADATA wsaData;
#else
#ifndef _WIN32
uid_t uid, euid;
gid_t gid, egid;
#endif
@ -573,7 +570,7 @@ int InitUnrealIRCd(int argc, char *argv[])
#ifndef _WIN32
(void)umask(077); /* better safe than sorry --SRB */
#else
WSAStartup(wVersionRequested, &wsaData);
init_winsock();
#endif
setup_signals();

13
src/socket.c

@ -1365,3 +1365,16 @@ int unreal_bind(int fd, const char *ip, int port, SocketType socket_type)
return ret;
}
}
#ifdef _WIN32
void init_winsock(void)
{
WSADATA WSAData;
if (WSAStartup(MAKEWORD(1, 1), &WSAData) != 0)
{
MessageBox(NULL, "Unable to initialize WinSock", "UnrealIRCD Initalization Error", MB_OK);
fprintf(stderr, "Unable to initialize WinSock\n");
exit(1);
}
}
#endif

5
src/unrealircdctl.c

@ -73,9 +73,10 @@ void unrealircdctl_status(void)
int main(int argc, char *argv[])
{
WSADATA wsaData;
WSAStartup(MAKEWORD(1,1), &wsaData);
dbuf_init();
#ifdef _WIN32
init_winsock();
#endif
if (argc == 1)
unrealircdctl_usage(argv[0]);

8
src/windows/gui.c

@ -188,7 +188,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
MSG msg;
unsigned char *s;
HWND hWnd;
WSADATA WSAData;
HICON hIcon;
SC_HANDLE hService, hSCManager;
SERVICE_TABLE_ENTRY DispatchTable[] =
@ -250,12 +249,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
if (!LoadLibrary("riched20.dll"))
LoadLibrary("riched32.dll");
InitDebug();
if (WSAStartup(MAKEWORD(1, 1), &WSAData) != 0)
{
MessageBox(NULL, "Unable to initialize WinSock", "UnrealIRCD Initalization Error", MB_OK);
return FALSE;
}
init_winsock();
hInst = hInstance;
MainDlgBackground = CreateSolidBrush(RGB(75, 134, 238)); /* Background of main dialog */

9
src/windows/service.c

@ -90,7 +90,6 @@ VOID WINAPI IRCDCtrlHandler(DWORD opcode)
*/
VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv)
{
WSADATA WSAData;
DWORD error = 0;
char path[MAX_PATH], *folder;
@ -121,13 +120,7 @@ VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv)
GetOSName(OSName);
InitDebug();
/* Initialize Winsocks */
if ((error = WSAStartup(MAKEWORD(1, 1), &WSAData)) != 0)
{
SetServiceStop(error);
return;
}
init_winsock();
/* Initialize the IRCd */
if ((error = InitUnrealIRCd(dwArgc, lpszArgv)) != 1)

Loading…
Cancel
Save