1 /* $Id: ipx.c,v 1.2 2003-10-03 03:37:43 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Routines for IPX communications.
20 * Revision 2.10 1995/03/29 17:27:55 john
21 * Added code to not duplicate broadcasts.
23 * Revision 2.9 1995/03/29 15:32:07 john
26 * Revision 2.8 1995/03/29 15:07:31 john
27 * Added network support.
29 * Revision 2.7 1995/03/29 11:22:27 john
30 * Added broadcasting over a net.
32 * Revision 2.6 1995/03/28 20:05:03 john
33 * Took away alternate server stuff.
35 * Revision 2.5 1995/03/23 19:14:29 john
36 * Added better MAX_USERS message.
38 * Revision 2.4 1995/03/23 19:00:02 john
39 * Added user list capabitly.
41 * Revision 2.3 1995/03/23 12:27:05 john
42 * Move IPX into bios lib.
44 * Revision 2.2 1995/03/22 19:08:15 john
45 * Added code to fix sending packets over router... now
46 * we just need to make broadcasts go over router!!
48 * Revision 2.1 1995/03/21 08:40:16 john
49 * Ifdef'd out the NETWORK code.
51 * Revision 2.0 1995/02/27 11:30:45 john
52 * New version 2.0, which has no anonymous unions, builds with
53 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
55 * Revision 1.31 1995/02/16 17:35:03 john
56 * Added code to allow dynamic socket changing.
58 * Revision 1.30 1995/02/01 21:03:45 john
61 * Revision 1.29 1995/01/22 14:31:05 john
64 * Revision 1.28 1995/01/22 14:29:26 john
65 * Added code to bypass broadcast messages.
67 * Revision 1.27 1995/01/03 13:46:16 john
68 * Added code that should make ipx work over different servers,
69 * but ifdef'd it out with SHAREWARE in ipx.c. I haven't tested
70 * this, and I hope it doesn't introduce net bugs.
72 * Revision 1.26 1994/12/14 11:54:37 rob
73 * Reduce # of ipx packets.
75 * Revision 1.25 1994/12/11 00:43:28 john
76 * Locked down DOS ipx buffers... probably not necessary, tho.
78 * Revision 1.24 1994/12/08 15:49:58 rob
79 * Bumped up the # of ipx packets.
81 * Revision 1.23 1994/12/04 15:23:54 rob
82 * Reduced packet # constants.
84 * Revision 1.22 1994/11/27 23:12:39 matt
85 * Made changes for new mprintf calling convention
87 * Revision 1.21 1994/11/19 15:15:19 mike
88 * remove unused code and data
90 * Revision 1.20 1994/11/10 11:06:07 rob
91 * Raised number of ipx packets to 64 and buffers to 128 (for 8-way games)
92 * Removed (commented out) all the spx support stuff.
94 * Revision 1.19 1994/11/07 17:50:12 rob
95 * Bumped up max_packets and ipx_num_packets to double their previous
98 * Revision 1.18 1994/11/07 15:39:01 rob
99 * Removed temporary hacked ipx_send_object function.
100 * Replaced with a more general thing.
102 * Revision 1.17 1994/11/05 16:08:40 rob
103 * Made a change necessary for object syncing on rejoin.
105 * Revision 1.16 1994/11/01 15:57:12 rob
106 * Added support for SPX sockets for critical messages.
108 * Revision 1.15 1994/10/31 19:21:01 rob
109 * Added a routine for sending objects via ipx. Its a hack and shoukld
110 * be replaced by something more general time permitting.
112 * Revision 1.14 1994/10/20 14:57:42 john
115 * Revision 1.13 1994/10/20 11:22:45 john
116 * Tweaked the number of waiting packets. Added code to print
117 * total packets missed, and to limit the packet send rate to
118 * 10 packets per second unless firing.
120 * Revision 1.12 1994/10/03 20:50:11 john
121 * Started adding sound pause functions.
123 * Revision 1.11 1994/09/15 08:54:24 mike
124 * comment out a mprintf.
126 * Revision 1.10 1994/09/12 19:38:20 john
127 * Made some stuff that prints to the DOS screen go to the
128 * mono instead, since it really is debugging info.
130 * Revision 1.9 1994/09/07 13:32:03 john
131 * Made ipx_close explicitly close the socket we were using,
132 * because it seems that VLM's don't automatically close them
133 * like the older NETX stuff did (Going from Novell 3.11 driver
136 * Revision 1.8 1994/09/06 19:29:20 john
137 * Added trial version of rejoin function.
139 * Revision 1.7 1994/08/09 19:31:50 john
140 * Networking changes.
142 * Revision 1.6 1994/08/05 16:11:41 john
143 * Psuedo working version of networking.
145 * Revision 1.5 1994/08/04 19:17:21 john
146 * Inbetween version of network stuff.
148 * Revision 1.4 1994/07/29 16:08:57 john
149 * *** empty log message ***
151 * Revision 1.3 1994/07/25 12:33:31 john
152 * Network "pinging" in.
154 * Revision 1.2 1994/07/20 15:58:28 john
155 * First installment of ipx stuff.
157 * Revision 1.1 1994/07/19 15:42:00 john
164 static char rcsid[] = "$Id: ipx.c,v 1.2 2003-10-03 03:37:43 btb Exp $";
168 #define _BORLAND_DOS_REGS 1
188 typedef unsigned char BYTE;
189 typedef unsigned short WORD;
190 typedef unsigned long DWORD;
192 typedef struct local_address {
194 } __pack__ local_address;
196 typedef struct net_address {
198 local_address node_id;
200 } __pack__ net_address;
202 typedef struct ipx_header {
205 BYTE transport_control;
207 net_address destination;
209 } __pack__ ipx_header;
211 typedef struct ecb_header {
215 BYTE completion_code;
217 BYTE ipx_reserved[14];
219 local_address immediate_address;
221 WORD fragment_pointer[2];
223 } __pack__ ecb_header;
225 typedef struct packet_data {
227 byte data[IPX_MAX_DATA_SIZE];
228 } __pack__ packet_data;
230 typedef struct ipx_packet {
234 } __pack__ ipx_packet;
236 typedef struct user_address {
240 } __pack__ user_address;
243 int Ipx_num_users = 0;
244 user_address Ipx_users[MAX_USERS];
246 #define MAX_NETWORKS 64
247 int Ipx_num_networks = 0;
248 uint Ipx_networks[MAX_NETWORKS];
250 int ipx_packetnum = 0;
252 #define MAX_PACKETS 64
254 static packet_data packet_buffers[MAX_PACKETS];
255 static short packet_free_list[MAX_PACKETS];
256 static int num_packets = 0;
257 static int largest_packet_index = 0;
258 static short packet_size[MAX_PACKETS];
260 //added on 10/29/98 by Kevin Bently to add ipx stuff
261 WORD ipx_num_outgoing_packets = 8;
262 ipx_packet * outpackets;
263 //end this section addition - Kevin Bently
266 ubyte ipx_installed=0;
267 WORD ipx_vector_segment;
268 WORD ipx_vector_offset;
269 ubyte ipx_socket_life = 0; // 0=closed at prog termination, 0xff=closed when requested.
270 DWORD ipx_network = 0;
271 local_address ipx_my_node;
272 WORD ipx_num_packets=32; // 32 Ipx packets
273 ipx_packet * packets;
275 ushort ipx_packets_selector;
277 ecb_header * last_ecb=NULL;
280 void got_new_packet( ecb_header * ecb );
281 void ipx_listen_for_packet(ecb_header * ecb );
283 void free_packet( int id )
285 packet_buffers[id].packetnum = -1;
286 packet_free_list[ --num_packets ] = id;
287 if (largest_packet_index==id)
288 while ((--largest_packet_index>0) && (packet_buffers[largest_packet_index].packetnum == -1 ));
291 int ipx_get_packet_data( ubyte * data )
293 int i, n, best, best_id, size;
295 for (i=1; i<ipx_num_packets; i++ ) {
296 if ( !packets[i].ecb.in_use ) {
297 got_new_packet( &packets[i].ecb );
298 packets[i].ecb.in_use = 0;
299 ipx_listen_for_packet(&packets[i].ecb);
307 for (i=0; i<=largest_packet_index; i++ ) {
308 if ( packet_buffers[i].packetnum > -1 ) {
310 if ( best == -1 || (packet_buffers[i].packetnum<best) ) {
311 best = packet_buffers[i].packetnum;
317 //mprintf( (0, "Best id = %d, pn = %d, last_ecb = %x, len=%x, ne = %d\n", best_id, best, last_ecb, lastlen, neterrors ));
318 //mprintf( (1, "<%d> ", neterrors ));
320 if ( best_id < 0 ) return 0;
322 size = packet_size[best_id];
323 memcpy( data, packet_buffers[best_id].data, size );
324 free_packet(best_id);
330 unsigned int swap_short( unsigned int short )
331 #pragma aux swap_short parm [eax] = "xchg al,ah";
333 static inline unsigned int swap_short( unsigned int sshort ) {
335 asm("xchg %%ah,%%al" : "=a" (__retval) : "a" (sshort));
340 void got_new_packet( ecb_header * ecb )
344 unsigned short datasize;
348 p = (ipx_packet *)ecb;
350 if ( p->ecb.in_use ) { neterrors++; return; }
351 if ( p->ecb.completion_code ) { neterrors++; return; }
353 // Error( "Recieve error %d for completion code", p->ecb.completion_code );
355 if ( memcmp( &p->ipx.source.node_id, &ipx_my_node, 6 ) ) {
356 datasize=swap_short(p->ipx.length);
358 datasize -= sizeof(ipx_header);
359 // Find slot to put packet in...
360 if ( datasize > 0 && datasize <= sizeof(packet_data) ) {
361 if ( num_packets >= MAX_PACKETS ) {
362 //printf( 1, "IPX: Packet buffer overrun!!!\n" );
366 id = packet_free_list[ num_packets++ ];
367 if (id > largest_packet_index ) largest_packet_index = id;
368 packet_size[id] = datasize-sizeof(int);
369 packet_buffers[id].packetnum = p->pd.packetnum;
370 if ( packet_buffers[id].packetnum < 0 ) { neterrors++; return; }
371 memcpy( packet_buffers[id].data, p->pd.data, packet_size[id] );
378 //ipx_listen_for_packet(&p->ecb);
381 ubyte * ipx_get_my_local_address()
383 return ipx_my_node.address;
386 ubyte * ipx_get_my_server_address()
388 return (ubyte *)&ipx_network;
391 void ipx_listen_for_packet(ecb_header * ecb )
393 dpmi_real_regs rregs;
395 memset(&rregs,0,sizeof(dpmi_real_regs));
396 rregs.ebx = 4; // Listen For Packet function
397 rregs.esi = DPMI_real_offset(ecb);
398 rregs.es = DPMI_real_segment(ecb);
399 dpmi_real_int386x( 0x7A, &rregs );
402 void ipx_cancel_listen_for_packet(ecb_header * ecb )
404 dpmi_real_regs rregs;
405 memset(&rregs,0,sizeof(dpmi_real_regs));
406 rregs.ebx = 6; // IPX Cancel event
407 rregs.esi = DPMI_real_offset(ecb);
408 rregs.es = DPMI_real_segment(ecb);
409 dpmi_real_int386x( 0x7A, &rregs );
413 void ipx_send_packet(ecb_header * ecb )
415 dpmi_real_regs rregs;
416 memset(&rregs,0,sizeof(dpmi_real_regs));
417 rregs.ebx = 3; // Send Packet function
418 rregs.esi = DPMI_real_offset(ecb);
419 rregs.es = DPMI_real_segment(ecb);
420 dpmi_real_int386x( 0x7A, &rregs );
426 ubyte local_target[6];
427 } __pack__ net_xlat_info;
429 void ipx_get_local_target( ubyte * server, ubyte * node, ubyte * local_target )
431 net_xlat_info * info;
432 dpmi_real_regs rregs;
434 // Get dos memory for call...
435 info = (net_xlat_info *)dpmi_get_temp_low_buffer( sizeof(net_xlat_info) );
436 assert( info != NULL );
437 memcpy( info->network, server, 4 );
438 memcpy( info->node, node, 6 );
440 memset(&rregs,0,sizeof(dpmi_real_regs));
442 rregs.ebx = 2; // Get Local Target
443 rregs.es = DPMI_real_segment(info);
444 rregs.esi = DPMI_real_offset(info->network);
445 rregs.edi = DPMI_real_offset(info->local_target);
447 dpmi_real_int386x( 0x7A, &rregs );
449 // Save the local target...
450 memcpy( local_target, info->local_target, 6 );
455 dpmi_real_regs rregs;
456 if ( ipx_installed ) {
457 // When using VLM's instead of NETX, the sockets don't
458 // seem to automatically get closed, so we must explicitly
459 // close them at program termination.
461 memset(&rregs,0,sizeof(dpmi_real_regs));
462 rregs.edx = ipx_socket;
463 rregs.ebx = 1; // Close socket
464 dpmi_real_int386x( 0x7A, &rregs );
469 //---------------------------------------------------------------
470 // Initializes all IPX internals.
471 // If socket_number==0, then opens next available socket.
472 // Returns: 0 if successful.
473 // -1 if socket already open.
474 // -2 if socket table full.
475 // -3 if IPX not installed.
476 // -4 if couldn't allocate low dos memory
477 // -5 if error with getting internetwork address
479 int ipx_init( int socket_number, int show_address )
481 dpmi_real_regs rregs;
482 ubyte *ipx_real_buffer;
489 // init packet buffers.
490 for (i=0; i<MAX_PACKETS; i++ ) {
491 packet_buffers[i].packetnum = -1;
492 packet_free_list[i] = i;
495 largest_packet_index = 0;
497 // Get the IPX vector
498 memset(&rregs,0,sizeof(dpmi_real_regs));
499 rregs.eax=0x00007a00;
500 dpmi_real_int386x( 0x2f, &rregs );
502 if ( (rregs.eax & 0xFF) != 0xFF ) {
505 ipx_vector_offset = rregs.edi & 0xFFFF;
506 ipx_vector_segment = rregs.es;
507 //printf( "IPX entry point at %.4x:%.4x\n", ipx_vector_segment, ipx_vector_offset );
509 // Open a socket for IPX
511 memset(&rregs,0,sizeof(dpmi_real_regs));
512 swab( (char *)&socket_number,(char *)&ipx_socket, 2 );
513 rregs.edx = ipx_socket;
514 rregs.eax = ipx_socket_life;
515 rregs.ebx = 0; // Open socket
516 dpmi_real_int386x( 0x7A, &rregs );
518 ipx_socket = rregs.edx & 0xFFFF;
520 if ( rregs.eax & 0xFF ) {
521 //mprintf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
527 // Find our internetwork address
528 ipx_real_buffer = dpmi_get_temp_low_buffer( 1024 ); // 1k block
529 if ( ipx_real_buffer == NULL ) {
530 //printf( "Error allocation realmode memory\n" );
534 memset(&rregs,0,sizeof(dpmi_real_regs));
535 rregs.ebx = 9; // Get internetwork address
536 rregs.esi = DPMI_real_offset(ipx_real_buffer);
537 rregs.es = DPMI_real_segment(ipx_real_buffer);
538 dpmi_real_int386x( 0x7A, &rregs );
540 if ( rregs.eax & 0xFF ) {
541 //printf( "Error getting internetwork address!\n" );
545 memcpy( &ipx_network, ipx_real_buffer, 4 );
546 memcpy( &ipx_my_node, &ipx_real_buffer[4], 6 );
548 Ipx_num_networks = 0;
549 memcpy( &Ipx_networks[Ipx_num_networks++], &ipx_network, 4 );
551 if ( show_address ) {
552 printf( "My IPX addresss is " );
553 printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] );
554 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] );
558 packets = dpmi_real_malloc( sizeof(ipx_packet)*ipx_num_packets, &ipx_packets_selector );
559 if ( packets == NULL ) {
560 //printf( "Couldn't allocate real memory for %d packets\n", ipx_num_packets );
563 #if 0 /* adb: not needed, fails with cwsdpmi */
564 if (!dpmi_lock_region( packets, sizeof(ipx_packet)*ipx_num_packets )) {
565 //printf( "Couldn't lock real memory for %d packets\n", ipx_num_packets );
569 memset( packets, 0, sizeof(ipx_packet)*ipx_num_packets );
571 for (i=1; i<ipx_num_packets; i++ ) {
572 packets[i].ecb.in_use = 0x1d;
573 //packets[i].ecb.in_use = 0;
574 packets[i].ecb.socket_id = ipx_socket;
575 packets[i].ecb.fragment_count = 1;
576 packets[i].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[i].ipx);
577 packets[i].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[i].ipx);
578 packets[i].ecb.fragment_size = sizeof(ipx_packet)-sizeof(ecb_header); //-sizeof(ecb_header);
580 ipx_listen_for_packet(&packets[i].ecb);
583 //added/replaced on 10/29/98 by Kevin Bently for new ipx stuff
584 //-killed- packets[0].ecb.socket_id = ipx_socket;
585 //-killed- packets[0].ecb.fragment_count = 1;
586 //-killed- packets[0].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[0].ipx);
587 //-killed- packets[0].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[0].ipx);
588 //-killed- packets[0].ipx.packet_type = 4; // IPX packet
589 //-killed- packets[0].ipx.destination.socket_id = ipx_socket;
590 //-killed-// memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
591 //-killed- memset( packets[0].ipx.destination.network_id, 0, 4 );
592 outpackets = dpmi_real_malloc( sizeof(ipx_packet)*ipx_num_packets, &ipx_packets_selector);
594 for(i=0;i<ipx_num_outgoing_packets;i++)
596 outpackets[i].ecb.socket_id = ipx_socket;
597 outpackets[i].ecb.fragment_count = 1;
598 outpackets[i].ecb.fragment_pointer[0] = DPMI_real_offset(&outpackets[i].ipx);
599 outpackets[i].ecb.fragment_pointer[1] = DPMI_real_segment(&outpackets[i].ipx);
600 outpackets[i].ipx.packet_type = 4; // IPX packet
601 outpackets[i].ipx.destination.socket_id = ipx_socket;
602 memset( outpackets[i].ipx.destination.network_id, 0, 4 );
606 //end this section replace - Kevin Bently
610 void ipx_send_packet_data( ubyte * data, int datasize, ubyte *network, ubyte *address, ubyte *immediate_address )
613 ipx_packet *sendpacket = NULL;
615 assert(ipx_installed);
617 if ( datasize >= IPX_MAX_DATA_SIZE ) {
618 printf( "Data too big\n" );
624 //added/replaced on 10/29/98 by Kevin Bently for new ipx stuff
625 //-killed- // Make sure no one is already sending something
626 //-killed- while( packets[0].ecb.in_use )
630 //-killed- if (packets[0].ecb.completion_code) {
631 //-killed- printf( "Send error %d for completion code\n", packets[0].ecb.completion_code );
632 //-killed- //killed on 10/25/98 by Victor Rachels to fix LAN crash
633 //-killed- //-killed- exit(1);
634 //-killed- //end this section kill - Victor
637 for(i=0;i<ipx_num_outgoing_packets;i++)
638 if(!outpackets[i].ecb.in_use)
639 sendpacket= &outpackets[i];
640 //end this section replacement - Kevin Bently
642 // Fill in destination address
643 if ( memcmp( network, &ipx_network, 4 ) )
644 memcpy( sendpacket->ipx.destination.network_id, network, 4 );
646 memset( sendpacket->ipx.destination.network_id, 0, 4 );
647 memcpy( sendpacket->ipx.destination.node_id.address, address, 6 );
648 memcpy( sendpacket->ecb.immediate_address.address, immediate_address, 6 );
649 sendpacket->pd.packetnum = ipx_packetnum++;
651 // Fill in data to send
652 sendpacket->ecb.fragment_size = sizeof(ipx_header) + sizeof(int) + datasize;
654 assert( datasize > 1 );
655 assert( sendpacket->ecb.fragment_size <= 576 );
657 memcpy( sendpacket->pd.data, data, datasize );
660 ipx_send_packet( &sendpacket->ecb );
664 void ipx_send_broadcast_packet_data( ubyte * data, int datasize )
667 ubyte broadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
668 ubyte local_address[6];
670 // Set to all networks besides mine
671 for (i=0; i<Ipx_num_networks; i++ ) {
672 if ( memcmp( &Ipx_networks[i], &ipx_network, 4 ) ) {
673 ipx_get_local_target( (ubyte *)&Ipx_networks[i], broadcast, local_address );
674 ipx_send_packet_data( data, datasize, (ubyte *)&Ipx_networks[i], broadcast, local_address );
676 ipx_send_packet_data( data, datasize, (ubyte *)&Ipx_networks[i], broadcast, broadcast );
680 //OLDipx_send_packet_data( data, datasize, (ubyte *)&ipx_network, broadcast, broadcast );
682 // Send directly to all users not on my network or in the network list.
683 for (i=0; i<Ipx_num_users; i++ ) {
684 if ( memcmp( Ipx_users[i].network, &ipx_network, 4 ) ) {
685 for (j=0; j<Ipx_num_networks; j++ ) {
686 if (!memcmp( Ipx_users[i].network, &Ipx_networks[j], 4 ))
689 ipx_send_packet_data( data, datasize, Ipx_users[i].network, Ipx_users[i].node, Ipx_users[i].address );
696 // Sends a non-localized packet... needs 4 byte server, 6 byte address
697 void ipx_send_internetwork_packet_data( ubyte * data, int datasize, ubyte * server, ubyte *address )
699 ubyte local_address[6];
701 if ( (*(uint *)server) != 0 ) {
702 ipx_get_local_target( server, address, local_address );
703 ipx_send_packet_data( data, datasize, server, address, local_address );
705 // Old method, no server info.
706 ipx_send_packet_data( data, datasize, server, address, address );
710 int ipx_change_default_socket( ushort socket_number )
714 dpmi_real_regs rregs;
716 if ( !ipx_installed ) return -3;
719 memset(&rregs,0,sizeof(dpmi_real_regs));
720 swab( (char *)&socket_number,(char *)&new_ipx_socket, 2 );
721 rregs.edx = new_ipx_socket;
722 rregs.eax = ipx_socket_life;
723 rregs.ebx = 0; // Open socket
724 dpmi_real_int386x( 0x7A, &rregs );
726 new_ipx_socket = rregs.edx & 0xFFFF;
728 if ( rregs.eax & 0xFF ) {
729 //printf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
733 for (i=1; i<ipx_num_packets; i++ ) {
734 ipx_cancel_listen_for_packet(&packets[i].ecb);
737 // Close existing socket...
738 memset(&rregs,0,sizeof(dpmi_real_regs));
739 rregs.edx = ipx_socket;
740 rregs.ebx = 1; // Close socket
741 dpmi_real_int386x( 0x7A, &rregs );
743 ipx_socket = new_ipx_socket;
745 // Repost all listen requests on the new socket...
746 for (i=1; i<ipx_num_packets; i++ ) {
747 packets[i].ecb.in_use = 0;
748 packets[i].ecb.socket_id = ipx_socket;
749 ipx_listen_for_packet(&packets[i].ecb);
752 packets[0].ecb.socket_id = ipx_socket;
753 packets[0].ipx.destination.socket_id = ipx_socket;
756 // init packet buffers.
757 for (i=0; i<MAX_PACKETS; i++ ) {
758 packet_buffers[i].packetnum = -1;
759 packet_free_list[i] = i;
762 largest_packet_index = 0;
767 void ipx_read_user_file(char * filename)
771 char temp_line[132], *p1;
774 if (!filename) return;
778 fp = fopen( filename, "rt" );
781 printf( "Broadcast Users:\n" );
783 while (fgets(temp_line, 132, fp)) {
785 p1 = strchr(temp_line,'\n'); if (p1) *p1 = '\0';
786 p1 = strchr(temp_line,';'); if (p1) *p1 = '\0';
787 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] );
788 // 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] );
789 if ( n != 10 ) continue;
790 if ( Ipx_num_users < MAX_USERS ) {
791 ubyte * ipx_real_buffer = (ubyte *)&tmp;
792 ipx_get_local_target( tmp.network, tmp.node, tmp.address );
793 Ipx_users[Ipx_num_users++] = tmp;
794 printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] );
795 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] );
797 printf( "Too many addresses in %s! (Limit of %d)\n", filename, MAX_USERS );
806 void ipx_read_network_file(char * filename)
810 char temp_line[132], *p1;
813 if (!filename) return;
815 fp = fopen( filename, "rt" );
818 printf( "Using Networks:\n" );
819 for (i=0; i<Ipx_num_networks; i++ ) {
820 ubyte * n1 = (ubyte *)&Ipx_networks[i];
821 printf("* %02x%02x%02x%02x\n", n1[0], n1[1], n1[2], n1[3] );
824 while (fgets(temp_line, 132, fp)) {
826 p1 = strchr(temp_line,'\n'); if (p1) *p1 = '\0';
827 p1 = strchr(temp_line,';'); if (p1) *p1 = '\0';
828 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] );
829 // n = sscanf( temp_line, "%2x%2x%2x%2x", &tmp.network[0], &tmp.network[1], &tmp.network[2], &tmp.network[3] );
830 if ( n != 4 ) continue;
831 if ( Ipx_num_networks < MAX_NETWORKS ) {
833 for (j=0; j<Ipx_num_networks; j++ )
834 if ( !memcmp( &Ipx_networks[j], tmp.network, 4 ) )
836 if ( j >= Ipx_num_networks ) {
837 memcpy( &Ipx_networks[Ipx_num_networks++], tmp.network, 4 );
838 printf(" %02x%02x%02x%02x\n", tmp.network[0], tmp.network[1], tmp.network[2], tmp.network[3] );
841 printf( "Too many networks in %s! (Limit of %d)\n", filename, MAX_NETWORKS );
850 //---typedef struct rip_entry {
856 //---typedef struct rip_packet {
857 //--- ushort operation; //1=request, 2=response
858 //--- rip_entry rip[50];
862 //---void ipx_find_all_servers()
865 //--- rip_packet * rp;
866 //--- assert(ipx_installed);
868 //--- ipx_change_default_socket( 0x0453 );
869 //--- // ipx_change_default_socket( 0x5304 );
871 //--- // Make sure no one is already sending something
872 //--- while( packets[0].ecb.in_use )
876 //--- if (packets[0].ecb.completion_code) {
877 //--- printf( "AAAA:Send error %d for completion code\n", packets[0].ecb.completion_code );
881 //--- rp = (rip_packet *)&packets[0].pd;
883 //--- // Fill in destination address
885 //--- char mzero1[] = {0,0,0,1};
886 //--- char mzero[] = {0,0,0,0,0,1};
887 //--- char immediate[6];
888 //--- //memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
889 //--- //memcpy( packets[0].ipx.destination.node_id.address, ipx_my_node.address, 6 );
891 //--- memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
892 //--- memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
894 //--- memcpy( packets[0].ipx.destination.socket_id, &ipx_socket, 2 );
895 //--- memcpy( packets[0].ipx.source.network_id, &ipx_network, 4 );
896 //--- memcpy( packets[0].ipx.source.node_id.address, ipx_my_node.address, 6 );
897 //--- memcpy( packets[0].ipx.source.socket_id, &ipx_socket, 2 );
898 //--- //memcpy( packets[0].ecb.immediate_address.address, ipx_my_node.address, 6 );
899 //--- //mzero1[3] = 1;
900 //--- //memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
901 //--- //mzero[5] = 1;
902 //--- //memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
903 //--- //ipx_get_local_target( mzero1, mzero, immediate );
904 //--- //memcpy( packets[0].ecb.immediate_address.address, mzero, 6 );
905 //--- //memcpy( packets[0].ecb.immediate_address.address, immediate, 6 );
906 //--- //mzero[5] = 0;
909 //--- packets[0].ipx.packet_type = 1; // RIP packet
911 //--- // Fill in data to send
912 //--- packets[0].ecb.fragment_size = sizeof(ipx_header) + sizeof(rip_packet);
913 //--- assert( packets[0].ecb.fragment_size <= 576 );
915 //--- rp->operation = 0; // Request
916 //--- for (i=0;i<50; i++) {
917 //--- rp->rip[i].network = 0xFFFFFFFF;
918 //--- rp->rip[i].nhops = 0;
919 //--- rp->rip[i].nticks = 0;
923 //--- ipx_send_packet( &packets[0].ecb );
925 //--- for (i=0;i<50; i++) {
926 //--- if ( rp->rip[i].network != 0xFFFFFFFF )
927 //--- printf( "Network = %8x, Hops=%d, Ticks=%d\n", rp->rip[i].network, rp->rip[i].nhops, rp->rip[i].nticks );