diff --git a/Makefile b/Makefile index 25f2416..527c277 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ SRC_FILES := changes.txt license.txt Makefile mkstubs.pl readme.txt src/config.h src/common.h src/router.c src/router.h include/dplay.h include/dplaysp.h include/dplobby.h \ include/wsnwlink.h -all: ipxwrapper.dll wsock32.dll mswsock.dll ipxconfig.exe dpwsockx.dll +all: ipxwrapper.dll wsock32.dll mswsock.dll ipxconfig.exe dpwsockx.dll ipxrouter.exe clean: rm -f ipxwrapper.dll wsock32.dll mswsock.dll ipxconfig.exe dpwsockx.dll @@ -57,6 +57,9 @@ ipxconfig.exe: src/ipxconfig.cpp dpwsockx.dll: src/directplay.o src/log.o src/dpwsockx_stubs.o src/common.o ipxwrapper.dll $(CC) $(CFLAGS) -Wl,--enable-stdcall-fixup,-s -shared -o dpwsockx.dll src/directplay.o src/log.o src/common.o src/dpwsockx_stubs.o src/dpwsockx.def -L. -lipxwrapper -lwsock32 +ipxrouter.exe: src/router-exe.o src/router.o src/interface.o src/common.o + $(CC) $(CFLAGS) -static-libgcc -g -o ipxrouter.exe $^ -lws2_32 -liphlpapi + src/ipxwrapper_stubs.s: src/ipxwrapper_stubs.txt perl mkstubs.pl src/ipxwrapper_stubs.txt src/ipxwrapper_stubs.s diff --git a/src/router-exe.c b/src/router-exe.c new file mode 100644 index 0000000..1842f01 --- /dev/null +++ b/src/router-exe.c @@ -0,0 +1,72 @@ +/* ipxwrapper - Standalone router executable + * Copyright (C) 2011 Daniel Collins + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include + +#include "router.h" +#include "common.h" +#include "config.h" + +struct reg_global global_conf; + +int main(int argc, char **argv) { + reg_open(KEY_QUERY_VALUE); + + if(reg_get_bin("global", &global_conf, sizeof(global_conf)) != sizeof(global_conf)) { + global_conf.udp_port = DEFAULT_PORT; + global_conf.w95_bug = 1; + global_conf.bcast_all = 0; + global_conf.filter = 1; + } + + reg_close(); + + WSADATA wsdata; + int err = WSAStartup(MAKEWORD(1,1), &wsdata); + + if(err) { + log_printf("Failed to initialize winsock: %s", w32_error(err)); + }else{ + struct router_vars *router = router_init(TRUE); + + if(router) { + FreeConsole(); + router_main(router); + router_destroy(router); + } + + WSACleanup(); + } + + system("pause"); + + return 0; +} + +void log_printf(const char *fmt, ...) { + va_list argv; + + va_start(argv, fmt); + + AllocConsole(); + + vfprintf(stderr, fmt, argv); + fputc('\n', stderr); + + va_end(argv); +} diff --git a/src/router.c b/src/router.c index 600288b..1a858c6 100644 --- a/src/router.c +++ b/src/router.c @@ -162,7 +162,7 @@ DWORD router_main(void *arg) { struct sockaddr_in addr; int addrlen = sizeof(addr); - int len = r_recvfrom(router->udp_sock, router->recvbuf, PACKET_BUF_SIZE, 0, (struct sockaddr*)&addr, &addrlen); + int len = recvfrom(router->udp_sock, router->recvbuf, PACKET_BUF_SIZE, 0, (struct sockaddr*)&addr, &addrlen); if(len == -1) { if(WSAGetLastError() == WSAEWOULDBLOCK || WSAGetLastError() == WSAECONNRESET) { continue; @@ -226,7 +226,7 @@ DWORD router_main(void *arg) { addr.sin_addr.s_addr = inet_addr("127.0.0.1"); addr.sin_port = ra->local_port; - if(r_sendto(router->udp_sock, (char*)packet, len, 0, (struct sockaddr*)&addr, sizeof(addr)) == -1) { + if(sendto(router->udp_sock, (char*)packet, len, 0, (struct sockaddr*)&addr, sizeof(addr)) == -1) { log_printf("Error relaying packet: %s", w32_error(WSAGetLastError())); } }