1 /* $Id: ipx.c,v 1.3 2003-10-03 07:58:14 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.3 2003-10-03 07:58:14 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 one of the constants defined in include/ipx.h
474 int ipx_init( int socket_number, int show_address )
476 dpmi_real_regs rregs;
477 ubyte *ipx_real_buffer;
484 // init packet buffers.
485 for (i=0; i<MAX_PACKETS; i++ ) {
486 packet_buffers[i].packetnum = -1;
487 packet_free_list[i] = i;
490 largest_packet_index = 0;
492 // Get the IPX vector
493 memset(&rregs,0,sizeof(dpmi_real_regs));
494 rregs.eax=0x00007a00;
495 dpmi_real_int386x( 0x2f, &rregs );
497 if ( (rregs.eax & 0xFF) != 0xFF ) {
498 return IPX_NOT_INSTALLED;
500 ipx_vector_offset = rregs.edi & 0xFFFF;
501 ipx_vector_segment = rregs.es;
502 //printf( "IPX entry point at %.4x:%.4x\n", ipx_vector_segment, ipx_vector_offset );
504 // Open a socket for IPX
506 memset(&rregs,0,sizeof(dpmi_real_regs));
507 swab( (char *)&socket_number,(char *)&ipx_socket, 2 );
508 rregs.edx = ipx_socket;
509 rregs.eax = ipx_socket_life;
510 rregs.ebx = 0; // Open socket
511 dpmi_real_int386x( 0x7A, &rregs );
513 ipx_socket = rregs.edx & 0xFFFF;
515 if ( rregs.eax & 0xFF ) {
516 //mprintf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
517 return IPX_SOCKET_TABLE_FULL;
522 // Find our internetwork address
523 ipx_real_buffer = dpmi_get_temp_low_buffer( 1024 ); // 1k block
524 if ( ipx_real_buffer == NULL ) {
525 //printf( "Error allocation realmode memory\n" );
526 return IPX_NO_LOW_DOS_MEM;
529 memset(&rregs,0,sizeof(dpmi_real_regs));
530 rregs.ebx = 9; // Get internetwork address
531 rregs.esi = DPMI_real_offset(ipx_real_buffer);
532 rregs.es = DPMI_real_segment(ipx_real_buffer);
533 dpmi_real_int386x( 0x7A, &rregs );
535 if ( rregs.eax & 0xFF ) {
536 //printf( "Error getting internetwork address!\n" );
537 return IPX_SOCKET_TABLE_FULL;
540 memcpy( &ipx_network, ipx_real_buffer, 4 );
541 memcpy( &ipx_my_node, &ipx_real_buffer[4], 6 );
543 Ipx_num_networks = 0;
544 memcpy( &Ipx_networks[Ipx_num_networks++], &ipx_network, 4 );
546 if ( show_address ) {
547 printf( "My IPX addresss is " );
548 printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] );
549 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] );
553 packets = dpmi_real_malloc( sizeof(ipx_packet)*ipx_num_packets, &ipx_packets_selector );
554 if ( packets == NULL ) {
555 //printf( "Couldn't allocate real memory for %d packets\n", ipx_num_packets );
556 return IPX_NO_LOW_DOS_MEM;
558 #if 0 /* adb: not needed, fails with cwsdpmi */
559 if (!dpmi_lock_region( packets, sizeof(ipx_packet)*ipx_num_packets )) {
560 //printf( "Couldn't lock real memory for %d packets\n", ipx_num_packets );
561 return IPX_NO_LOW_DOS_MEM;
564 memset( packets, 0, sizeof(ipx_packet)*ipx_num_packets );
566 for (i=1; i<ipx_num_packets; i++ ) {
567 packets[i].ecb.in_use = 0x1d;
568 //packets[i].ecb.in_use = 0;
569 packets[i].ecb.socket_id = ipx_socket;
570 packets[i].ecb.fragment_count = 1;
571 packets[i].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[i].ipx);
572 packets[i].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[i].ipx);
573 packets[i].ecb.fragment_size = sizeof(ipx_packet)-sizeof(ecb_header); //-sizeof(ecb_header);
575 ipx_listen_for_packet(&packets[i].ecb);
578 //added/replaced on 10/29/98 by Kevin Bently for new ipx stuff
579 //-killed- packets[0].ecb.socket_id = ipx_socket;
580 //-killed- packets[0].ecb.fragment_count = 1;
581 //-killed- packets[0].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[0].ipx);
582 //-killed- packets[0].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[0].ipx);
583 //-killed- packets[0].ipx.packet_type = 4; // IPX packet
584 //-killed- packets[0].ipx.destination.socket_id = ipx_socket;
585 //-killed-// memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
586 //-killed- memset( packets[0].ipx.destination.network_id, 0, 4 );
587 outpackets = dpmi_real_malloc( sizeof(ipx_packet)*ipx_num_packets, &ipx_packets_selector);
589 for(i=0;i<ipx_num_outgoing_packets;i++)
591 outpackets[i].ecb.socket_id = ipx_socket;
592 outpackets[i].ecb.fragment_count = 1;
593 outpackets[i].ecb.fragment_pointer[0] = DPMI_real_offset(&outpackets[i].ipx);
594 outpackets[i].ecb.fragment_pointer[1] = DPMI_real_segment(&outpackets[i].ipx);
595 outpackets[i].ipx.packet_type = 4; // IPX packet
596 outpackets[i].ipx.destination.socket_id = ipx_socket;
597 memset( outpackets[i].ipx.destination.network_id, 0, 4 );
601 //end this section replace - Kevin Bently
605 void ipx_send_packet_data( ubyte * data, int datasize, ubyte *network, ubyte *address, ubyte *immediate_address )
608 ipx_packet *sendpacket = NULL;
610 assert(ipx_installed);
612 if ( datasize >= IPX_MAX_DATA_SIZE ) {
613 printf( "Data too big\n" );
619 //added/replaced on 10/29/98 by Kevin Bently for new ipx stuff
620 //-killed- // Make sure no one is already sending something
621 //-killed- while( packets[0].ecb.in_use )
625 //-killed- if (packets[0].ecb.completion_code) {
626 //-killed- printf( "Send error %d for completion code\n", packets[0].ecb.completion_code );
627 //-killed- //killed on 10/25/98 by Victor Rachels to fix LAN crash
628 //-killed- //-killed- exit(1);
629 //-killed- //end this section kill - Victor
632 for(i=0;i<ipx_num_outgoing_packets;i++)
633 if(!outpackets[i].ecb.in_use)
634 sendpacket= &outpackets[i];
635 //end this section replacement - Kevin Bently
637 // Fill in destination address
638 if ( memcmp( network, &ipx_network, 4 ) )
639 memcpy( sendpacket->ipx.destination.network_id, network, 4 );
641 memset( sendpacket->ipx.destination.network_id, 0, 4 );
642 memcpy( sendpacket->ipx.destination.node_id.address, address, 6 );
643 memcpy( sendpacket->ecb.immediate_address.address, immediate_address, 6 );
644 sendpacket->pd.packetnum = ipx_packetnum++;
646 // Fill in data to send
647 sendpacket->ecb.fragment_size = sizeof(ipx_header) + sizeof(int) + datasize;
649 assert( datasize > 1 );
650 assert( sendpacket->ecb.fragment_size <= 576 );
652 memcpy( sendpacket->pd.data, data, datasize );
655 ipx_send_packet( &sendpacket->ecb );
659 void ipx_send_broadcast_packet_data( ubyte * data, int datasize )
662 ubyte broadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
663 ubyte local_address[6];
665 // Set to all networks besides mine
666 for (i=0; i<Ipx_num_networks; i++ ) {
667 if ( memcmp( &Ipx_networks[i], &ipx_network, 4 ) ) {
668 ipx_get_local_target( (ubyte *)&Ipx_networks[i], broadcast, local_address );
669 ipx_send_packet_data( data, datasize, (ubyte *)&Ipx_networks[i], broadcast, local_address );
671 ipx_send_packet_data( data, datasize, (ubyte *)&Ipx_networks[i], broadcast, broadcast );
675 //OLDipx_send_packet_data( data, datasize, (ubyte *)&ipx_network, broadcast, broadcast );
677 // Send directly to all users not on my network or in the network list.
678 for (i=0; i<Ipx_num_users; i++ ) {
679 if ( memcmp( Ipx_users[i].network, &ipx_network, 4 ) ) {
680 for (j=0; j<Ipx_num_networks; j++ ) {
681 if (!memcmp( Ipx_users[i].network, &Ipx_networks[j], 4 ))
684 ipx_send_packet_data( data, datasize, Ipx_users[i].network, Ipx_users[i].node, Ipx_users[i].address );
691 // Sends a non-localized packet... needs 4 byte server, 6 byte address
692 void ipx_send_internetwork_packet_data( ubyte * data, int datasize, ubyte * server, ubyte *address )
694 ubyte local_address[6];
696 if ( (*(uint *)server) != 0 ) {
697 ipx_get_local_target( server, address, local_address );
698 ipx_send_packet_data( data, datasize, server, address, local_address );
700 // Old method, no server info.
701 ipx_send_packet_data( data, datasize, server, address, address );
705 int ipx_change_default_socket( ushort socket_number )
709 dpmi_real_regs rregs;
711 if ( !ipx_installed ) return -3;
714 memset(&rregs,0,sizeof(dpmi_real_regs));
715 swab( (char *)&socket_number,(char *)&new_ipx_socket, 2 );
716 rregs.edx = new_ipx_socket;
717 rregs.eax = ipx_socket_life;
718 rregs.ebx = 0; // Open socket
719 dpmi_real_int386x( 0x7A, &rregs );
721 new_ipx_socket = rregs.edx & 0xFFFF;
723 if ( rregs.eax & 0xFF ) {
724 //printf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
728 for (i=1; i<ipx_num_packets; i++ ) {
729 ipx_cancel_listen_for_packet(&packets[i].ecb);
732 // Close existing socket...
733 memset(&rregs,0,sizeof(dpmi_real_regs));
734 rregs.edx = ipx_socket;
735 rregs.ebx = 1; // Close socket
736 dpmi_real_int386x( 0x7A, &rregs );
738 ipx_socket = new_ipx_socket;
740 // Repost all listen requests on the new socket...
741 for (i=1; i<ipx_num_packets; i++ ) {
742 packets[i].ecb.in_use = 0;
743 packets[i].ecb.socket_id = ipx_socket;
744 ipx_listen_for_packet(&packets[i].ecb);
747 packets[0].ecb.socket_id = ipx_socket;
748 packets[0].ipx.destination.socket_id = ipx_socket;
751 // init packet buffers.
752 for (i=0; i<MAX_PACKETS; i++ ) {
753 packet_buffers[i].packetnum = -1;
754 packet_free_list[i] = i;
757 largest_packet_index = 0;
762 void ipx_read_user_file(char * filename)
766 char temp_line[132], *p1;
769 if (!filename) return;
773 fp = fopen( filename, "rt" );
776 printf( "Broadcast Users:\n" );
778 while (fgets(temp_line, 132, fp)) {
780 p1 = strchr(temp_line,'\n'); if (p1) *p1 = '\0';
781 p1 = strchr(temp_line,';'); if (p1) *p1 = '\0';
782 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] );
783 // 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] );
784 if ( n != 10 ) continue;
785 if ( Ipx_num_users < MAX_USERS ) {
786 ubyte * ipx_real_buffer = (ubyte *)&tmp;
787 ipx_get_local_target( tmp.network, tmp.node, tmp.address );
788 Ipx_users[Ipx_num_users++] = tmp;
789 printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] );
790 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] );
792 printf( "Too many addresses in %s! (Limit of %d)\n", filename, MAX_USERS );
801 void ipx_read_network_file(char * filename)
805 char temp_line[132], *p1;
808 if (!filename) return;
810 fp = fopen( filename, "rt" );
813 printf( "Using Networks:\n" );
814 for (i=0; i<Ipx_num_networks; i++ ) {
815 ubyte * n1 = (ubyte *)&Ipx_networks[i];
816 printf("* %02x%02x%02x%02x\n", n1[0], n1[1], n1[2], n1[3] );
819 while (fgets(temp_line, 132, fp)) {
821 p1 = strchr(temp_line,'\n'); if (p1) *p1 = '\0';
822 p1 = strchr(temp_line,';'); if (p1) *p1 = '\0';
823 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] );
824 // n = sscanf( temp_line, "%2x%2x%2x%2x", &tmp.network[0], &tmp.network[1], &tmp.network[2], &tmp.network[3] );
825 if ( n != 4 ) continue;
826 if ( Ipx_num_networks < MAX_NETWORKS ) {
828 for (j=0; j<Ipx_num_networks; j++ )
829 if ( !memcmp( &Ipx_networks[j], tmp.network, 4 ) )
831 if ( j >= Ipx_num_networks ) {
832 memcpy( &Ipx_networks[Ipx_num_networks++], tmp.network, 4 );
833 printf(" %02x%02x%02x%02x\n", tmp.network[0], tmp.network[1], tmp.network[2], tmp.network[3] );
836 printf( "Too many networks in %s! (Limit of %d)\n", filename, MAX_NETWORKS );
845 //---typedef struct rip_entry {
851 //---typedef struct rip_packet {
852 //--- ushort operation; //1=request, 2=response
853 //--- rip_entry rip[50];
857 //---void ipx_find_all_servers()
860 //--- rip_packet * rp;
861 //--- assert(ipx_installed);
863 //--- ipx_change_default_socket( 0x0453 );
864 //--- // ipx_change_default_socket( 0x5304 );
866 //--- // Make sure no one is already sending something
867 //--- while( packets[0].ecb.in_use )
871 //--- if (packets[0].ecb.completion_code) {
872 //--- printf( "AAAA:Send error %d for completion code\n", packets[0].ecb.completion_code );
876 //--- rp = (rip_packet *)&packets[0].pd;
878 //--- // Fill in destination address
880 //--- char mzero1[] = {0,0,0,1};
881 //--- char mzero[] = {0,0,0,0,0,1};
882 //--- char immediate[6];
883 //--- //memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
884 //--- //memcpy( packets[0].ipx.destination.node_id.address, ipx_my_node.address, 6 );
886 //--- memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
887 //--- memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
889 //--- memcpy( packets[0].ipx.destination.socket_id, &ipx_socket, 2 );
890 //--- memcpy( packets[0].ipx.source.network_id, &ipx_network, 4 );
891 //--- memcpy( packets[0].ipx.source.node_id.address, ipx_my_node.address, 6 );
892 //--- memcpy( packets[0].ipx.source.socket_id, &ipx_socket, 2 );
893 //--- //memcpy( packets[0].ecb.immediate_address.address, ipx_my_node.address, 6 );
894 //--- //mzero1[3] = 1;
895 //--- //memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
896 //--- //mzero[5] = 1;
897 //--- //memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
898 //--- //ipx_get_local_target( mzero1, mzero, immediate );
899 //--- //memcpy( packets[0].ecb.immediate_address.address, mzero, 6 );
900 //--- //memcpy( packets[0].ecb.immediate_address.address, immediate, 6 );
901 //--- //mzero[5] = 0;
904 //--- packets[0].ipx.packet_type = 1; // RIP packet
906 //--- // Fill in data to send
907 //--- packets[0].ecb.fragment_size = sizeof(ipx_header) + sizeof(rip_packet);
908 //--- assert( packets[0].ecb.fragment_size <= 576 );
910 //--- rp->operation = 0; // Request
911 //--- for (i=0;i<50; i++) {
912 //--- rp->rip[i].network = 0xFFFFFFFF;
913 //--- rp->rip[i].nhops = 0;
914 //--- rp->rip[i].nticks = 0;
918 //--- ipx_send_packet( &packets[0].ecb );
920 //--- for (i=0;i<50; i++) {
921 //--- if ( rp->rip[i].network != 0xFFFFFFFF )
922 //--- printf( "Network = %8x, Hops=%d, Ticks=%d\n", rp->rip[i].network, rp->rip[i].nhops, rp->rip[i].nticks );