From 8942135758dbad0f07add7c1e2567867d4f53d6b Mon Sep 17 00:00:00 2001 From: pk910 Date: Sun, 2 Oct 2011 03:41:34 +0200 Subject: [PATCH] some modifications for WIN32 support :) --- .gitignore | 22 ++++++++++++++- Makefile.am | 2 +- configure.ac | 16 +++++++---- src/ClientSocket.c | 57 +++++++++++++++++++++++++++++++++++++- src/cmd_neonserv_netinfo.c | 8 +++--- src/main.c | 12 ++++++++ src/main.h | 7 ++++- 7 files changed, 111 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 4e8b61d..66e11f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,22 @@ mysqlConfig.h -src/version.c \ No newline at end of file +src/version.c +src/.deps +src/.dirstamp +src/*.o +autom4te.cache +aclocal.m4 +config.h.in~ +config.h.in +config.h +config.status +config.log +configure +depcomp +install-sh +Makefile.in +Makefile +missing +stamp-h1 +neonserv +neonserv.exe +libmysql.dll \ No newline at end of file diff --git a/Makefile.am b/Makefile.am index 409b9be..a7f3b07 100644 --- a/Makefile.am +++ b/Makefile.am @@ -98,4 +98,4 @@ neonserv_SOURCES = src/version.c \ src/cmd_neonserv_voiceall.c \ src/cmd_neonserv_wipeinfo.c -neonserv_LDADD = $(MYSQL_LIBS) \ No newline at end of file +neonserv_LDADD = $(MYSQL_LIBS) $(WINSOCK_LIBS) \ No newline at end of file diff --git a/configure.ac b/configure.ac index 308d5f4..a464dac 100644 --- a/configure.ac +++ b/configure.ac @@ -11,21 +11,27 @@ AC_PROG_AWK # Checks for libraries. # Get MySQL library and include locations -AC_ARG_WITH([mysql-include-path], - [AS_HELP_STRING([--with-mysql-include-path], +AC_ARG_WITH([mysql], + [AS_HELP_STRING([--with-mysql=DIR], [location of the MySQL headers, defaults to /usr/include/mysql])], [MYSQL_CFLAGS="-I$withval"], [MYSQL_CFLAGS='-I/usr/include/mysql']) AC_SUBST([MYSQL_CFLAGS]) -AC_ARG_WITH([mysql-lib-path], - [AS_HELP_STRING([--with-mysql-lib-path], [location of the MySQL libraries])], +AC_ARG_WITH([mysql-lib], + [AS_HELP_STRING([--with-mysql-lib=DIR], [location of the MySQL libraries])], [MYSQL_LIBS="-L$withval -lmysqlclient"], [MYSQL_LIBS='-lmysqlclient']) AC_SUBST([MYSQL_LIBS]) +AC_ARG_WITH([winsock], + [AS_HELP_STRING([--with-winsock], [use winsock (WIN32 systems)])], + [WINSOCK_LIBS='-lws2_32'], + [WINSOCK_LIBS='']) +AC_SUBST([WINSOCK_LIBS]) + # Checks for header files. -AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h]) +AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h windows.h winsock2.h]) # Checks for typedefs, structures, and compiler characteristics. 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)) diff --git a/src/cmd_neonserv_netinfo.c b/src/cmd_neonserv_netinfo.c index c8fd1b6..e8260d5 100644 --- a/src/cmd_neonserv_netinfo.c +++ b/src/cmd_neonserv_netinfo.c @@ -52,22 +52,22 @@ CMD_BIND(neonserv_cmd_netinfo) { table_add(table, content); content[0] = get_language_string(user, "NS_NETINFO_CHANNEL"); - sprintf(tmp, "%d %.2f kB (%d * %lu B = %.2f kB)", channel_count, channel_memory / 1024, channel_count, sizeof(struct ChanNode), channel_memory / 1024); + sprintf(tmp, "%d %.2f kB (%d * %u B = %.2f kB)", channel_count, channel_memory / 1024, channel_count, (unsigned int) sizeof(struct ChanNode), channel_memory / 1024); content[1] = tmp; table_add(table, content); content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN"); - sprintf(tmp, "%d %.2f kB (%d * %lu B = %.2f kB)", channel_ban_count, channel_ban_memory / 1024, channel_ban_count, sizeof(struct BanNode), channel_ban_memory / 1024); + sprintf(tmp, "%d %.2f kB (%d * %u B = %.2f kB)", channel_ban_count, channel_ban_memory / 1024, channel_ban_count, (unsigned int) sizeof(struct BanNode), channel_ban_memory / 1024); content[1] = tmp; table_add(table, content); content[0] = get_language_string(user, "NS_NETINFO_USER"); - sprintf(tmp, "%d %.2f kB (%d * %lu B = %.2f kB)", user_count, user_memory / 1024, user_count, sizeof(struct UserNode), user_memory / 1024); + sprintf(tmp, "%d %.2f kB (%d * %u B = %.2f kB)", user_count, user_memory / 1024, user_count, (unsigned int) sizeof(struct UserNode), user_memory / 1024); content[1] = tmp; table_add(table, content); content[0] = get_language_string(user, "NS_NETINFO_CHANUSER"); - sprintf(tmp, "%d %.2f kB (%d * %lu B = %.2f kB)", chanuser_count, chanuser_memory / 1024, chanuser_count, sizeof(struct ChanUser), chanuser_memory / 1024); + sprintf(tmp, "%d %.2f kB (%d * %u B = %.2f kB)", chanuser_count, chanuser_memory / 1024, chanuser_count, (unsigned int) sizeof(struct ChanUser), chanuser_memory / 1024); content[1] = tmp; table_add(table, content); diff --git a/src/main.c b/src/main.c index 2fcc3db..0aa1a1b 100644 --- a/src/main.c +++ b/src/main.c @@ -36,6 +36,18 @@ int main(void) { start_time = time(0); + #ifdef WIN32 + int res; + WSADATA wsadata; + // Start Windows Sockets. + res = WSAStartup(MAKEWORD(2, 0), &wsadata); + if (res) + { + perror("Unable to start Windows Sockets"); + return 0; + } + #endif + init_mysql(); init_lang(); init_parser(); diff --git a/src/main.h b/src/main.h index b1452e7..6e73985 100644 --- a/src/main.h +++ b/src/main.h @@ -12,12 +12,17 @@ #include #include #include +#ifdef WIN32 +#include +#include +#else #include #include #include #include -#include #include +#endif +#include #include #include -- 2.20.1