fixed WIN32 compatibility (use old connect function without IPv6 and bind support)
authorpk910 <philipp@zoelle1.de>
Sun, 11 Dec 2011 06:34:07 +0000 (07:34 +0100)
committerpk910 <philipp@zoelle1.de>
Sun, 11 Dec 2011 06:34:07 +0000 (07:34 +0100)
src/ClientSocket.c
src/cmd_neonserv_extscript.c

index 5fa795e30c028887bfdc7fdb3a4389c3b90f8e52..db93f9a114236a64b6dc444c66a670ceb058a433 100644 (file)
@@ -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;
index 67374d15668560da89f828ff930925c1f8ac990c..8c31bb29d5f258dc57a21ae35e6c097895f54f3d 100644 (file)
@@ -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);
 }