X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=blobdiff_plain;f=src%2FClientSocket.c;h=f4288f291ec6360aa1e0b532aad62746de386eab;hp=62e367d7b9ce9ca4d21458211348aed287b675e9;hb=8942135758dbad0f07add7c1e2567867d4f53d6b;hpb=0f1dc61921eef1db8e404a5a82372e2d1cd55daa diff --git a/src/ClientSocket.c b/src/ClientSocket.c index 62e367d..f4288f2 100644 --- a/src/ClientSocket.c +++ b/src/ClientSocket.c @@ -48,6 +48,59 @@ struct ClientSocket* create_socket(char *host, int port, char *pass, struct User return client; } +#ifdef WIN32 + +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; + client->connection_time = time(0); + + //send the IRC Headers + char sendBuf[512]; + int len; + + if(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->user->ident, client->user->realname); + write_socket(client, sendBuf, len); + len = sprintf(sendBuf, "NICK %s\n", client->user->nick); + write_socket(client, sendBuf, len); + + return 1; +} + +#else + int connect_socket(struct ClientSocket *client) { if((client->flags & SOCKET_FLAG_CONNECTED)) return 1; struct hostent *host; @@ -58,7 +111,7 @@ int connect_socket(struct ClientSocket *client) { host = gethostbyname(client->host); if (!host) { - herror("gethostbyname() failed"); + perror("gethostbyname() failed"); return 0; } addr.sin_addr = *(struct in_addr*)host->h_addr; @@ -99,6 +152,8 @@ int connect_socket(struct ClientSocket *client) { return 1; } +#endif + int close_socket(struct ClientSocket *client) { if(client == NULL) return 0; if((client->flags & SOCKET_FLAG_CONNECTED))