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;
host = gethostbyname(client->host);
if (!host)
{
- herror("gethostbyname() failed");
+ perror("gethostbyname() failed");
return 0;
}
addr.sin_addr = *(struct in_addr*)host->h_addr;
return 1;
}
+#endif
+
int close_socket(struct ClientSocket *client) {
if(client == NULL) return 0;
if((client->flags & SOCKET_FLAG_CONNECTED))