mirror of
https://github.com/solemnwarning/ipxwrapper
synced 2024-12-30 16:45:37 +01:00
Bugfix: Setup socket for sending packets with new router code properly.
This commit is contained in:
parent
8e06150325
commit
f1a6cf40a2
@ -40,7 +40,7 @@
|
||||
ipx_socket *sockets = NULL;
|
||||
struct ipx_interface *nics = NULL;
|
||||
ipx_host *hosts = NULL;
|
||||
SOCKET net_fd = -1;
|
||||
SOCKET send_fd = -1;
|
||||
struct reg_global global_conf;
|
||||
|
||||
HMODULE winsock2_dll = NULL;
|
||||
@ -106,7 +106,34 @@ BOOL WINAPI DllMain(HINSTANCE me, DWORD why, LPVOID res) {
|
||||
if(!rclient_start(&g_rclient)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(g_rclient.router) {
|
||||
send_fd = g_rclient.router->udp_sock;
|
||||
}else{
|
||||
/* Create UDP socket for sending packets if not using a private router */
|
||||
|
||||
if((send_fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||
log_printf("Failed to create UDP socket: %s", w32_error(WSAGetLastError()));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
struct sockaddr_in addr;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = INADDR_ANY;
|
||||
addr.sin_port = 0;
|
||||
|
||||
if(bind(send_fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
|
||||
log_printf("Failed to bind UDP socket (send_fd): %s", w32_error(WSAGetLastError()));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}else if(why == DLL_PROCESS_DETACH) {
|
||||
if(send_fd != -1 && !g_rclient.router) {
|
||||
closesocket(send_fd);
|
||||
}
|
||||
|
||||
send_fd = -1;
|
||||
|
||||
rclient_stop(&g_rclient);
|
||||
|
||||
WSACleanup();
|
||||
|
@ -101,7 +101,7 @@ struct ipx_host {
|
||||
extern ipx_socket *sockets;
|
||||
extern struct ipx_interface *nics;
|
||||
extern ipx_host *hosts;
|
||||
extern SOCKET net_fd;
|
||||
extern SOCKET send_fd;
|
||||
extern struct reg_global global_conf;
|
||||
extern struct rclient g_rclient;
|
||||
|
||||
|
@ -622,7 +622,7 @@ int WSAAPI sendto(SOCKET fd, const char *buf, int len, int flags, const struct s
|
||||
saddr.sin_port = htons(global_conf.udp_port);
|
||||
saddr.sin_addr.s_addr = (host ? host->ipaddr : (global_conf.bcast_all ? INADDR_BROADCAST : sockptr->nic_bcast));
|
||||
|
||||
int sval = r_sendto(net_fd, (char*)packet, psize, 0, (struct sockaddr*)&saddr, sizeof(saddr));
|
||||
int sval = r_sendto(send_fd, (char*)packet, psize, 0, (struct sockaddr*)&saddr, sizeof(saddr));
|
||||
if(sval == -1) {
|
||||
len = -1;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user