From 505f83172e7298412b8e1a3af2e90312225770c3 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Thu, 29 Aug 2002 08:54:42 +0000 Subject: [PATCH] fixed networking fuck-up? --- NEWS | 1 + arch/linux/Makefile.am | 3 +- arch/linux/ipx_bsd.c | 345 ++++++++++++++++++------------------- arch/linux/ipx_udp.c | 10 +- arch/linux/linuxnet.c | 373 ++++++++++++++++++++++++++++++++++++++--- main/Makefile.am | 3 +- main/inferno.c | 10 +- 7 files changed, 524 insertions(+), 221 deletions(-) diff --git a/NEWS b/NEWS index 571a9c4b..5cecf773 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ - Shareware data files support... Including the ability to play other missions if you have only the mac demo datafiles. - Descent 1 level support! thanks to Martin Schaffner +- Networking fuck-up fixed? --- Version 0.1.3 --- - deb and rpm support added diff --git a/arch/linux/Makefile.am b/arch/linux/Makefile.am index ac6b4ab5..578fd568 100644 --- a/arch/linux/Makefile.am +++ b/arch/linux/Makefile.am @@ -6,8 +6,7 @@ INCLUDES = -I$(top_srcdir)/arch/include -I$(top_srcdir)/include -I$(top_srcdir)/ if USE_NETWORK -NETWORK_SRCS = ipx_bsd.c ipx_kali.c ipx_lin.c linuxnet.c ukali.c -# arch_ip.cpp +NETWORK_SRCS = ipx_bsd.c ipx_kali.c ipx_lin.c ipx_udp.c linuxnet.c endif libarch_linux_a_SOURCES = ${NETWORK_SRCS} findfile.c init.c diff --git a/arch/linux/ipx_bsd.c b/arch/linux/ipx_bsd.c index 383918ef..b2a32f1e 100644 --- a/arch/linux/ipx_bsd.c +++ b/arch/linux/ipx_bsd.c @@ -1,25 +1,15 @@ /* - * $Source: /cvs/cvsroot/d2x/arch/linux/ipx_bsd.c,v $ - * $Revision: 1.4 $ - * $Author: bradleyb $ - * $Date: 2001-10-19 07:39:25 $ * * IPX driver using BSD style sockets * Mostly taken from dosemu * - * $Log: not supported by cvs2svn $ - * Revision 1.3 2001/10/19 07:29:36 bradleyb - * Brought linux networking in line with d1x, moved some arch/linux_* stuff to arch/linux/ - * - * Revision 1.2 2001/01/29 13:35:08 bradleyb - * Fixed build system, minor fixes - * */ #ifdef HAVE_CONFIG_H #include #endif +#include #include #include #include @@ -37,6 +27,7 @@ #include #include +#include "pstypes.h" #include "ipx_drv.h" #include "ipx_bsd.h" @@ -47,211 +38,195 @@ #define leave_priv_setting() #endif -static ipx_socket_t mysock; - -static int ipx_bsd_GetMyAddress( void ) +static int ipx_bsd_GetMyAddress(void) { - int sock; - struct sockaddr_ipx ipxs; - struct sockaddr_ipx ipxs2; - int len; - int i; - - sock=socket(AF_IPX,SOCK_DGRAM,PF_IPX); - if(sock==-1) - { - n_printf("IPX: could not open socket in GetMyAddress\n"); - return(-1); - } - - /* bind this socket to network 0 */ - ipxs.sipx_family=AF_IPX; + int sock; + struct sockaddr_ipx ipxs; + struct sockaddr_ipx ipxs2; + int len; + int i; + + sock=socket(AF_IPX,SOCK_DGRAM,PF_IPX); + if (sock == -1) { + n_printf("IPX: could not open socket in GetMyAddress\n"); + return(-1); + } + + /* bind this socket to network 0 */ + ipxs.sipx_family=AF_IPX; #ifdef IPX_MANUAL_ADDRESS - memcpy(&ipxs.sipx_network, ipx_MyAddress, 4); + memcpy(&ipxs.sipx_network, ipx_MyAddress, 4); #else - ipxs.sipx_network=0; -#endif - ipxs.sipx_port=0; - - if(bind(sock,(struct sockaddr *)&ipxs,sizeof(ipxs))==-1) - { - n_printf("IPX: could bind to network 0 in GetMyAddress\n"); - close( sock ); - return(-1); - } - - len = sizeof(ipxs2); - if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) { - n_printf("IPX: could not get socket name in GetMyAddress\n"); - close( sock ); - return(-1); - } - - memcpy(ipx_MyAddress, &ipxs2.sipx_network, 4); - for (i = 0; i < 6; i++) { - ipx_MyAddress[4+i] = ipxs2.sipx_node[i]; - } - close( sock ); - return(0); + ipxs.sipx_network=0; +#endif + ipxs.sipx_port=0; + + if (bind(sock,(struct sockaddr *)&ipxs,sizeof(ipxs)) == -1) { + n_printf("IPX: could bind to network 0 in GetMyAddress\n"); + close( sock ); + return(-1); + } + + len = sizeof(ipxs2); + if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) { + n_printf("IPX: could not get socket name in GetMyAddress\n"); + close( sock ); + return(-1); + } + + memcpy(ipx_MyAddress, &ipxs2.sipx_network, 4); + for (i = 0; i < 6; i++) { + ipx_MyAddress[4+i] = ipxs2.sipx_node[i]; + } + close( sock ); + return(0); } -static int ipx_bsd_OpenSocket(int port) +static int ipx_bsd_OpenSocket(ipx_socket_t *sk, int port) { - int sock; /* sock here means Linux socket handle */ - int opt; - struct sockaddr_ipx ipxs; - int len; - struct sockaddr_ipx ipxs2; - - /* DANG_FIXTHIS - kludge to support broken linux IPX stack */ - /* need to convert dynamic socket open into a real socket number */ -/* if (port == 0) { - n_printf("IPX: using socket %x\n", nextDynamicSocket); - port = nextDynamicSocket++; - } -*/ - /* do a socket call, then bind to this port */ - sock = socket(AF_IPX, SOCK_DGRAM, PF_IPX); - if (sock == -1) { - n_printf("IPX: could not open IPX socket.\n"); - return -1; - } + int sock; /* sock here means Linux socket handle */ + int opt; + struct sockaddr_ipx ipxs; + int len; + struct sockaddr_ipx ipxs2; + + /* DANG_FIXTHIS - kludge to support broken linux IPX stack */ + /* need to convert dynamic socket open into a real socket number */ + /* + if (port == 0) { + n_printf("IPX: using socket %x\n", nextDynamicSocket); + port = nextDynamicSocket++; + } + */ + /* do a socket call, then bind to this port */ + sock = socket(AF_IPX, SOCK_DGRAM, PF_IPX); + if (sock == -1) { + n_printf("IPX: could not open IPX socket.\n"); + return -1; + } #ifdef DOSEMU - opt = 1; - /* turn on socket debugging */ - if (d.network) { - enter_priv_on(); - if (setsockopt(sock, SOL_SOCKET, SO_DEBUG, &opt, sizeof(opt)) == -1) { - leave_priv_setting(); - n_printf("IPX: could not set socket option for debugging.\n"); - return -1; - } - leave_priv_setting(); - } -#endif - opt = 1; - /* Permit broadcast output */ - enter_priv_on(); - if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, - &opt, sizeof(opt)) == -1) { - leave_priv_setting(); - n_printf("IPX: could not set socket option for broadcast.\n"); - return -1; - } + opt = 1; + /* turn on socket debugging */ + if (d.network) { + enter_priv_on(); + if (setsockopt(sock, SOL_SOCKET, SO_DEBUG, &opt, sizeof(opt)) == -1) { + leave_priv_setting(); + n_printf("IPX: could not set socket option for debugging.\n"); + return -1; + } + leave_priv_setting(); + } +#endif + opt = 1; + /* Permit broadcast output */ + enter_priv_on(); + if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, + &opt, sizeof(opt)) == -1) { + leave_priv_setting(); + n_printf("IPX: could not set socket option for broadcast.\n"); + return -1; + } #ifdef DOSEMU - /* allow setting the type field in the IPX header */ - opt = 1; + /* allow setting the type field in the IPX header */ + opt = 1; #if 0 /* this seems to be wrong: IPX_TYPE can only be set on level SOL_IPX */ - if (setsockopt(sock, SOL_SOCKET, IPX_TYPE, &opt, sizeof(opt)) == -1) { + if (setsockopt(sock, SOL_SOCKET, IPX_TYPE, &opt, sizeof(opt)) == -1) { #else - /* the socket _is_ an IPX socket, hence it first passes ipx_setsockopt() - * in file linux/net/ipx/af_ipx.c. This one handles SOL_IPX itself and - * passes SOL_SOCKET-levels down to sock_setsockopt(). - * Hence I guess the below is correct (can somebody please verify this?) - * -- Hans, June 14 1997 - */ - if (setsockopt(sock, SOL_IPX, IPX_TYPE, &opt, sizeof(opt)) == -1) { + /* the socket _is_ an IPX socket, hence it first passes ipx_setsockopt() + * in file linux/net/ipx/af_ipx.c. This one handles SOL_IPX itself and + * passes SOL_SOCKET-levels down to sock_setsockopt(). + * Hence I guess the below is correct (can somebody please verify this?) + * -- Hans, June 14 1997 + */ + if (setsockopt(sock, SOL_IPX, IPX_TYPE, &opt, sizeof(opt)) == -1) { #endif - leave_priv_setting(); - n_printf("IPX: could not set socket option for type.\n"); - return -1; - } -#endif - ipxs.sipx_family = AF_IPX; - ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]); -/* ipxs.sipx_network = htonl(MyNetwork); */ - bzero(ipxs.sipx_node, 6); /* Please fill in my node name */ - ipxs.sipx_port = htons(port); - - /* now bind to this port */ - if (bind(sock, (struct sockaddr *) &ipxs, sizeof(ipxs)) == -1) { - n_printf("IPX: could not bind socket to address\n"); - close( sock ); - leave_priv_setting(); - return -1; - } - - if( port==0 ) { - len = sizeof(ipxs2); - if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) { - n_printf("IPX: could not get socket name in IPXOpenSocket\n"); - close( sock ); - leave_priv_setting(); - return -1; - } else { - port = htons(ipxs2.sipx_port); - n_printf("IPX: opened dynamic socket %04x\n", port); - } - } - leave_priv_setting(); - mysock.fd = sock; - mysock.socket = port; - - ipx_bsd_GetMyAddress(); - - return 0; + leave_priv_setting(); + n_printf("IPX: could not set socket option for type.\n"); + return -1; + } +#endif + ipxs.sipx_family = AF_IPX; + ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]); + /* ipxs.sipx_network = htonl(MyNetwork); */ + bzero(ipxs.sipx_node, 6); /* Please fill in my node name */ + ipxs.sipx_port = htons(port); + + /* now bind to this port */ + if (bind(sock, (struct sockaddr *) &ipxs, sizeof(ipxs)) == -1) { + n_printf("IPX: could not bind socket to address\n"); + close( sock ); + leave_priv_setting(); + return -1; + } + + if( port==0 ) { + len = sizeof(ipxs2); + if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) { + n_printf("IPX: could not get socket name in IPXOpenSocket\n"); + close( sock ); + leave_priv_setting(); + return -1; + } else { + port = htons(ipxs2.sipx_port); + n_printf("IPX: opened dynamic socket %04x\n", port); + } + } + leave_priv_setting(); + sk->fd = sock; + sk->socket = port; + return 0; } -static void ipx_bsd_CloseSocket(void) { - /* now close the file descriptor for the socket, and free it */ - n_printf("IPX: closing file descriptor on socket %x\n", mysock.socket); - close(mysock.fd); +static void ipx_bsd_CloseSocket(ipx_socket_t *mysock) { + /* now close the file descriptor for the socket, and free it */ + n_printf("IPX: closing file descriptor on socket %x\n", mysock->socket); + close(mysock->fd); } -static int ipx_bsd_SendPacket(IPXPacket_t *IPXHeader, - u_char *data, int dataLen) { - struct sockaddr_ipx ipxs; - - ipxs.sipx_family = AF_IPX; - /* get destination address from IPX packet header */ - memcpy(&ipxs.sipx_network, IPXHeader->Destination.Network, 4); - /* if destination address is 0, then send to my net */ - if (ipxs.sipx_network == 0) { - ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]); -/* ipxs.sipx_network = htonl(MyNetwork); */ - } - memcpy(&ipxs.sipx_node, IPXHeader->Destination.Node, 6); - //memcpy(&ipxs.sipx_port, IPXHeader->Destination.Socket, 2); - ipxs.sipx_port=htons(mysock.socket); - ipxs.sipx_type = IPXHeader->PacketType; - /* ipxs.sipx_port=htons(0x452); */ - return sendto(mysock.fd, data, dataLen, 0, - (struct sockaddr *) &ipxs, sizeof(ipxs)); +static int ipx_bsd_SendPacket(ipx_socket_t *mysock, IPXPacket_t *IPXHeader, + u_char *data, int dataLen) { + struct sockaddr_ipx ipxs; + + ipxs.sipx_family = AF_IPX; + /* get destination address from IPX packet header */ + memcpy(&ipxs.sipx_network, IPXHeader->Destination.Network, 4); + /* if destination address is 0, then send to my net */ + if (ipxs.sipx_network == 0) { + ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]); + /* ipxs.sipx_network = htonl(MyNetwork); */ + } + memcpy(&ipxs.sipx_node, IPXHeader->Destination.Node, 6); + memcpy(&ipxs.sipx_port, IPXHeader->Destination.Socket, 2); + ipxs.sipx_type = IPXHeader->PacketType; + /* ipxs.sipx_port=htons(0x452); */ + return sendto(mysock->fd, data, dataLen, 0, + (struct sockaddr *) &ipxs, sizeof(ipxs)); } -static int ipx_bsd_ReceivePacket(char *buffer, int bufsize, - struct ipx_recv_data *rd) { +static int ipx_bsd_ReceivePacket(ipx_socket_t *s, char *buffer, int bufsize, + struct ipx_recv_data *rd) { int sz, size; struct sockaddr_ipx ipxs; - + sz = sizeof(ipxs); - if ((size = recvfrom(mysock.fd, buffer, bufsize, 0, - (struct sockaddr *) &ipxs, &sz)) <= 0) - return size; + if ((size = recvfrom(s->fd, buffer, bufsize, 0, + (struct sockaddr *) &ipxs, &sz)) <= 0) + return size; memcpy(rd->src_network, &ipxs.sipx_network, 4); memcpy(rd->src_node, ipxs.sipx_node, 6); rd->src_socket = ipxs.sipx_port; - rd->dst_socket = mysock.socket; + rd->dst_socket = s->socket; rd->pkt_type = ipxs.sipx_type; - - return size; -} -static int ipx_bsd_general_PacketReady(void) { - return ipx_general_PacketReady(mysock.fd); + return size; } struct ipx_driver ipx_bsd = { -// ipx_bsd_GetMyAddress, + ipx_bsd_GetMyAddress, ipx_bsd_OpenSocket, ipx_bsd_CloseSocket, ipx_bsd_SendPacket, ipx_bsd_ReceivePacket, - ipx_bsd_general_PacketReady, - NULL, - 1, - NULL, - NULL, - NULL + ipx_general_PacketReady }; diff --git a/arch/linux/ipx_udp.c b/arch/linux/ipx_udp.c index 3a12396d..19b4c4c7 100644 --- a/arch/linux/ipx_udp.c +++ b/arch/linux/ipx_udp.c @@ -1,8 +1,6 @@ +/* $Id: */ + /* - * $Source: /cvs/cvsroot/d2x/arch/linux/ipx_udp.c,v $ - * $Revision: 1.4 $ - * $Author: bradleyb $ - * $Date: 2001-10-19 07:29:37 $ * * IPX driver for native Linux TCP/IP networking (UDP implementation) * Version 0.99.2 @@ -63,10 +61,6 @@ * * Have fun! * - * $Log: not supported by cvs2svn $ - * Revision 1.3 2001/01/29 13:35:08 bradleyb - * Fixed build system, minor fixes - * */ #ifdef HAVE_CONFIG_H diff --git a/arch/linux/linuxnet.c b/arch/linux/linuxnet.c index d1d237df..56f4701f 100644 --- a/arch/linux/linuxnet.c +++ b/arch/linux/linuxnet.c @@ -1,42 +1,375 @@ /* - * $Source: /cvs/cvsroot/d2x/arch/linux/linuxnet.c,v $ - * $Revision: 1.5 $ - * $Author: bradleyb $ - * $Date: 2001-10-19 07:39:26 $ +THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX +SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO +END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A +ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS +IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS +SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE +FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE +CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS +AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. +COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. +*/ + +/* * * Linux net * - * $Log: not supported by cvs2svn $ - * Revision 1.4 2001/10/19 07:29:37 bradleyb - * Brought linux networking in line with d1x, moved some arch/linux_* stuff to arch/linux/ - * - * Revision 1.3 2001/01/29 13:35:09 bradleyb - * Fixed build system, minor fixes - * */ #ifdef HAVE_CONFIG_H #include #endif +#ifdef NETWORK +#include +#include +#include +#include +#include +#include /* for htons & co. */ + #include "pstypes.h" +#include "config.h" +#include "args.h" #include "ipx_drv.h" #include "ipx_bsd.h" #include "ipx_kali.h" #include "ipx_udp.h" +//added 05/17/99 Matt Mueller - needed to redefine FD_* so that no asm is used +//#include "checker.h" +//end addition -MM +#define MAX_IPX_DATA 576 -#include +int ipx_fd; +ipx_socket_t ipx_socket_data; +ubyte ipx_installed=0; +ushort ipx_socket = 0; +uint ipx_network = 0; +ubyte ipx_MyAddress[10]; +int ipx_packetnum = 0; /* Sequence number */ +//int ipx_packettotal=0,ipx_lastspeed=0; + +/* User defined routing stuff */ +typedef struct user_address { + ubyte network[4]; + ubyte node[6]; + ubyte address[6]; +} user_address; +#define MAX_USERS 64 +int Ipx_num_users = 0; +user_address Ipx_users[MAX_USERS]; + +#define MAX_NETWORKS 64 +int Ipx_num_networks = 0; +uint Ipx_networks[MAX_NETWORKS]; + +void ipx_close(void); + +int ipx_general_PacketReady(ipx_socket_t *s) { + fd_set set; + struct timeval tv; + + FD_ZERO(&set); + FD_SET(s->fd, &set); + tv.tv_sec = tv.tv_usec = 0; + if (select(s->fd + 1, &set, NULL, NULL, &tv) > 0) + return 1; + else + return 0; +} + +struct ipx_driver *driver = &ipx_bsd; + +ubyte * ipx_get_my_server_address() +{ + return (ubyte *)&ipx_network; +} + +ubyte * ipx_get_my_local_address() +{ + return (ubyte *)(ipx_MyAddress + 4); +} + +//--------------------------------------------------------------- +// Initializes all IPX internals. +// If socket_number==0, then opens next available socket. +// Returns: 0 if successful. +// -1 if socket already open. +// -2 if socket table full. +// -3 if IPX not installed. +// -4 if couldn't allocate low dos memory +// -5 if error with getting internetwork address +int ipx_init( int socket_number, int show_address ) +{ + int i; + +/* DPH: killed kali for now + if (FindArg("-kali")) { + printf("Using Kali for network games\n"); + driver = &ipx_kali; +//added on 12/20/98 by Jan Kratochvil for direct TCP/IP games + } else*/ if (FindArg("-udp")) { + printf("Using native TCP/IP (UDP) for network games\n"); + driver = &ipx_udp; +//end this section addition - JK + } else { + printf("Using real IPX for network games\n"); + driver = &ipx_bsd; + } + if ((i = FindArg("-ipxnetwork")) && Args[i + 1]) { + unsigned long n = strtol(Args[i + 1], NULL, 16); + ipx_MyAddress[0] = n >> 24; ipx_MyAddress[1] = (n >> 16) & 255; + ipx_MyAddress[2] = (n >> 8) & 255; ipx_MyAddress[3] = n & 255; + printf("IPX: Using network %08x\n", (unsigned int)n); + } + if (driver->OpenSocket(&ipx_socket_data, socket_number)) { + return -3; + } + driver->GetMyAddress(); + memcpy(&ipx_network, ipx_MyAddress, 4); + Ipx_num_networks = 0; + memcpy( &Ipx_networks[Ipx_num_networks++], &ipx_network, 4 ); + ipx_installed = 1; + atexit(ipx_close); + return 0; +} + +void ipx_close() +{ + if (ipx_installed) + driver->CloseSocket(&ipx_socket_data); + ipx_installed = 0; +} + +int ipx_get_packet_data( ubyte * data ) +{ + struct ipx_recv_data rd; + char buf[MAX_IPX_DATA]; +//killed 6-15-99 to get rid of compile warnings - OE +// uint best_id = 0; +// uint pkt_num; +//end kill - OE + int size; + int best_size = 0; +//edited 04/12/99 Matt Mueller - duh, we don't want to throw all that data away! + //--killed-- Like the original, only take latest packet, throw away rest + //do _NOT_ throw them away! + while (driver->PacketReady(&ipx_socket_data)) { + if ((size = + driver->ReceivePacket(&ipx_socket_data, buf, + sizeof(buf), &rd)) > 4) { + if (!memcmp(rd.src_network, ipx_MyAddress, 10)) + continue; /* don't get own pkts */ +//--killed-- pkt_num = *(uint *)buf; +//--killed-- if (pkt_num >= best_id) { + memcpy(data, buf + 4, size - 4); + return size-4; +//--killed-- best_id = pkt_num; +//--killed-- best_size = size - 4; +//--killed-- } +//end edit -MM + } + } + return best_size; +} + +void ipx_send_packet_data( ubyte * data, int datasize, ubyte *network, ubyte *address, ubyte *immediate_address ) +{ + u_char buf[MAX_IPX_DATA]; + IPXPacket_t ipx_header; + + memcpy(ipx_header.Destination.Network, network, 4); + memcpy(ipx_header.Destination.Node, immediate_address, 6); + *(u_short *)ipx_header.Destination.Socket = htons(ipx_socket_data.socket); + ipx_header.PacketType = 4; /* Packet Exchange */ + *(uint *)buf = ipx_packetnum++; + //ipx_packettotal+=datasize+4; + //if (f2i(Players[Player_num].time_level) && (f2i(Players[Player_num].time_level)%10!=ipx_lastspeed)) + //{ + // ipx_lastspeed=f2i(Players[Player_num].time_level)%10; + // printf("tot=%i,t2=%i,time=%i,avg=%i,a2=%i\n",ipx_packetnum,ipx_packettotal,(int)f2i(Players[Player_num].time_level), + // ipx_packetnum/(int)f2i(Players[Player_num].time_level), + // ipx_packettotal/(int)f2i(Players[Player_num].time_level)); + //} + memcpy(buf + 4, data, datasize); + driver->SendPacket(&ipx_socket_data, &ipx_header, buf, datasize + 4); +} + +void ipx_get_local_target( ubyte * server, ubyte * node, ubyte * local_target ) +{ + // let's hope Linux knows how to route it + memcpy( local_target, node, 6 ); +} + +void ipx_send_broadcast_packet_data( ubyte * data, int datasize ) +{ + int i, j; + ubyte broadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + ubyte local_address[6]; + + // Set to all networks besides mine + for (i=0; iCloseSocket(&ipx_socket_data); + if (driver->OpenSocket(&ipx_socket_data, socket_number)) { + return -3; + } + return 0; +} + +void ipx_read_user_file(char * filename) +{ + FILE * fp; + user_address tmp; + char temp_line[132], *p1; + int n, ln=0, x; + + if (!filename) return; + + Ipx_num_users = 0; + + fp = fopen( filename, "rt" ); + if ( !fp ) return; + + printf( "Broadcast Users:\n" ); + + while (fgets(temp_line, 132, fp)) { + ln++; + p1 = strchr(temp_line,'\n'); if (p1) *p1 = '\0'; + p1 = strchr(temp_line,';'); if (p1) *p1 = '\0'; +#if 1 // adb: replaced sscanf(..., "%2x...", (char *)...) with better, but longer code + if (strlen(temp_line) >= 21 && temp_line[8] == '/') { + for (n = 0; n < 4; n++) { + if (sscanf(temp_line + n * 2, "%2x", &x) != 1) + break; + tmp.network[n] = x; + } + if (n != 4) + continue; + for (n = 0; n < 6; n++) { + if (sscanf(temp_line + 9 + n * 2, "%2x", &x) != 1) + break; + tmp.node[n] = x; + } + if (n != 6) + continue; + } else + continue; +#else + n = sscanf( temp_line, "%2x%2x%2x%2x/%2x%2x%2x%2x%2x%2x", &tmp.network[0], &tmp.network[1], &tmp.network[2], &tmp.network[3], &tmp.node[0], &tmp.node[1], &tmp.node[2],&tmp.node[3], &tmp.node[4], &tmp.node[5] ); + if ( n != 10 ) continue; +#endif + if ( Ipx_num_users < MAX_USERS ) { + ubyte * ipx_real_buffer = (ubyte *)&tmp; + ipx_get_local_target( tmp.network, tmp.node, tmp.address ); + Ipx_users[Ipx_num_users++] = tmp; + printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] ); + printf( "%02X%02X%02X%02X%02X%02X\n", ipx_real_buffer[4],ipx_real_buffer[5],ipx_real_buffer[6],ipx_real_buffer[7],ipx_real_buffer[8],ipx_real_buffer[9] ); + } else { + printf( "Too many addresses in %s! (Limit of %d)\n", filename, MAX_USERS ); + fclose(fp); + return; + } + } + fclose(fp); +} -struct ipx_driver * arch_ipx_set_driver(char *arg) + +void ipx_read_network_file(char * filename) { - if (strcmp(arg,"kali")==0){ - return &ipx_kali; -#if 0 - }else if (strcmp(arg,"udp")==0){ - return &ipx_udp; + FILE * fp; + user_address tmp; + char temp_line[132], *p1; + int i, n, ln=0, x; + + if (!filename) return; + + fp = fopen( filename, "rt" ); + if ( !fp ) return; + + printf( "Using Networks:\n" ); + for (i=0; i= 8) { + for (n = 0; n < 4; n++) { + if (sscanf(temp_line + n * 2, "%2x", &x) != 1) + break; + tmp.network[n] = x; + } + if (n != 4) + continue; + } else + continue; +#else + n = sscanf( temp_line, "%2x%2x%2x%2x", &tmp.network[0], &tmp.network[1], &tmp.network[2], &tmp.network[3] ); + if ( n != 4 ) continue; #endif - }else { - return &ipx_bsd; + if ( Ipx_num_networks < MAX_NETWORKS ) { + int j; + for (j=0; j= Ipx_num_networks ) { + memcpy( &Ipx_networks[Ipx_num_networks++], tmp.network, 4 ); + printf(" %02x%02x%02x%02x\n", tmp.network[0], tmp.network[1], tmp.network[2], tmp.network[3] ); + } + } else { + printf( "Too many networks in %s! (Limit of %d)\n", filename, MAX_NETWORKS ); + fclose(fp); + return; + } } + fclose(fp); } +#endif //NETWORK diff --git a/main/Makefile.am b/main/Makefile.am index 12fab48e..7ac00895 100644 --- a/main/Makefile.am +++ b/main/Makefile.am @@ -9,8 +9,7 @@ noinst_LIBRARIES = libmain.a INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/arch/include if USE_NETWORK -NETWORK_SRCS = ipx_drv.c kmatrix.c multi.c multibot.c network.c -# ipclienc.c ip_base.cpp ipclient.cpp netlist.c netpkt.c multipow.c +NETWORK_SRCS = kmatrix.c multi.c multibot.c network.c endif if EDITOR diff --git a/main/inferno.c b/main/inferno.c index fbaa5d7e..69404a2d 100644 --- a/main/inferno.c +++ b/main/inferno.c @@ -1,4 +1,4 @@ -/* $Id: inferno.c,v 1.40 2002-08-23 10:43:11 btb Exp $ */ +/* $Id: inferno.c,v 1.41 2002-08-29 08:54:42 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -295,7 +295,9 @@ void print_commandline_help() // printf( " -tsengdebug1 %s\n","FIXME: Undocumented"); // printf( " -tsengdebug2 %s\n","FIXME: Undocumented"); // printf( " -tsengdebug3 %s\n","FIXME: Undocumented"); -// printf( " -udp %s\n","FIXME: Undocumented"); +#ifdef NETWORK + printf( " -udp %s\n","Use TCP/UDP for networking"); +#endif // printf( " -vidram %s\n","FIXME: Undocumented"); printf( " -xcontrol %s\n","FIXME: Undocumented"); printf( " -xname %s\n","FIXME: Undocumented"); @@ -404,14 +406,14 @@ void do_register_player(ubyte *title_pal) void do_network_init() { if (!FindArg( "-nonetwork" )) { - int socket=0, t; + int socket = 0, showaddress = 0, t; int ipx_error; con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK); if ((t=FindArg("-socket"))) socket = atoi( Args[t+1] ); //@@if ( FindArg("-showaddress") ) showaddress=1; - if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket))==0) { + if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket, showaddress))==0) { con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket ); Network_active = 1; } else { -- 2.39.2