From e97252314899373d0e5ff6236a518a5bbf4a7bcb Mon Sep 17 00:00:00 2001 From: pk910 Date: Sun, 11 Dec 2011 07:34:07 +0100 Subject: [PATCH] fixed WIN32 compatibility (use old connect function without IPv6 and bind support) --- src/ClientSocket.c | 57 ++++++++++++++++++++++++++++++++++++ src/cmd_neonserv_extscript.c | 2 ++ 2 files changed, 59 insertions(+) diff --git a/src/ClientSocket.c b/src/ClientSocket.c index 5fa795e..db93f9a 100644 --- a/src/ClientSocket.c +++ b/src/ClientSocket.c @@ -77,6 +77,7 @@ struct ClientSocket* create_socket(char *host, int port, char *bindto, char *pas return client; } +#ifndef WIN32 int connect_socket(struct ClientSocket *client) { if((client->flags & SOCKET_FLAG_CONNECTED)) return 1; int sock; @@ -201,6 +202,62 @@ int connect_socket(struct ClientSocket *client) { return 1; } +#else +int connect_socket(struct ClientSocket *client) { + if((client->flags & SOCKET_FLAG_CONNECTED)) return 1; + struct hostent *host; + struct sockaddr_in addr; + int sock; + addr.sin_addr.s_addr = inet_addr(client->host); + if (addr.sin_addr.s_addr == INADDR_NONE) { + host = gethostbyname(client->host); + if(!host) { + return SOCKET_ERROR; + } + memcpy(&(addr.sin_addr), host->h_addr_list[0], 4); + } + sock = socket(PF_INET, SOCK_STREAM, 0); + if (sock == -1) + { + perror("socket() failed"); + return 0; + } + + addr.sin_port = htons(client->port); + addr.sin_family = AF_INET; + + if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) + { + perror("connect() failed"); + return 0; + } + + client->sock = sock; + client->flags |= SOCKET_FLAG_CONNECTED | SOCKET_FLAG_RECONNECT; + client->connection_time = time(0); + + + if(client->flags & SOCKET_FLAG_SSL) { + ssl_connect(client); + } + + + //send the IRC Headers + char sendBuf[512]; + int len; + + if(client->pass && strcmp(client->pass, "")) { + len = sprintf(sendBuf, "PASS :%s\n", client->pass); + write_socket(client, sendBuf, len); + } + len = sprintf(sendBuf, "USER %s 0 0 :%s\n", client->ident, client->realname); + write_socket(client, sendBuf, len); + len = sprintf(sendBuf, "NICK %s\n", client->nick); + write_socket(client, sendBuf, len); + + return 1; +} +#endif int close_socket(struct ClientSocket *client) { if(client == NULL) return 0; diff --git a/src/cmd_neonserv_extscript.c b/src/cmd_neonserv_extscript.c index 67374d1..8c31bb2 100644 --- a/src/cmd_neonserv_extscript.c +++ b/src/cmd_neonserv_extscript.c @@ -134,7 +134,9 @@ CMD_BIND(neonserv_cmd_extscript) { cache->chan = chan; cache->answere_channel = answere_channel; cache->pipe = popen(command, "r"); + #ifndef WIN32 fcntl(fileno(cache->pipe), F_SETFL, O_NONBLOCK); + #endif timeq_add(1, neonserv_cmd_extscript_callback, cache); } -- 2.20.1