2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
14 * $Source: /cvs/cvsroot/d2x/arch/dos/bak/ipx.c,v $
15 * $Revision: 1.1.1.1 $
17 * $Date: 2001-01-19 03:30:15 $
19 * Routines for IPX communications.
21 * $Log: not supported by cvs2svn $
22 * Revision 1.1.1.1 1999/06/14 22:00:03 donut
23 * Import of d1x 1.37 source.
25 * Revision 2.10 1995/03/29 17:27:55 john
26 * Added code to not duplicate broadcasts.
28 * Revision 2.9 1995/03/29 15:32:07 john
31 * Revision 2.8 1995/03/29 15:07:31 john
32 * Added network support.
34 * Revision 2.7 1995/03/29 11:22:27 john
35 * Added broadcasting over a net.
37 * Revision 2.6 1995/03/28 20:05:03 john
38 * Took away alternate server stuff.
40 * Revision 2.5 1995/03/23 19:14:29 john
41 * Added better MAX_USERS message.
43 * Revision 2.4 1995/03/23 19:00:02 john
44 * Added user list capabitly.
46 * Revision 2.3 1995/03/23 12:27:05 john
47 * Move IPX into bios lib.
49 * Revision 2.2 1995/03/22 19:08:15 john
50 * Added code to fix sending packets over router... now
51 * we just need to make broadcasts go over router!!
53 * Revision 2.1 1995/03/21 08:40:16 john
54 * Ifdef'd out the NETWORK code.
56 * Revision 2.0 1995/02/27 11:30:45 john
57 * New version 2.0, which has no anonymous unions, builds with
58 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
60 * Revision 1.31 1995/02/16 17:35:03 john
61 * Added code to allow dynamic socket changing.
63 * Revision 1.30 1995/02/01 21:03:45 john
66 * Revision 1.29 1995/01/22 14:31:05 john
69 * Revision 1.28 1995/01/22 14:29:26 john
70 * Added code to bypass broadcast messages.
72 * Revision 1.27 1995/01/03 13:46:16 john
73 * Added code that should make ipx work over different servers,
74 * but ifdef'd it out with SHAREWARE in ipx.c. I haven't tested
75 * this, and I hope it doesn't introduce net bugs.
77 * Revision 1.26 1994/12/14 11:54:37 rob
78 * Reduce # of ipx packets.
80 * Revision 1.25 1994/12/11 00:43:28 john
81 * Locked down DOS ipx buffers... probably not necessary, tho.
83 * Revision 1.24 1994/12/08 15:49:58 rob
84 * Bumped up the # of ipx packets.
86 * Revision 1.23 1994/12/04 15:23:54 rob
87 * Reduced packet # constants.
89 * Revision 1.22 1994/11/27 23:12:39 matt
90 * Made changes for new mprintf calling convention
92 * Revision 1.21 1994/11/19 15:15:19 mike
93 * remove unused code and data
95 * Revision 1.20 1994/11/10 11:06:07 rob
96 * Raised number of ipx packets to 64 and buffers to 128 (for 8-way games)
97 * Removed (commented out) all the spx support stuff.
99 * Revision 1.19 1994/11/07 17:50:12 rob
100 * Bumped up max_packets and ipx_num_packets to double their previous
103 * Revision 1.18 1994/11/07 15:39:01 rob
104 * Removed temporary hacked ipx_send_object function.
105 * Replaced with a more general thing.
107 * Revision 1.17 1994/11/05 16:08:40 rob
108 * Made a change necessary for object syncing on rejoin.
110 * Revision 1.16 1994/11/01 15:57:12 rob
111 * Added support for SPX sockets for critical messages.
113 * Revision 1.15 1994/10/31 19:21:01 rob
114 * Added a routine for sending objects via ipx. Its a hack and shoukld
115 * be replaced by something more general time permitting.
117 * Revision 1.14 1994/10/20 14:57:42 john
120 * Revision 1.13 1994/10/20 11:22:45 john
121 * Tweaked the number of waiting packets. Added code to print
122 * total packets missed, and to limit the packet send rate to
123 * 10 packets per second unless firing.
125 * Revision 1.12 1994/10/03 20:50:11 john
126 * Started adding sound pause functions.
128 * Revision 1.11 1994/09/15 08:54:24 mike
129 * comment out a mprintf.
131 * Revision 1.10 1994/09/12 19:38:20 john
132 * Made some stuff that prints to the DOS screen go to the
133 * mono instead, since it really is debugging info.
135 * Revision 1.9 1994/09/07 13:32:03 john
136 * Made ipx_close explicitly close the socket we were using,
137 * because it seems that VLM's don't automatically close them
138 * like the older NETX stuff did (Going from Novell 3.11 driver
141 * Revision 1.8 1994/09/06 19:29:20 john
142 * Added trial version of rejoin function.
144 * Revision 1.7 1994/08/09 19:31:50 john
145 * Networking changes.
147 * Revision 1.6 1994/08/05 16:11:41 john
148 * Psuedo working version of networking.
150 * Revision 1.5 1994/08/04 19:17:21 john
151 * Inbetween version of network stuff.
153 * Revision 1.4 1994/07/29 16:08:57 john
154 * *** empty log message ***
156 * Revision 1.3 1994/07/25 12:33:31 john
157 * Network "pinging" in.
159 * Revision 1.2 1994/07/20 15:58:28 john
160 * First installment of ipx stuff.
162 * Revision 1.1 1994/07/19 15:42:00 john
169 static char rcsid[] = "$Id: ipx.c,v 1.1.1.1 2001-01-19 03:30:15 bradleyb Exp $";
173 #define _BORLAND_DOS_REGS 1
193 typedef unsigned char BYTE;
194 typedef unsigned short WORD;
195 typedef unsigned long DWORD;
197 typedef struct local_address {
199 } __pack__ local_address;
201 typedef struct net_address {
203 local_address node_id;
205 } __pack__ net_address;
207 typedef struct ipx_header {
210 BYTE transport_control;
212 net_address destination;
214 } __pack__ ipx_header;
216 typedef struct ecb_header {
220 BYTE completion_code;
222 BYTE ipx_reserved[14];
224 local_address immediate_address;
226 WORD fragment_pointer[2];
228 } __pack__ ecb_header;
230 typedef struct packet_data {
232 byte data[IPX_MAX_DATA_SIZE];
233 } __pack__ packet_data;
235 typedef struct ipx_packet {
239 } __pack__ ipx_packet;
241 typedef struct user_address {
245 } __pack__ user_address;
248 int Ipx_num_users = 0;
249 user_address Ipx_users[MAX_USERS];
251 #define MAX_NETWORKS 64
252 int Ipx_num_networks = 0;
253 uint Ipx_networks[MAX_NETWORKS];
255 int ipx_packetnum = 0;
257 #define MAX_PACKETS 64
259 static packet_data packet_buffers[MAX_PACKETS];
260 static short packet_free_list[MAX_PACKETS];
261 static int num_packets = 0;
262 static int largest_packet_index = 0;
263 static short packet_size[MAX_PACKETS];
265 //added on 10/29/98 by Kevin Bently to add ipx stuff
266 WORD ipx_num_outgoing_packets = 8;
267 ipx_packet * outpackets;
268 //end this section addition - Kevin Bently
271 ubyte ipx_installed=0;
272 WORD ipx_vector_segment;
273 WORD ipx_vector_offset;
274 ubyte ipx_socket_life = 0; // 0=closed at prog termination, 0xff=closed when requested.
275 DWORD ipx_network = 0;
276 local_address ipx_my_node;
277 WORD ipx_num_packets=32; // 32 Ipx packets
278 ipx_packet * packets;
280 ushort ipx_packets_selector;
282 ecb_header * last_ecb=NULL;
285 void got_new_packet( ecb_header * ecb );
286 void ipx_listen_for_packet(ecb_header * ecb );
288 void free_packet( int id )
290 packet_buffers[id].packetnum = -1;
291 packet_free_list[ --num_packets ] = id;
292 if (largest_packet_index==id)
293 while ((--largest_packet_index>0) && (packet_buffers[largest_packet_index].packetnum == -1 ));
296 int ipx_get_packet_data( ubyte * data )
298 int i, n, best, best_id, size;
300 for (i=1; i<ipx_num_packets; i++ ) {
301 if ( !packets[i].ecb.in_use ) {
302 got_new_packet( &packets[i].ecb );
303 packets[i].ecb.in_use = 0;
304 ipx_listen_for_packet(&packets[i].ecb);
312 for (i=0; i<=largest_packet_index; i++ ) {
313 if ( packet_buffers[i].packetnum > -1 ) {
315 if ( best == -1 || (packet_buffers[i].packetnum<best) ) {
316 best = packet_buffers[i].packetnum;
322 //mprintf( (0, "Best id = %d, pn = %d, last_ecb = %x, len=%x, ne = %d\n", best_id, best, last_ecb, lastlen, neterrors ));
323 //mprintf( (1, "<%d> ", neterrors ));
325 if ( best_id < 0 ) return 0;
327 size = packet_size[best_id];
328 memcpy( data, packet_buffers[best_id].data, size );
329 free_packet(best_id);
335 unsigned int swap_short( unsigned int short )
336 #pragma aux swap_short parm [eax] = "xchg al,ah";
338 static inline unsigned int swap_short( unsigned int sshort ) {
340 asm("xchg %%ah,%%al" : "=a" (__retval) : "a" (sshort));
345 void got_new_packet( ecb_header * ecb )
349 unsigned short datasize;
353 p = (ipx_packet *)ecb;
355 if ( p->ecb.in_use ) { neterrors++; return; }
356 if ( p->ecb.completion_code ) { neterrors++; return; }
358 // Error( "Recieve error %d for completion code", p->ecb.completion_code );
360 if ( memcmp( &p->ipx.source.node_id, &ipx_my_node, 6 ) ) {
361 datasize=swap_short(p->ipx.length);
363 datasize -= sizeof(ipx_header);
364 // Find slot to put packet in...
365 if ( datasize > 0 && datasize <= sizeof(packet_data) ) {
366 if ( num_packets >= MAX_PACKETS ) {
367 //printf( 1, "IPX: Packet buffer overrun!!!\n" );
371 id = packet_free_list[ num_packets++ ];
372 if (id > largest_packet_index ) largest_packet_index = id;
373 packet_size[id] = datasize-sizeof(int);
374 packet_buffers[id].packetnum = p->pd.packetnum;
375 if ( packet_buffers[id].packetnum < 0 ) { neterrors++; return; }
376 memcpy( packet_buffers[id].data, p->pd.data, packet_size[id] );
383 //ipx_listen_for_packet(&p->ecb);
386 ubyte * ipx_get_my_local_address()
388 return ipx_my_node.address;
391 ubyte * ipx_get_my_server_address()
393 return (ubyte *)&ipx_network;
396 void ipx_listen_for_packet(ecb_header * ecb )
398 dpmi_real_regs rregs;
400 memset(&rregs,0,sizeof(dpmi_real_regs));
401 rregs.ebx = 4; // Listen For Packet function
402 rregs.esi = DPMI_real_offset(ecb);
403 rregs.es = DPMI_real_segment(ecb);
404 dpmi_real_int386x( 0x7A, &rregs );
407 void ipx_cancel_listen_for_packet(ecb_header * ecb )
409 dpmi_real_regs rregs;
410 memset(&rregs,0,sizeof(dpmi_real_regs));
411 rregs.ebx = 6; // IPX Cancel event
412 rregs.esi = DPMI_real_offset(ecb);
413 rregs.es = DPMI_real_segment(ecb);
414 dpmi_real_int386x( 0x7A, &rregs );
418 void ipx_send_packet(ecb_header * ecb )
420 dpmi_real_regs rregs;
421 memset(&rregs,0,sizeof(dpmi_real_regs));
422 rregs.ebx = 3; // Send Packet function
423 rregs.esi = DPMI_real_offset(ecb);
424 rregs.es = DPMI_real_segment(ecb);
425 dpmi_real_int386x( 0x7A, &rregs );
431 ubyte local_target[6];
432 } __pack__ net_xlat_info;
434 void ipx_get_local_target( ubyte * server, ubyte * node, ubyte * local_target )
436 net_xlat_info * info;
437 dpmi_real_regs rregs;
439 // Get dos memory for call...
440 info = (net_xlat_info *)dpmi_get_temp_low_buffer( sizeof(net_xlat_info) );
441 assert( info != NULL );
442 memcpy( info->network, server, 4 );
443 memcpy( info->node, node, 6 );
445 memset(&rregs,0,sizeof(dpmi_real_regs));
447 rregs.ebx = 2; // Get Local Target
448 rregs.es = DPMI_real_segment(info);
449 rregs.esi = DPMI_real_offset(info->network);
450 rregs.edi = DPMI_real_offset(info->local_target);
452 dpmi_real_int386x( 0x7A, &rregs );
454 // Save the local target...
455 memcpy( local_target, info->local_target, 6 );
460 dpmi_real_regs rregs;
461 if ( ipx_installed ) {
462 // When using VLM's instead of NETX, the sockets don't
463 // seem to automatically get closed, so we must explicitly
464 // close them at program termination.
466 memset(&rregs,0,sizeof(dpmi_real_regs));
467 rregs.edx = ipx_socket;
468 rregs.ebx = 1; // Close socket
469 dpmi_real_int386x( 0x7A, &rregs );
474 //---------------------------------------------------------------
475 // Initializes all IPX internals.
476 // If socket_number==0, then opens next available socket.
477 // Returns: 0 if successful.
478 // -1 if socket already open.
479 // -2 if socket table full.
480 // -3 if IPX not installed.
481 // -4 if couldn't allocate low dos memory
482 // -5 if error with getting internetwork address
484 int ipx_init( int socket_number, int show_address )
486 dpmi_real_regs rregs;
487 ubyte *ipx_real_buffer;
494 // init packet buffers.
495 for (i=0; i<MAX_PACKETS; i++ ) {
496 packet_buffers[i].packetnum = -1;
497 packet_free_list[i] = i;
500 largest_packet_index = 0;
502 // Get the IPX vector
503 memset(&rregs,0,sizeof(dpmi_real_regs));
504 rregs.eax=0x00007a00;
505 dpmi_real_int386x( 0x2f, &rregs );
507 if ( (rregs.eax & 0xFF) != 0xFF ) {
510 ipx_vector_offset = rregs.edi & 0xFFFF;
511 ipx_vector_segment = rregs.es;
512 //printf( "IPX entry point at %.4x:%.4x\n", ipx_vector_segment, ipx_vector_offset );
514 // Open a socket for IPX
516 memset(&rregs,0,sizeof(dpmi_real_regs));
517 swab( (char *)&socket_number,(char *)&ipx_socket, 2 );
518 rregs.edx = ipx_socket;
519 rregs.eax = ipx_socket_life;
520 rregs.ebx = 0; // Open socket
521 dpmi_real_int386x( 0x7A, &rregs );
523 ipx_socket = rregs.edx & 0xFFFF;
525 if ( rregs.eax & 0xFF ) {
526 //mprintf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
532 // Find our internetwork address
533 ipx_real_buffer = dpmi_get_temp_low_buffer( 1024 ); // 1k block
534 if ( ipx_real_buffer == NULL ) {
535 //printf( "Error allocation realmode memory\n" );
539 memset(&rregs,0,sizeof(dpmi_real_regs));
540 rregs.ebx = 9; // Get internetwork address
541 rregs.esi = DPMI_real_offset(ipx_real_buffer);
542 rregs.es = DPMI_real_segment(ipx_real_buffer);
543 dpmi_real_int386x( 0x7A, &rregs );
545 if ( rregs.eax & 0xFF ) {
546 //printf( "Error getting internetwork address!\n" );
550 memcpy( &ipx_network, ipx_real_buffer, 4 );
551 memcpy( &ipx_my_node, &ipx_real_buffer[4], 6 );
553 Ipx_num_networks = 0;
554 memcpy( &Ipx_networks[Ipx_num_networks++], &ipx_network, 4 );
556 if ( show_address ) {
557 printf( "My IPX addresss is " );
558 printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] );
559 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] );
563 packets = dpmi_real_malloc( sizeof(ipx_packet)*ipx_num_packets, &ipx_packets_selector );
564 if ( packets == NULL ) {
565 //printf( "Couldn't allocate real memory for %d packets\n", ipx_num_packets );
568 #if 0 /* adb: not needed, fails with cwsdpmi */
569 if (!dpmi_lock_region( packets, sizeof(ipx_packet)*ipx_num_packets )) {
570 //printf( "Couldn't lock real memory for %d packets\n", ipx_num_packets );
574 memset( packets, 0, sizeof(ipx_packet)*ipx_num_packets );
576 for (i=1; i<ipx_num_packets; i++ ) {
577 packets[i].ecb.in_use = 0x1d;
578 //packets[i].ecb.in_use = 0;
579 packets[i].ecb.socket_id = ipx_socket;
580 packets[i].ecb.fragment_count = 1;
581 packets[i].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[i].ipx);
582 packets[i].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[i].ipx);
583 packets[i].ecb.fragment_size = sizeof(ipx_packet)-sizeof(ecb_header); //-sizeof(ecb_header);
585 ipx_listen_for_packet(&packets[i].ecb);
588 //added/replaced on 10/29/98 by Kevin Bently for new ipx stuff
589 //-killed- packets[0].ecb.socket_id = ipx_socket;
590 //-killed- packets[0].ecb.fragment_count = 1;
591 //-killed- packets[0].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[0].ipx);
592 //-killed- packets[0].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[0].ipx);
593 //-killed- packets[0].ipx.packet_type = 4; // IPX packet
594 //-killed- packets[0].ipx.destination.socket_id = ipx_socket;
595 //-killed-// memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
596 //-killed- memset( packets[0].ipx.destination.network_id, 0, 4 );
597 outpackets = dpmi_real_malloc( sizeof(ipx_packet)*ipx_num_packets, &ipx_packets_selector);
599 for(i=0;i<ipx_num_outgoing_packets;i++)
601 outpackets[i].ecb.socket_id = ipx_socket;
602 outpackets[i].ecb.fragment_count = 1;
603 outpackets[i].ecb.fragment_pointer[0] = DPMI_real_offset(&outpackets[i].ipx);
604 outpackets[i].ecb.fragment_pointer[1] = DPMI_real_segment(&outpackets[i].ipx);
605 outpackets[i].ipx.packet_type = 4; // IPX packet
606 outpackets[i].ipx.destination.socket_id = ipx_socket;
607 memset( outpackets[i].ipx.destination.network_id, 0, 4 );
611 //end this section replace - Kevin Bently
615 void ipx_send_packet_data( ubyte * data, int datasize, ubyte *network, ubyte *address, ubyte *immediate_address )
618 ipx_packet *sendpacket = NULL;
620 assert(ipx_installed);
622 if ( datasize >= IPX_MAX_DATA_SIZE ) {
623 printf( "Data too big\n" );
629 //added/replaced on 10/29/98 by Kevin Bently for new ipx stuff
630 //-killed- // Make sure no one is already sending something
631 //-killed- while( packets[0].ecb.in_use )
635 //-killed- if (packets[0].ecb.completion_code) {
636 //-killed- printf( "Send error %d for completion code\n", packets[0].ecb.completion_code );
637 //-killed- //killed on 10/25/98 by Victor Rachels to fix LAN crash
638 //-killed- //-killed- exit(1);
639 //-killed- //end this section kill - Victor
642 for(i=0;i<ipx_num_outgoing_packets;i++)
643 if(!outpackets[i].ecb.in_use)
644 sendpacket= &outpackets[i];
645 //end this section replacement - Kevin Bently
647 // Fill in destination address
648 if ( memcmp( network, &ipx_network, 4 ) )
649 memcpy( sendpacket->ipx.destination.network_id, network, 4 );
651 memset( sendpacket->ipx.destination.network_id, 0, 4 );
652 memcpy( sendpacket->ipx.destination.node_id.address, address, 6 );
653 memcpy( sendpacket->ecb.immediate_address.address, immediate_address, 6 );
654 sendpacket->pd.packetnum = ipx_packetnum++;
656 // Fill in data to send
657 sendpacket->ecb.fragment_size = sizeof(ipx_header) + sizeof(int) + datasize;
659 assert( datasize > 1 );
660 assert( sendpacket->ecb.fragment_size <= 576 );
662 memcpy( sendpacket->pd.data, data, datasize );
665 ipx_send_packet( &sendpacket->ecb );
669 void ipx_send_broadcast_packet_data( ubyte * data, int datasize )
672 ubyte broadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
673 ubyte local_address[6];
675 // Set to all networks besides mine
676 for (i=0; i<Ipx_num_networks; i++ ) {
677 if ( memcmp( &Ipx_networks[i], &ipx_network, 4 ) ) {
678 ipx_get_local_target( (ubyte *)&Ipx_networks[i], broadcast, local_address );
679 ipx_send_packet_data( data, datasize, (ubyte *)&Ipx_networks[i], broadcast, local_address );
681 ipx_send_packet_data( data, datasize, (ubyte *)&Ipx_networks[i], broadcast, broadcast );
685 //OLDipx_send_packet_data( data, datasize, (ubyte *)&ipx_network, broadcast, broadcast );
687 // Send directly to all users not on my network or in the network list.
688 for (i=0; i<Ipx_num_users; i++ ) {
689 if ( memcmp( Ipx_users[i].network, &ipx_network, 4 ) ) {
690 for (j=0; j<Ipx_num_networks; j++ ) {
691 if (!memcmp( Ipx_users[i].network, &Ipx_networks[j], 4 ))
694 ipx_send_packet_data( data, datasize, Ipx_users[i].network, Ipx_users[i].node, Ipx_users[i].address );
701 // Sends a non-localized packet... needs 4 byte server, 6 byte address
702 void ipx_send_internetwork_packet_data( ubyte * data, int datasize, ubyte * server, ubyte *address )
704 ubyte local_address[6];
706 if ( (*(uint *)server) != 0 ) {
707 ipx_get_local_target( server, address, local_address );
708 ipx_send_packet_data( data, datasize, server, address, local_address );
710 // Old method, no server info.
711 ipx_send_packet_data( data, datasize, server, address, address );
715 int ipx_change_default_socket( ushort socket_number )
719 dpmi_real_regs rregs;
721 if ( !ipx_installed ) return -3;
724 memset(&rregs,0,sizeof(dpmi_real_regs));
725 swab( (char *)&socket_number,(char *)&new_ipx_socket, 2 );
726 rregs.edx = new_ipx_socket;
727 rregs.eax = ipx_socket_life;
728 rregs.ebx = 0; // Open socket
729 dpmi_real_int386x( 0x7A, &rregs );
731 new_ipx_socket = rregs.edx & 0xFFFF;
733 if ( rregs.eax & 0xFF ) {
734 //printf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
738 for (i=1; i<ipx_num_packets; i++ ) {
739 ipx_cancel_listen_for_packet(&packets[i].ecb);
742 // Close existing socket...
743 memset(&rregs,0,sizeof(dpmi_real_regs));
744 rregs.edx = ipx_socket;
745 rregs.ebx = 1; // Close socket
746 dpmi_real_int386x( 0x7A, &rregs );
748 ipx_socket = new_ipx_socket;
750 // Repost all listen requests on the new socket...
751 for (i=1; i<ipx_num_packets; i++ ) {
752 packets[i].ecb.in_use = 0;
753 packets[i].ecb.socket_id = ipx_socket;
754 ipx_listen_for_packet(&packets[i].ecb);
757 packets[0].ecb.socket_id = ipx_socket;
758 packets[0].ipx.destination.socket_id = ipx_socket;
761 // init packet buffers.
762 for (i=0; i<MAX_PACKETS; i++ ) {
763 packet_buffers[i].packetnum = -1;
764 packet_free_list[i] = i;
767 largest_packet_index = 0;
772 void ipx_read_user_file(char * filename)
776 char temp_line[132], *p1;
779 if (!filename) return;
783 fp = fopen( filename, "rt" );
786 printf( "Broadcast Users:\n" );
788 while (fgets(temp_line, 132, fp)) {
790 p1 = strchr(temp_line,'\n'); if (p1) *p1 = '\0';
791 p1 = strchr(temp_line,';'); if (p1) *p1 = '\0';
792 n = sscanf( temp_line, "%2x%2x%2x%2x/%2x%2x%2x%2x%2x%2x",(unsigned int *)&tmp.network[0],(unsigned int *) &tmp.network[1],(unsigned int *) &tmp.network[2],(unsigned int *) &tmp.network[3],(unsigned int *) &tmp.node[0],(unsigned int *) &tmp.node[1],(unsigned int *) &tmp.node[2],(unsigned int *)&tmp.node[3],(unsigned int *) &tmp.node[4],(unsigned int *) &tmp.node[5] );
793 // 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] );
794 if ( n != 10 ) continue;
795 if ( Ipx_num_users < MAX_USERS ) {
796 ubyte * ipx_real_buffer = (ubyte *)&tmp;
797 ipx_get_local_target( tmp.network, tmp.node, tmp.address );
798 Ipx_users[Ipx_num_users++] = tmp;
799 printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] );
800 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] );
802 printf( "Too many addresses in %s! (Limit of %d)\n", filename, MAX_USERS );
811 void ipx_read_network_file(char * filename)
815 char temp_line[132], *p1;
818 if (!filename) return;
820 fp = fopen( filename, "rt" );
823 printf( "Using Networks:\n" );
824 for (i=0; i<Ipx_num_networks; i++ ) {
825 ubyte * n1 = (ubyte *)&Ipx_networks[i];
826 printf("* %02x%02x%02x%02x\n", n1[0], n1[1], n1[2], n1[3] );
829 while (fgets(temp_line, 132, fp)) {
831 p1 = strchr(temp_line,'\n'); if (p1) *p1 = '\0';
832 p1 = strchr(temp_line,';'); if (p1) *p1 = '\0';
833 n = sscanf( temp_line, "%2x%2x%2x%2x",(unsigned int *) &tmp.network[0],(unsigned int *) &tmp.network[1],(unsigned int *) &tmp.network[2],(unsigned int *) &tmp.network[3] );
834 // n = sscanf( temp_line, "%2x%2x%2x%2x", &tmp.network[0], &tmp.network[1], &tmp.network[2], &tmp.network[3] );
835 if ( n != 4 ) continue;
836 if ( Ipx_num_networks < MAX_NETWORKS ) {
838 for (j=0; j<Ipx_num_networks; j++ )
839 if ( !memcmp( &Ipx_networks[j], tmp.network, 4 ) )
841 if ( j >= Ipx_num_networks ) {
842 memcpy( &Ipx_networks[Ipx_num_networks++], tmp.network, 4 );
843 printf(" %02x%02x%02x%02x\n", tmp.network[0], tmp.network[1], tmp.network[2], tmp.network[3] );
846 printf( "Too many networks in %s! (Limit of %d)\n", filename, MAX_NETWORKS );
855 //---typedef struct rip_entry {
861 //---typedef struct rip_packet {
862 //--- ushort operation; //1=request, 2=response
863 //--- rip_entry rip[50];
867 //---void ipx_find_all_servers()
870 //--- rip_packet * rp;
871 //--- assert(ipx_installed);
873 //--- ipx_change_default_socket( 0x0453 );
874 //--- // ipx_change_default_socket( 0x5304 );
876 //--- // Make sure no one is already sending something
877 //--- while( packets[0].ecb.in_use )
881 //--- if (packets[0].ecb.completion_code) {
882 //--- printf( "AAAA:Send error %d for completion code\n", packets[0].ecb.completion_code );
886 //--- rp = (rip_packet *)&packets[0].pd;
888 //--- // Fill in destination address
890 //--- char mzero1[] = {0,0,0,1};
891 //--- char mzero[] = {0,0,0,0,0,1};
892 //--- char immediate[6];
893 //--- //memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
894 //--- //memcpy( packets[0].ipx.destination.node_id.address, ipx_my_node.address, 6 );
896 //--- memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
897 //--- memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
899 //--- memcpy( packets[0].ipx.destination.socket_id, &ipx_socket, 2 );
900 //--- memcpy( packets[0].ipx.source.network_id, &ipx_network, 4 );
901 //--- memcpy( packets[0].ipx.source.node_id.address, ipx_my_node.address, 6 );
902 //--- memcpy( packets[0].ipx.source.socket_id, &ipx_socket, 2 );
903 //--- //memcpy( packets[0].ecb.immediate_address.address, ipx_my_node.address, 6 );
904 //--- //mzero1[3] = 1;
905 //--- //memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
906 //--- //mzero[5] = 1;
907 //--- //memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
908 //--- //ipx_get_local_target( mzero1, mzero, immediate );
909 //--- //memcpy( packets[0].ecb.immediate_address.address, mzero, 6 );
910 //--- //memcpy( packets[0].ecb.immediate_address.address, immediate, 6 );
911 //--- //mzero[5] = 0;
914 //--- packets[0].ipx.packet_type = 1; // RIP packet
916 //--- // Fill in data to send
917 //--- packets[0].ecb.fragment_size = sizeof(ipx_header) + sizeof(rip_packet);
918 //--- assert( packets[0].ecb.fragment_size <= 576 );
920 //--- rp->operation = 0; // Request
921 //--- for (i=0;i<50; i++) {
922 //--- rp->rip[i].network = 0xFFFFFFFF;
923 //--- rp->rip[i].nhops = 0;
924 //--- rp->rip[i].nticks = 0;
928 //--- ipx_send_packet( &packets[0].ecb );
930 //--- for (i=0;i<50; i++) {
931 //--- if ( rp->rip[i].network != 0xFFFFFFFF )
932 //--- printf( "Network = %8x, Hops=%d, Ticks=%d\n", rp->rip[i].network, rp->rip[i].nhops, rp->rip[i].nticks );