]> icculus.org git repositories - btb/d2x.git/blob - unused/bios/ipx.c
use the orientation parameter of g3_draw_bitmap
[btb/d2x.git] / unused / bios / ipx.c
1 /*
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-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14
15 #include <i86.h>
16 #include <dos.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <malloc.h>
20 #include <stdlib.h>
21 #include <conio.h>
22 #include <assert.h>
23
24 #include "types.h"
25 #include "timer.h"
26 #include "ipx.h"
27 #include "dxxerror.h"
28 #include "dpmi.h"
29 #include "key.h"
30
31 typedef unsigned char BYTE;
32 typedef unsigned short WORD;
33 typedef unsigned long DWORD;
34
35 typedef struct local_address {
36         ubyte address[6];
37 } local_address;
38
39 typedef struct net_address {
40         BYTE                            network_id[4];                  
41         local_address   node_id;
42         WORD                            socket_id;
43 } net_address;
44
45 typedef struct ipx_header {
46         WORD                    checksum;
47         WORD                    length;
48         BYTE                    transport_control;
49         BYTE                    packet_type;
50         net_address     destination;
51         net_address     source;
52 } ipx_header;
53
54 typedef struct ecb_header {
55         WORD                    link[2];
56         WORD                    esr_address[2];
57         BYTE                    in_use;
58         BYTE                    completion_code;
59         WORD                    socket_id;
60         BYTE                    ipx_reserved[14];        
61         WORD                    connection_id;
62         local_address immediate_address;
63         WORD                    fragment_count;
64         WORD                    fragment_pointer[2];
65         WORD                    fragment_size;
66 } ecb_header;
67
68 typedef struct packet_data {
69         int                     packetnum;
70         byte                    data[IPX_MAX_DATA_SIZE];
71 } packet_data;
72
73 typedef struct ipx_packet {
74         ecb_header      ecb;
75         ipx_header      ipx;
76         packet_data     pd;
77 } ipx_packet;
78
79 typedef struct user_address {
80         ubyte network[4];
81         ubyte node[6];
82         ubyte address[6];
83 } user_address;
84
85 #define MAX_USERS 64
86 int Ipx_num_users = 0;
87 user_address Ipx_users[MAX_USERS];
88
89 #define MAX_NETWORKS 64
90 int Ipx_num_networks = 0;
91 uint Ipx_networks[MAX_NETWORKS];
92
93 int ipx_packetnum = 0;
94
95 #define MAX_PACKETS 64
96
97 static packet_data packet_buffers[MAX_PACKETS];
98 static short packet_free_list[MAX_PACKETS];
99 static int num_packets = 0;
100 static int largest_packet_index = 0;
101 static short packet_size[MAX_PACKETS];
102
103 WORD ipx_socket=0;
104 ubyte ipx_installed=0;
105 WORD ipx_vector_segment;
106 WORD ipx_vector_offset;
107 ubyte ipx_socket_life = 0;      // 0=closed at prog termination, 0xff=closed when requested.
108 DWORD ipx_network = 0;
109 local_address ipx_my_node;
110 WORD ipx_num_packets=32;                // 32 Ipx packets
111 ipx_packet * packets;
112 int neterrors = 0;
113 ushort ipx_packets_selector;
114
115 ecb_header * last_ecb=NULL;
116 int lastlen=0;
117
118 void free_packet( int id )
119 {
120         packet_buffers[id].packetnum = -1;
121         packet_free_list[ --num_packets ] = id;
122         if (largest_packet_index==id)   
123                 while ((--largest_packet_index>0) && (packet_buffers[largest_packet_index].packetnum == -1 ));
124 }
125
126 int ipx_get_packet_data( ubyte * data )
127 {
128         int i, n, best, best_id, size;
129
130         for (i=1; i<ipx_num_packets; i++ )      {
131                 if ( !packets[i].ecb.in_use )   {
132                         got_new_packet( &packets[i].ecb );
133                         packets[i].ecb.in_use = 0;
134                         ipx_listen_for_packet(&packets[i].ecb);
135                 }                       
136         }
137
138         best = -1;
139         n = 0;
140         best_id = -1;
141
142         for (i=0; i<=largest_packet_index; i++ )        {
143                 if ( packet_buffers[i].packetnum > -1 ) {
144                         n++;
145                         if ( best == -1 || (packet_buffers[i].packetnum<best) ) {
146                                 best = packet_buffers[i].packetnum;
147                                 best_id = i;
148                         }
149                 }                       
150         }
151
152         //mprintf( (0, "Best id = %d, pn = %d, last_ecb = %x, len=%x, ne = %d\n", best_id, best, last_ecb, lastlen, neterrors ));
153         //mprintf( (1, "<%d> ", neterrors ));
154
155         if ( best_id < 0 ) return 0;
156
157         size = packet_size[best_id];
158         memcpy( data, packet_buffers[best_id].data, size );
159         free_packet(best_id);
160
161         return size;
162 }
163
164 unsigned int swap_short( unsigned int short );
165 #pragma aux swap_short parm [eax] = "xchg al,ah";
166
167 void got_new_packet( ecb_header * ecb )
168 {
169         ipx_packet * p;
170         int id;
171         unsigned short datasize;
172
173         datasize = 0;
174         last_ecb = ecb;
175         p = (ipx_packet *)ecb;
176
177         if ( p->ecb.in_use ) { neterrors++; return; }
178         if      ( p->ecb.completion_code )      { neterrors++; return; }
179
180         //      Error( "Recieve error %d for completion code", p->ecb.completion_code );
181         
182         if ( memcmp( &p->ipx.source.node_id, &ipx_my_node, 6 ) )        {
183                 datasize=swap_short(p->ipx.length);
184                 lastlen=datasize;
185                 datasize -= sizeof(ipx_header);
186                 // Find slot to put packet in...
187                 if ( datasize > 0 && datasize <= sizeof(packet_data) )  {
188                         if ( num_packets >= MAX_PACKETS ) {
189                                 //printf( 1, "IPX: Packet buffer overrun!!!\n" );
190                                 neterrors++;
191                                 return;
192                         }               
193                         id = packet_free_list[ num_packets++ ];
194                         if (id > largest_packet_index ) largest_packet_index = id;
195                         packet_size[id] = datasize-sizeof(int);
196                         packet_buffers[id].packetnum =  p->pd.packetnum;
197                         if ( packet_buffers[id].packetnum < 0 ) { neterrors++; return; }
198                         memcpy( packet_buffers[id].data, p->pd.data, packet_size[id] );
199                 } else {
200                         neterrors++; return;
201                 }
202         } 
203         // Repost the ecb
204         p->ecb.in_use = 0;
205         //ipx_listen_for_packet(&p->ecb);
206 }
207
208 ubyte * ipx_get_my_local_address()
209 {
210         return ipx_my_node.address;
211 }
212
213 ubyte * ipx_get_my_server_address()
214 {
215         return (ubyte *)&ipx_network;
216 }
217
218 void ipx_listen_for_packet(ecb_header * ecb )   
219 {
220         dpmi_real_regs rregs;
221         ecb->in_use = 0x1d;
222         memset(&rregs,0,sizeof(dpmi_real_regs));
223         rregs.ebx = 4;  // Listen For Packet function
224         rregs.esi = DPMI_real_offset(ecb);
225         rregs.es = DPMI_real_segment(ecb);
226         dpmi_real_int386x( 0x7A, &rregs );
227 }
228
229 void ipx_cancel_listen_for_packet(ecb_header * ecb )    
230 {
231         dpmi_real_regs rregs;
232         memset(&rregs,0,sizeof(dpmi_real_regs));
233         rregs.ebx = 6;  // IPX Cancel event
234         rregs.esi = DPMI_real_offset(ecb);
235         rregs.es = DPMI_real_segment(ecb);
236         dpmi_real_int386x( 0x7A, &rregs );
237 }
238
239
240 void ipx_send_packet(ecb_header * ecb ) 
241 {
242         dpmi_real_regs rregs;
243         memset(&rregs,0,sizeof(dpmi_real_regs));
244         rregs.ebx = 3;  // Send Packet function
245         rregs.esi = DPMI_real_offset(ecb);
246         rregs.es = DPMI_real_segment(ecb);
247         dpmi_real_int386x( 0x7A, &rregs );
248 }
249
250 typedef struct {
251         ubyte   network[4];
252         ubyte           node[6];
253         ubyte           local_target[6];
254 } net_xlat_info;
255
256 void ipx_get_local_target( ubyte * server, ubyte * node, ubyte * local_target )
257 {
258         net_xlat_info * info;
259         dpmi_real_regs rregs;
260                 
261         // Get dos memory for call...
262         info = (net_xlat_info *)dpmi_get_temp_low_buffer( sizeof(net_xlat_info) );      
263         assert( info != NULL );
264         memcpy( info->network, server, 4 );
265         memcpy( info->node, node, 6 );
266         
267         memset(&rregs,0,sizeof(dpmi_real_regs));
268
269         rregs.ebx = 2;          // Get Local Target     
270         rregs.es = DPMI_real_segment(info);
271         rregs.esi = DPMI_real_offset(info->network);
272         rregs.edi = DPMI_real_offset(info->local_target);
273
274         dpmi_real_int386x( 0x7A, &rregs );
275
276         // Save the local target...
277         memcpy( local_target, info->local_target, 6 );
278 }
279
280 void ipx_close()
281 {
282         dpmi_real_regs rregs;
283         if ( ipx_installed )    {
284                 // When using VLM's instead of NETX, the sockets don't
285                 // seem to automatically get closed, so we must explicitly
286                 // close them at program termination.
287                 ipx_installed = 0;
288                 memset(&rregs,0,sizeof(dpmi_real_regs));
289                 rregs.edx = ipx_socket;
290                 rregs.ebx = 1;  // Close socket
291                 dpmi_real_int386x( 0x7A, &rregs );
292         }
293 }
294
295
296 //---------------------------------------------------------------
297 // Initializes all IPX internals. 
298 // If socket_number==0, then opens next available socket.
299 // Returns:     0  if successful.
300 //                              -1 if socket already open.
301 //                              -2      if socket table full.
302 //                              -3 if IPX not installed.
303 //                              -4 if couldn't allocate low dos memory
304 //                              -5 if error with getting internetwork address
305
306 int ipx_init( int socket_number, int show_address )
307 {
308         dpmi_real_regs rregs;
309         ubyte *ipx_real_buffer;
310         int i;
311
312         atexit(ipx_close);
313
314         ipx_packetnum = 0;
315
316         // init packet buffers.
317         for (i=0; i<MAX_PACKETS; i++ )  {
318                 packet_buffers[i].packetnum = -1;
319                 packet_free_list[i] = i;
320         }
321         num_packets = 0;
322         largest_packet_index = 0;
323
324         // Get the IPX vector
325         memset(&rregs,0,sizeof(dpmi_real_regs));
326         rregs.eax=0x00007a00;
327         dpmi_real_int386x( 0x2f, &rregs );
328
329         if ( (rregs.eax & 0xFF) != 0xFF )       {
330                 return 3;   
331         }
332         ipx_vector_offset = rregs.edi & 0xFFFF;
333         ipx_vector_segment = rregs.es;
334         //printf( "IPX entry point at %.4x:%.4x\n", ipx_vector_segment, ipx_vector_offset );
335
336         // Open a socket for IPX
337
338         memset(&rregs,0,sizeof(dpmi_real_regs));
339         swab( (char *)&socket_number,(char *)&ipx_socket, 2 );
340         rregs.edx = ipx_socket;
341         rregs.eax = ipx_socket_life;
342         rregs.ebx = 0;  // Open socket
343         dpmi_real_int386x( 0x7A, &rregs );
344         
345         ipx_socket = rregs.edx & 0xFFFF;
346         
347         if ( rregs.eax & 0xFF ) {
348                 //mprintf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
349                 return -2;
350         }
351         
352         ipx_installed = 1;
353
354         // Find our internetwork address
355         ipx_real_buffer = dpmi_get_temp_low_buffer( 1024 );     // 1k block
356         if ( ipx_real_buffer == NULL )  {
357                 //printf( "Error allocation realmode memory\n" );
358                 return -4;
359         }
360
361         memset(&rregs,0,sizeof(dpmi_real_regs));
362         rregs.ebx = 9;          // Get internetwork address
363         rregs.esi = DPMI_real_offset(ipx_real_buffer);
364         rregs.es = DPMI_real_segment(ipx_real_buffer);
365         dpmi_real_int386x( 0x7A, &rregs );
366
367         if ( rregs.eax & 0xFF ) {
368                 //printf( "Error getting internetwork address!\n" );
369                 return -2;
370         }
371
372         memcpy( &ipx_network, ipx_real_buffer, 4 );
373         memcpy( &ipx_my_node, &ipx_real_buffer[4], 6 );
374
375         Ipx_num_networks = 0;
376         memcpy( &Ipx_networks[Ipx_num_networks++], &ipx_network, 4 );
377
378         if ( show_address )     {
379                 printf( "My IPX addresss is " );
380                 printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] );
381                 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] );
382                 printf( "\n" );
383         }
384
385         packets = dpmi_real_malloc( sizeof(ipx_packet)*ipx_num_packets, &ipx_packets_selector );
386         if ( packets == NULL )  {
387                 //printf( "Couldn't allocate real memory for %d packets\n", ipx_num_packets );
388                 return -4;
389         }
390         if (!dpmi_lock_region( packets, sizeof(ipx_packet)*ipx_num_packets ))   {
391                 //printf( "Couldn't lock real memory for %d packets\n", ipx_num_packets );
392                 return -4;
393         }
394         memset( packets, 0, sizeof(ipx_packet)*ipx_num_packets );
395
396         for (i=1; i<ipx_num_packets; i++ )      {
397                 packets[i].ecb.in_use = 0x1d;
398                 //packets[i].ecb.in_use = 0;
399                 packets[i].ecb.socket_id = ipx_socket;
400                 packets[i].ecb.fragment_count = 1;
401                 packets[i].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[i].ipx);
402                 packets[i].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[i].ipx);
403                 packets[i].ecb.fragment_size = sizeof(ipx_packet)-sizeof(ecb_header);                   //-sizeof(ecb_header);
404
405                 ipx_listen_for_packet(&packets[i].ecb);
406         }
407
408         packets[0].ecb.socket_id = ipx_socket;
409         packets[0].ecb.fragment_count = 1;
410         packets[0].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[0].ipx);
411         packets[0].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[0].ipx);
412         packets[0].ipx.packet_type = 4;         // IPX packet
413         packets[0].ipx.destination.socket_id = ipx_socket;
414 //      memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
415         memset( packets[0].ipx.destination.network_id, 0, 4 );
416
417         return 0;
418 }
419
420 void ipx_send_packet_data( ubyte * data, int datasize, ubyte *network, ubyte *address, ubyte *immediate_address )
421 {
422         assert(ipx_installed);
423
424         Assert(datasize < IPX_MAX_DATA_SIZE);
425
426         // Make sure no one is already sending something
427         while( packets[0].ecb.in_use )
428         {
429         }
430         
431 //      if (packets[0].ecb.completion_code)
432           //    Error("IPX: Send error %d for completion code\n", packets[0].ecb.completion_code );
433
434         // Fill in destination address
435         if ( memcmp( network, &ipx_network, 4 ) )
436                 memcpy( packets[0].ipx.destination.network_id, network, 4 );
437         else
438                 memset( packets[0].ipx.destination.network_id, 0, 4 );
439         memcpy( packets[0].ipx.destination.node_id.address, address, 6 );
440         memcpy( packets[0].ecb.immediate_address.address, immediate_address, 6 );
441         packets[0].pd.packetnum = ipx_packetnum++;
442
443         // Fill in data to send
444         packets[0].ecb.fragment_size = sizeof(ipx_header) + sizeof(int) + datasize;
445
446         assert( datasize > 1 );
447         assert( packets[0].ecb.fragment_size <= 576 );
448
449         memcpy( packets[0].pd.data, data, datasize );
450
451         // Send it
452         ipx_send_packet( &packets[0].ecb );
453
454 }
455
456 void ipx_send_broadcast_packet_data( ubyte * data, int datasize )       
457 {
458         int i, j;
459         ubyte broadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
460         ubyte local_address[6];
461
462         // Set to all networks besides mine
463         for (i=0; i<Ipx_num_networks; i++ )     {
464                 if ( memcmp( &Ipx_networks[i], &ipx_network, 4 ) )      {
465                         ipx_get_local_target( (ubyte *)&Ipx_networks[i], broadcast, local_address );
466                         ipx_send_packet_data( data, datasize, (ubyte *)&Ipx_networks[i], broadcast, local_address );
467                 } else {
468                         ipx_send_packet_data( data, datasize, (ubyte *)&Ipx_networks[i], broadcast, broadcast );
469                 }
470         }
471
472         //OLDipx_send_packet_data( data, datasize, (ubyte *)&ipx_network, broadcast, broadcast );
473
474         // Send directly to all users not on my network or in the network list.
475         for (i=0; i<Ipx_num_users; i++ )        {
476                 if ( memcmp( Ipx_users[i].network, &ipx_network, 4 ) )  {
477                         for (j=0; j<Ipx_num_networks; j++ )             {
478                                 if (!memcmp( Ipx_users[i].network, &Ipx_networks[j], 4 ))
479                                         goto SkipUser;
480                         }
481                         ipx_send_packet_data( data, datasize, Ipx_users[i].network, Ipx_users[i].node, Ipx_users[i].address );
482 SkipUser:
483                         j = 0;
484                 }
485         }
486 }
487
488 // Sends a non-localized packet... needs 4 byte server, 6 byte address
489 void ipx_send_internetwork_packet_data( ubyte * data, int datasize, ubyte * server, ubyte *address )
490 {
491         ubyte local_address[6];
492
493         if ( (*(uint *)server) != 0 )   {
494                 ipx_get_local_target( server, address, local_address );
495                 ipx_send_packet_data( data, datasize, server, address, local_address );
496         } else {
497                 // Old method, no server info.
498                 ipx_send_packet_data( data, datasize, server, address, address );
499         }
500 }
501
502 int ipx_change_default_socket( ushort socket_number )
503 {
504         int i;
505         WORD new_ipx_socket;
506         dpmi_real_regs rregs;
507
508         if ( !ipx_installed ) return -3;
509
510         // Open a new socket    
511         memset(&rregs,0,sizeof(dpmi_real_regs));
512         swab( (char *)&socket_number,(char *)&new_ipx_socket, 2 );
513         rregs.edx = new_ipx_socket;
514         rregs.eax = ipx_socket_life;
515         rregs.ebx = 0;  // Open socket
516         dpmi_real_int386x( 0x7A, &rregs );
517         
518         new_ipx_socket = rregs.edx & 0xFFFF;
519         
520         if ( rregs.eax & 0xFF ) {
521                 //printf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
522                 return -2;
523         }
524
525         for (i=1; i<ipx_num_packets; i++ )      {
526                 ipx_cancel_listen_for_packet(&packets[i].ecb);
527         }
528
529         // Close existing socket...
530         memset(&rregs,0,sizeof(dpmi_real_regs));
531         rregs.edx = ipx_socket;
532         rregs.ebx = 1;  // Close socket
533         dpmi_real_int386x( 0x7A, &rregs );
534
535         ipx_socket = new_ipx_socket;
536
537         // Repost all listen requests on the new socket...      
538         for (i=1; i<ipx_num_packets; i++ )      {
539                 packets[i].ecb.in_use = 0;
540                 packets[i].ecb.socket_id = ipx_socket;
541                 ipx_listen_for_packet(&packets[i].ecb);
542         }
543
544         packets[0].ecb.socket_id = ipx_socket;
545         packets[0].ipx.destination.socket_id = ipx_socket;
546
547         ipx_packetnum = 0;
548         // init packet buffers.
549         for (i=0; i<MAX_PACKETS; i++ )  {
550                 packet_buffers[i].packetnum = -1;
551                 packet_free_list[i] = i;
552         }
553         num_packets = 0;
554         largest_packet_index = 0;
555
556         return 0;
557 }
558
559 void ipx_read_user_file(char * filename)
560 {
561         FILE * fp;
562         user_address tmp;
563         char temp_line[132], *p1;
564         int n, ln=0;
565
566         if (!filename) return;
567
568         Ipx_num_users = 0;
569
570         fp = fopen( filename, "rt" );
571         if ( !fp ) return;
572
573         printf( "Broadcast Users:\n" );
574
575         while (fgets(temp_line, 132, fp)) {
576                 unsigned long net;
577                 char *np;
578                 ln++;
579                 p1 = strchr(temp_line,'\n'); if (p1) *p1 = '\0';
580                 p1 = strchr(temp_line,';'); if (p1) *p1 = '\0';
581                 if (strlen(temp_line) == 0) continue;  //skip blank lines
582                 //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] );
583                 //if ( n != 10 ) continue;
584                 np = strchr(temp_line,'/');
585                 if (!np)
586                         Error("Invalid entry <%s> on line %d of IPX User file <%s>",temp_line,ln,filename);
587                 else np++;
588                 n = sscanf( temp_line, "%x", &net);
589                 if (n != 1)
590                         Error("Invalid entry <%s> on line %d of IPX User file <%s>",temp_line,ln,filename);
591                 else {
592                         tmp.network[3] = (net & 0xff); net >>= 8;
593                         tmp.network[2] = (net & 0xff); net >>= 8;
594                         tmp.network[1] = (net & 0xff); net >>= 8;
595                         tmp.network[0] = (net & 0xff);
596                 }
597                 n = sscanf( np, "%2x%2x%2x%2x%2x%2x", &tmp.node[0], &tmp.node[1], &tmp.node[2],&tmp.node[3], &tmp.node[4], &tmp.node[5] );
598                 if (n != 6)
599                         Error("Invalid entry <%s> on line %d of IPX User file <%s>\n"
600                                         "  Node address must be 6 bytes (12 digits)",temp_line,ln,filename);
601                 if ( Ipx_num_users < MAX_USERS )        {
602                         ubyte * ipx_real_buffer = (ubyte *)&tmp;
603                         ipx_get_local_target( tmp.network, tmp.node, tmp.address );
604                         Ipx_users[Ipx_num_users++] = tmp;
605                         printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] );
606                         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] );
607                 } else {
608                         printf( "Too many addresses in %s! (Limit of %d)\n", filename, MAX_USERS );
609                         fclose(fp);
610                         return;
611                 }
612         }
613         fclose(fp);
614
615 }
616
617
618 void ipx_read_network_file(char * filename)
619 {
620         FILE * fp;
621         user_address tmp;
622         char temp_line[132], *p1;
623         int i, n, ln=0;
624
625         if (!filename) return;
626
627         fp = fopen( filename, "rt" );
628         if ( !fp ) return;
629
630         printf( "Using Networks:\n" );
631         for (i=0; i<Ipx_num_networks; i++ )             {
632                 ubyte * n1 = (ubyte *)&Ipx_networks[i];
633                 printf("* %02x%02x%02x%02x\n", n1[0], n1[1], n1[2], n1[3] );
634         }
635
636         while (fgets(temp_line, 132, fp)) {
637                 unsigned long net;
638                 ln++;
639                 p1 = strchr(temp_line,'\n'); if (p1) *p1 = '\0';
640                 p1 = strchr(temp_line,';'); if (p1) *p1 = '\0';
641                 if (strlen(temp_line) == 0) continue;  //skip blank lines
642                 //n = sscanf( temp_line, "%2x%2x%2x%2x", &tmp.network[0], &tmp.network[1], &tmp.network[2], &tmp.network[3] );
643                 //if ( n != 4 ) continue;
644                 n = sscanf( temp_line, "%x", &net );
645                 if (n != 1)
646                         Error("Invalid entry <%s> on line %d of IPX Net file <%s>",temp_line,ln,filename);
647                 else {
648                         tmp.network[3] = (net & 0xff); net >>= 8;
649                         tmp.network[2] = (net & 0xff); net >>= 8;
650                         tmp.network[1] = (net & 0xff); net >>= 8;
651                         tmp.network[0] = (net & 0xff);
652                 }
653
654                 if ( Ipx_num_networks < MAX_NETWORKS  ) {
655                         int j;
656                         for (j=0; j<Ipx_num_networks; j++ )     
657                                 if ( !memcmp( &Ipx_networks[j], tmp.network, 4 ) )
658                                         break;
659                         if ( j >= Ipx_num_networks )    {
660                                 memcpy( &Ipx_networks[Ipx_num_networks++], tmp.network, 4 );
661                                 printf("  %02x%02x%02x%02x\n", tmp.network[0], tmp.network[1], tmp.network[2], tmp.network[3] );
662                         }
663                 } else {
664                         printf( "Too many networks in %s! (Limit of %d)\n", filename, MAX_NETWORKS );
665                         fclose(fp);
666                         return;
667                 }
668         }
669         fclose(fp);
670
671 }
672
673 //---typedef struct rip_entry {
674 //---   uint            network;
675 //---   ushort  nhops;
676 //---   ushort  nticks;
677 //---} rip_entry;
678 //---
679 //---typedef struct rip_packet {
680 //---   ushort          operation;              //1=request, 2=response
681 //---   rip_entry       rip[50];
682 //---} rip_packet;
683 //---
684 //---
685 //---void  ipx_find_all_servers()
686 //---{
687 //---   int i;
688 //---   rip_packet * rp;
689 //---   assert(ipx_installed);
690 //---
691 //---   ipx_change_default_socket( 0x0453 );
692 //---   //      ipx_change_default_socket( 0x5304 );
693 //---
694 //---   // Make sure no one is already sending something
695 //---   while( packets[0].ecb.in_use )
696 //---   {
697 //---   }
698 //---   
699 //---   if (packets[0].ecb.completion_code)     {
700 //---           printf( "AAAA:Send error %d for completion code\n", packets[0].ecb.completion_code );
701 //---           //exit(1);
702 //---   }
703 //---
704 //---   rp = (rip_packet *)&packets[0].pd;
705 //---
706 //---   // Fill in destination address
707 //---   {
708 //---           char mzero1[] = {0,0,0,1};
709 //---           char mzero[] = {0,0,0,0,0,1};
710 //---           char immediate[6];
711 //---           //memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
712 //---           //memcpy( packets[0].ipx.destination.node_id.address, ipx_my_node.address, 6 );
713 //---
714 //---           memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
715 //---           memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
716 //---
717 //---           memcpy( packets[0].ipx.destination.socket_id, &ipx_socket, 2 );
718 //---           memcpy( packets[0].ipx.source.network_id, &ipx_network, 4 );
719 //---           memcpy( packets[0].ipx.source.node_id.address, ipx_my_node.address, 6 );
720 //---           memcpy( packets[0].ipx.source.socket_id, &ipx_socket, 2 );
721 //---           //memcpy( packets[0].ecb.immediate_address.address, ipx_my_node.address, 6 );
722 //---           //mzero1[3] = 1;
723 //---           //memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
724 //---           //mzero[5] = 1;
725 //---           //memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
726 //---           //ipx_get_local_target( mzero1, mzero, immediate );
727 //---           //memcpy( packets[0].ecb.immediate_address.address, mzero, 6 );
728 //---           //memcpy( packets[0].ecb.immediate_address.address, immediate, 6 );
729 //---           //mzero[5] = 0;
730 //---   }
731 //---
732 //---   packets[0].ipx.packet_type = 1;         // RIP packet
733 //---
734 //---   // Fill in data to send
735 //---   packets[0].ecb.fragment_size = sizeof(ipx_header) + sizeof(rip_packet);
736 //---   assert( packets[0].ecb.fragment_size <= 576 );
737 //---
738 //---   rp->operation = 0;              // Request
739 //---   for (i=0;i<50; i++)     {
740 //---           rp->rip[i].network = 0xFFFFFFFF;
741 //---           rp->rip[i].nhops = 0;
742 //---           rp->rip[i].nticks = 0;
743 //---   }
744 //---
745 //---   // Send it
746 //---   ipx_send_packet( &packets[0].ecb );
747 //---
748 //---   for (i=0;i<50; i++)     {
749 //---           if ( rp->rip[i].network != 0xFFFFFFFF )
750 //---                   printf( "Network = %8x, Hops=%d, Ticks=%d\n", rp->rip[i].network, rp->rip[i].nhops, rp->rip[i].nticks );
751 //---   }
752 //---}
753 //---
754 //---