]> icculus.org git repositories - btb/d2x.git/blob - arch/dos/ipx.c
reenabled ggi build
[btb/d2x.git] / arch / dos / 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-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  * $Source: /cvs/cvsroot/d2x/arch/dos/ipx.c,v $
16  * $Revision: 1.4 $
17  * $Author: bradleyb $
18  * $Date: 2001-10-19 10:46:06 $
19  * 
20  * Routines for IPX communications.
21  * 
22  * $Log: not supported by cvs2svn $
23  * Revision 1.2  2000/02/07 10:26:05  donut
24  * new ipx code structure reduces some redundancy and gives all arches multi netcode ability
25  *
26  * Revision 1.1.1.1  1999/06/14 21:58:22  donut
27  * Import of d1x 1.37 source.
28  *
29  * Revision 2.10  1995/03/29  17:27:55  john
30  * Added code to not duplicate broadcasts.
31  * 
32  * Revision 2.9  1995/03/29  15:32:07  john
33  * NEatened.
34  * 
35  * Revision 2.8  1995/03/29  15:07:31  john
36  * Added network support.
37  * 
38  * Revision 2.7  1995/03/29  11:22:27  john
39  * Added broadcasting over a net.
40  * 
41  * Revision 2.6  1995/03/28  20:05:03  john
42  * Took away alternate server stuff.
43  * 
44  * Revision 2.5  1995/03/23  19:14:29  john
45  * Added better MAX_USERS message.
46  * 
47  * Revision 2.4  1995/03/23  19:00:02  john
48  * Added user list capabitly.
49  * 
50  * Revision 2.3  1995/03/23  12:27:05  john
51  * Move IPX into bios lib.
52  * 
53  * Revision 2.2  1995/03/22  19:08:15  john
54  * Added code to fix sending packets over router... now
55  * we just need to make broadcasts go over router!!
56  * 
57  * Revision 2.1  1995/03/21  08:40:16  john
58  * Ifdef'd out the NETWORK code.
59  * 
60  * Revision 2.0  1995/02/27  11:30:45  john
61  * New version 2.0, which has no anonymous unions, builds with
62  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
63  * 
64  * Revision 1.31  1995/02/16  17:35:03  john
65  * Added code to allow dynamic socket changing.
66  * 
67  * Revision 1.30  1995/02/01  21:03:45  john
68  * Lintified.
69  * 
70  * Revision 1.29  1995/01/22  14:31:05  john
71  * Added key.h
72  * 
73  * Revision 1.28  1995/01/22  14:29:26  john
74  * Added code to bypass broadcast messages.
75  * 
76  * Revision 1.27  1995/01/03  13:46:16  john
77  * Added code that should make ipx work over different servers,
78  * but ifdef'd it out with SHAREWARE in ipx.c.  I haven't tested
79  * this, and I hope it doesn't introduce net bugs.
80  * 
81  * Revision 1.26  1994/12/14  11:54:37  rob
82  * Reduce # of ipx packets.
83  * 
84  * Revision 1.25  1994/12/11  00:43:28  john
85  * Locked down DOS ipx buffers... probably not necessary, tho.
86  * 
87  * Revision 1.24  1994/12/08  15:49:58  rob
88  * Bumped up the # of ipx packets.
89  * 
90  * Revision 1.23  1994/12/04  15:23:54  rob
91  * Reduced packet # constants.
92  * 
93  * Revision 1.22  1994/11/27  23:12:39  matt
94  * Made changes for new mprintf calling convention
95  * 
96  * Revision 1.21  1994/11/19  15:15:19  mike
97  * remove unused code and data
98  * 
99  * Revision 1.20  1994/11/10  11:06:07  rob
100  * Raised number of ipx packets to 64 and buffers to 128 (for 8-way games)
101  * Removed (commented out) all the spx support stuff.
102  * 
103  * Revision 1.19  1994/11/07  17:50:12  rob
104  * Bumped up max_packets and ipx_num_packets to double their previous
105  * values.
106  * 
107  * Revision 1.18  1994/11/07  15:39:01  rob
108  * Removed temporary hacked ipx_send_object function.
109  * Replaced with a more general thing.
110  * 
111  * Revision 1.17  1994/11/05  16:08:40  rob
112  * Made a change necessary for object syncing on rejoin.
113  * 
114  * Revision 1.16  1994/11/01  15:57:12  rob
115  * Added support for SPX sockets for critical messages.
116  * 
117  * Revision 1.15  1994/10/31  19:21:01  rob
118  * Added a routine for sending objects via ipx.  Its a hack and shoukld
119  * be replaced by something more general time permitting.
120  * 
121  * Revision 1.14  1994/10/20  14:57:42  john
122  * Some test stuff.
123  * 
124  * Revision 1.13  1994/10/20  11:22:45  john
125  * Tweaked the number of waiting packets. Added code to print 
126  * total packets missed, and to limit the packet send rate to
127  * 10 packets per second unless firing.
128  * 
129  * Revision 1.12  1994/10/03  20:50:11  john
130  * Started adding sound pause functions.
131  * 
132  * Revision 1.11  1994/09/15  08:54:24  mike
133  * comment out a mprintf.
134  * 
135  * Revision 1.10  1994/09/12  19:38:20  john
136  * Made some stuff that prints to the DOS screen go to the
137  * mono instead, since it really is debugging info.
138  * 
139  * Revision 1.9  1994/09/07  13:32:03  john
140  * Made ipx_close explicitly close the socket we were using,
141  * because it seems that VLM's don't automatically close them
142  * like the older NETX stuff did (Going from Novell 3.11 driver
143  * to 3.12 anyway).
144  * 
145  * Revision 1.8  1994/09/06  19:29:20  john
146  * Added trial version of rejoin function.
147  * 
148  * Revision 1.7  1994/08/09  19:31:50  john
149  * Networking changes.
150  * 
151  * Revision 1.6  1994/08/05  16:11:41  john
152  * Psuedo working version of networking.
153  * 
154  * Revision 1.5  1994/08/04  19:17:21  john
155  * Inbetween version of network stuff.
156  * 
157  * Revision 1.4  1994/07/29  16:08:57  john
158  * *** empty log message ***
159  * 
160  * Revision 1.3  1994/07/25  12:33:31  john
161  * Network "pinging" in.
162  * 
163  * Revision 1.2  1994/07/20  15:58:28  john
164  * First installment of ipx stuff.
165  * 
166  * Revision 1.1  1994/07/19  15:42:00  john
167  * Initial revision
168  * 
169  * 
170  */
171
172 #ifdef HAVE_CONFIG_H
173 #include <conf.h>
174 #endif
175
176 #ifdef __GNUC__
177 #define _BORLAND_DOS_REGS 1
178 #define far
179 #endif
180
181 #include <i86.h>
182 #include <dos.h>
183 #include <stdio.h>
184 #include <string.h>
185 #include <malloc.h>
186 #include <stdlib.h>
187 #include <conio.h>
188 #include <assert.h>
189
190 #include "pstypes.h"
191 #include "timer.h"
192 #include "ipx.h"
193 #include "error.h"
194 #include "u_dpmi.h"
195 #include "key.h"
196 #include "ipx_drv.h"
197
198 typedef unsigned char BYTE;
199 typedef unsigned short WORD;
200 typedef unsigned long DWORD;
201
202 typedef struct local_address {
203         ubyte address[6];
204 } __pack__ local_address;
205
206 typedef struct net_address {
207         BYTE                            network_id[4];                  
208         local_address   node_id;
209         WORD                            socket_id;
210 } __pack__ net_address;
211
212 typedef struct ipx_header {
213         WORD                    checksum;
214         WORD                    length;
215         BYTE                    transport_control;
216         BYTE                    packet_type;
217         net_address     destination;
218         net_address     source;
219 } __pack__ ipx_header;
220
221 typedef struct ecb_header {
222         WORD                    link[2];
223         WORD                    esr_address[2];
224         BYTE                    in_use;
225         BYTE                    completion_code;
226         WORD                    socket_id;
227         BYTE                    ipx_reserved[14];        
228         WORD                    connection_id;
229         local_address immediate_address;
230         WORD                    fragment_count;
231         WORD                    fragment_pointer[2];
232         WORD                    fragment_size;
233 } __pack__ ecb_header;
234
235 typedef struct packet_data {
236         int                     packetnum;
237         byte                    data[IPX_MAX_DATA_SIZE];
238 } __pack__ packet_data;
239
240 typedef struct ipx_packet {
241         ecb_header      ecb;
242         ipx_header      ipx;
243         packet_data     pd;
244 } __pack__ ipx_packet;
245
246 static int ipx_packetnum = 0;
247
248 #define MAX_PACKETS 64
249
250 static packet_data packet_buffers[MAX_PACKETS];
251 static short packet_free_list[MAX_PACKETS];
252 static int num_packets = 0;
253 static int largest_packet_index = 0;
254 static short packet_size[MAX_PACKETS];
255
256 WORD ipx_socket=0;
257 static ubyte ipx_installed=0;
258 WORD ipx_vector_segment;
259 WORD ipx_vector_offset;
260 ubyte ipx_socket_life = 0;      // 0=closed at prog termination, 0xff=closed when requested.
261 //DWORD ipx_network = 0;
262 //local_address ipx_my_node;
263 #define ipx_my_node (ipx_MyAddress+4)
264 WORD ipx_num_packets=32;                // 32 Ipx packets
265 ipx_packet * packets;
266 int neterrors = 0;
267 ushort ipx_packets_selector;
268
269 ecb_header * last_ecb=NULL;
270 int lastlen=0;
271
272 static void got_new_packet( ecb_header * ecb );
273 static void ipx_listen_for_packet(ecb_header * ecb );
274
275 static void free_packet( int id )
276 {
277         packet_buffers[id].packetnum = -1;
278         packet_free_list[ --num_packets ] = id;
279         if (largest_packet_index==id)   
280                 while ((--largest_packet_index>0) && (packet_buffers[largest_packet_index].packetnum == -1 ));
281 }
282
283 static int ipx_dos_get_packet_data( ubyte * data )
284 {
285         int i, n, best, best_id, size;
286
287         for (i=1; i<ipx_num_packets; i++ )      {
288                 if ( !packets[i].ecb.in_use )   {
289                         got_new_packet( &packets[i].ecb );
290                         packets[i].ecb.in_use = 0;
291                         ipx_listen_for_packet(&packets[i].ecb);
292                 }                       
293         }
294
295         best = -1;
296         n = 0;
297         best_id = -1;
298
299         for (i=0; i<=largest_packet_index; i++ )        {
300                 if ( packet_buffers[i].packetnum > -1 ) {
301                         n++;
302                         if ( best == -1 || (packet_buffers[i].packetnum<best) ) {
303                                 best = packet_buffers[i].packetnum;
304                                 best_id = i;
305                         }
306                 }                       
307         }
308
309         //mprintf( (0, "Best id = %d, pn = %d, last_ecb = %x, len=%x, ne = %d\n", best_id, best, last_ecb, lastlen, neterrors ));
310         //mprintf( (1, "<%d> ", neterrors ));
311
312         if ( best_id < 0 ) return 0;
313
314         size = packet_size[best_id];
315         memcpy( data, packet_buffers[best_id].data, size );
316         free_packet(best_id);
317
318         return size;
319 }
320
321 #ifndef __GNUC__
322 unsigned int swap_short( unsigned int short )
323 #pragma aux swap_short parm [eax] = "xchg al,ah";
324 #else
325 static inline unsigned int swap_short( unsigned int sshort ) {
326         int __retval;
327         asm("xchg %%ah,%%al" : "=a" (__retval) : "a" (sshort));
328         return __retval;
329 }
330 #endif
331
332 static void got_new_packet( ecb_header * ecb )
333 {
334         ipx_packet * p;
335         int id;
336         unsigned short datasize;
337
338         datasize = 0;
339         last_ecb = ecb;
340         p = (ipx_packet *)ecb;
341
342         if ( p->ecb.in_use ) { neterrors++; return; }
343         if      ( p->ecb.completion_code )      { neterrors++; return; }
344
345         //      Error( "Recieve error %d for completion code", p->ecb.completion_code );
346         
347         if ( memcmp( &p->ipx.source.node_id, ipx_my_node, 6 ) ) {
348                 datasize=swap_short(p->ipx.length);
349                 lastlen=datasize;
350                 datasize -= sizeof(ipx_header);
351                 // Find slot to put packet in...
352                 if ( datasize > 0 && datasize <= sizeof(packet_data) )  {
353                         if ( num_packets >= MAX_PACKETS ) {
354                                 //printf( 1, "IPX: Packet buffer overrun!!!\n" );
355                                 neterrors++;
356                                 return;
357                         }               
358                         id = packet_free_list[ num_packets++ ];
359                         if (id > largest_packet_index ) largest_packet_index = id;
360                         packet_size[id] = datasize-sizeof(int);
361                         packet_buffers[id].packetnum =  p->pd.packetnum;
362                         if ( packet_buffers[id].packetnum < 0 ) { neterrors++; return; }
363                         memcpy( packet_buffers[id].data, p->pd.data, packet_size[id] );
364                 } else {
365                         neterrors++; return;
366                 }
367         } 
368         // Repost the ecb
369         p->ecb.in_use = 0;
370         //ipx_listen_for_packet(&p->ecb);
371 }
372
373 /*ubyte * ipx_get_my_local_address()
374 {
375         return ipx_my_node.address;
376 }
377
378 ubyte * ipx_get_my_server_address()
379 {
380         return (ubyte *)&ipx_network;
381 }*/
382
383 static void ipx_listen_for_packet(ecb_header * ecb )    
384 {
385         dpmi_real_regs rregs;
386         ecb->in_use = 0x1d;
387         memset(&rregs,0,sizeof(dpmi_real_regs));
388         rregs.ebx = 4;  // Listen For Packet function
389         rregs.esi = DPMI_real_offset(ecb);
390         rregs.es = DPMI_real_segment(ecb);
391         dpmi_real_int386x( 0x7A, &rregs );
392 }
393
394 /*static void ipx_cancel_listen_for_packet(ecb_header * ecb )   
395 {
396         dpmi_real_regs rregs;
397         memset(&rregs,0,sizeof(dpmi_real_regs));
398         rregs.ebx = 6;  // IPX Cancel event
399         rregs.esi = DPMI_real_offset(ecb);
400         rregs.es = DPMI_real_segment(ecb);
401         dpmi_real_int386x( 0x7A, &rregs );
402 }
403 */
404
405 static void ipx_send_packet(ecb_header * ecb )  
406 {
407         dpmi_real_regs rregs;
408         memset(&rregs,0,sizeof(dpmi_real_regs));
409         rregs.ebx = 3;  // Send Packet function
410         rregs.esi = DPMI_real_offset(ecb);
411         rregs.es = DPMI_real_segment(ecb);
412         dpmi_real_int386x( 0x7A, &rregs );
413 }
414
415 typedef struct {
416         ubyte   network[4];
417         ubyte           node[6];
418         ubyte           local_target[6];
419 } __pack__ net_xlat_info;
420
421 static void ipx_dos_get_local_target( ubyte * server, ubyte * node, ubyte * local_target )
422 {
423         net_xlat_info * info;
424         dpmi_real_regs rregs;
425                 
426         // Get dos memory for call...
427         info = (net_xlat_info *)dpmi_get_temp_low_buffer( sizeof(net_xlat_info) );      
428         assert( info != NULL );
429         memcpy( info->network, server, 4 );
430         memcpy( info->node, node, 6 );
431         
432         memset(&rregs,0,sizeof(dpmi_real_regs));
433
434         rregs.ebx = 2;          // Get Local Target     
435         rregs.es = DPMI_real_segment(info);
436         rregs.esi = DPMI_real_offset(info->network);
437         rregs.edi = DPMI_real_offset(info->local_target);
438
439         dpmi_real_int386x( 0x7A, &rregs );
440
441         // Save the local target...
442         memcpy( local_target, info->local_target, 6 );
443 }
444
445 static void ipx_dos_close()
446 {
447         dpmi_real_regs rregs;
448         if ( ipx_installed )    {
449                 // When using VLM's instead of NETX, the sockets don't
450                 // seem to automatically get closed, so we must explicitly
451                 // close them at program termination.
452                 ipx_installed = 0;
453                 memset(&rregs,0,sizeof(dpmi_real_regs));
454                 rregs.edx = ipx_socket;
455                 rregs.ebx = 1;  // Close socket
456                 dpmi_real_int386x( 0x7A, &rregs );
457         }
458 }
459
460
461 //---------------------------------------------------------------
462 // Initializes all IPX internals. 
463 // If socket_number==0, then opens next available socket.
464 // Returns:     0  if successful.
465 //                              -1 if socket already open.
466 //                              -2      if socket table full.
467 //                              -3 if IPX not installed.
468 //                              -4 if couldn't allocate low dos memory
469 //                              -5 if error with getting internetwork address
470
471 static int ipx_dos_init( int socket_number )
472 {
473         int show_address=0;
474         dpmi_real_regs rregs;
475         ubyte *ipx_real_buffer;
476         int i;
477
478 //      atexit(ipx_close);
479
480         ipx_packetnum = 0;
481
482         // init packet buffers.
483         for (i=0; i<MAX_PACKETS; i++ )  {
484                 packet_buffers[i].packetnum = -1;
485                 packet_free_list[i] = i;
486         }
487         num_packets = 0;
488         largest_packet_index = 0;
489
490         // Get the IPX vector
491         memset(&rregs,0,sizeof(dpmi_real_regs));
492         rregs.eax=0x00007a00;
493         dpmi_real_int386x( 0x2f, &rregs );
494
495         if ( (rregs.eax & 0xFF) != 0xFF )       {
496                 return 3;   
497         }
498         ipx_vector_offset = rregs.edi & 0xFFFF;
499         ipx_vector_segment = rregs.es;
500         //printf( "IPX entry point at %.4x:%.4x\n", ipx_vector_segment, ipx_vector_offset );
501
502         // Open a socket for IPX
503
504         memset(&rregs,0,sizeof(dpmi_real_regs));
505         swab( (char *)&socket_number,(char *)&ipx_socket, 2 );
506         rregs.edx = ipx_socket;
507         rregs.eax = ipx_socket_life;
508         rregs.ebx = 0;  // Open socket
509         dpmi_real_int386x( 0x7A, &rregs );
510         
511         ipx_socket = rregs.edx & 0xFFFF;
512         
513         if ( rregs.eax & 0xFF ) {
514                 //mprintf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
515                 return -2;
516         }
517         
518         ipx_installed = 1;
519
520         // Find our internetwork address
521         ipx_real_buffer = dpmi_get_temp_low_buffer( 1024 );     // 1k block
522         if ( ipx_real_buffer == NULL )  {
523                 //printf( "Error allocation realmode memory\n" );
524                 return -4;
525         }
526
527         memset(&rregs,0,sizeof(dpmi_real_regs));
528         rregs.ebx = 9;          // Get internetwork address
529         rregs.esi = DPMI_real_offset(ipx_real_buffer);
530         rregs.es = DPMI_real_segment(ipx_real_buffer);
531         dpmi_real_int386x( 0x7A, &rregs );
532
533         if ( rregs.eax & 0xFF ) {
534                 //printf( "Error getting internetwork address!\n" );
535                 return -2;
536         }
537
538 /*      memcpy( &ipx_network, ipx_real_buffer, 4 );
539         memcpy( ipx_my_node, &ipx_real_buffer[4], 6 );*/
540         memcpy(ipx_MyAddress,ipx_real_buffer,10);
541
542         if ( show_address )     {
543                 printf( "My IPX addresss is " );
544                 printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] );
545                 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] );
546                 printf( "\n" );
547         }
548
549         packets = dpmi_real_malloc( sizeof(ipx_packet)*ipx_num_packets, &ipx_packets_selector );
550         if ( packets == NULL )  {
551                 //printf( "Couldn't allocate real memory for %d packets\n", ipx_num_packets );
552                 return -4;
553         }
554 #if 0 /* adb: not needed, fails with cwsdpmi */
555         if (!dpmi_lock_region( packets, sizeof(ipx_packet)*ipx_num_packets ))   {
556                 //printf( "Couldn't lock real memory for %d packets\n", ipx_num_packets );
557                 return -4;
558         }
559 #endif
560         memset( packets, 0, sizeof(ipx_packet)*ipx_num_packets );
561
562         for (i=1; i<ipx_num_packets; i++ )      {
563                 packets[i].ecb.in_use = 0x1d;
564                 //packets[i].ecb.in_use = 0;
565                 packets[i].ecb.socket_id = ipx_socket;
566                 packets[i].ecb.fragment_count = 1;
567                 packets[i].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[i].ipx);
568                 packets[i].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[i].ipx);
569                 packets[i].ecb.fragment_size = sizeof(ipx_packet)-sizeof(ecb_header);                   //-sizeof(ecb_header);
570
571                 ipx_listen_for_packet(&packets[i].ecb);
572         }
573
574         packets[0].ecb.socket_id = ipx_socket;
575         packets[0].ecb.fragment_count = 1;
576         packets[0].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[0].ipx);
577         packets[0].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[0].ipx);
578         packets[0].ipx.packet_type = 4;         // IPX packet
579         packets[0].ipx.destination.socket_id = ipx_socket;
580 //      memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
581         memset( packets[0].ipx.destination.network_id, 0, 4 );
582
583         return 0;
584 }
585
586 static void ipx_dos_send_packet_data( ubyte * data, int datasize, ubyte *network, ubyte *address, ubyte *immediate_address )
587 {
588         assert(ipx_installed);
589
590         if ( datasize >= IPX_MAX_DATA_SIZE )    {
591                 printf( "Data too big\n" );
592 //added/replaced on 11/8/98 by Victor Rachels to stop crappage
593                 return;
594 //                exit(1);
595 //end this section replacement - VR
596         }
597
598         // Make sure no one is already sending something
599         while( packets[0].ecb.in_use )
600         {
601         }
602         
603         if (packets[0].ecb.completion_code)     {
604 //                printf( "Send error %d for completion code\n", packets[0].ecb.completion_code );
605 //added/replaced on 11/8/98 by Victor Rachels to stop crappage
606                 return;
607         //        exit(1);
608 //end this section replacement - VR
609
610         }
611
612         // Fill in destination address
613         if ( memcmp( network, &ipx_network, 4 ) )
614                 memcpy( packets[0].ipx.destination.network_id, network, 4 );
615         else
616                 memset( packets[0].ipx.destination.network_id, 0, 4 );
617         memcpy( packets[0].ipx.destination.node_id.address, address, 6 );
618         memcpy( packets[0].ecb.immediate_address.address, immediate_address, 6 );
619         packets[0].pd.packetnum = ipx_packetnum++;
620
621         // Fill in data to send
622         packets[0].ecb.fragment_size = sizeof(ipx_header) + sizeof(int) + datasize;
623
624         assert( datasize > 1 );
625         assert( packets[0].ecb.fragment_size <= 576 );
626
627         memcpy( packets[0].pd.data, data, datasize );
628
629         // Send it
630         ipx_send_packet( &packets[0].ecb );
631
632 }
633
634 /*static int ipx_change_default_socket( ushort socket_number )
635 {
636         int i;
637         WORD new_ipx_socket;
638         dpmi_real_regs rregs;
639
640         if ( !ipx_installed ) return -3;
641
642         // Open a new socket    
643         memset(&rregs,0,sizeof(dpmi_real_regs));
644         swab( (char *)&socket_number,(char *)&new_ipx_socket, 2 );
645         rregs.edx = new_ipx_socket;
646         rregs.eax = ipx_socket_life;
647         rregs.ebx = 0;  // Open socket
648         dpmi_real_int386x( 0x7A, &rregs );
649         
650         new_ipx_socket = rregs.edx & 0xFFFF;
651         
652         if ( rregs.eax & 0xFF ) {
653                 //printf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
654                 return -2;
655         }
656
657         for (i=1; i<ipx_num_packets; i++ )      {
658                 ipx_cancel_listen_for_packet(&packets[i].ecb);
659         }
660
661         // Close existing socket...
662         memset(&rregs,0,sizeof(dpmi_real_regs));
663         rregs.edx = ipx_socket;
664         rregs.ebx = 1;  // Close socket
665         dpmi_real_int386x( 0x7A, &rregs );
666
667         ipx_socket = new_ipx_socket;
668
669         // Repost all listen requests on the new socket...      
670         for (i=1; i<ipx_num_packets; i++ )      {
671                 packets[i].ecb.in_use = 0;
672                 packets[i].ecb.socket_id = ipx_socket;
673                 ipx_listen_for_packet(&packets[i].ecb);
674         }
675
676         packets[0].ecb.socket_id = ipx_socket;
677         packets[0].ipx.destination.socket_id = ipx_socket;
678
679         ipx_packetnum = 0;
680         // init packet buffers.
681         for (i=0; i<MAX_PACKETS; i++ )  {
682                 packet_buffers[i].packetnum = -1;
683                 packet_free_list[i] = i;
684         }
685         num_packets = 0;
686         largest_packet_index = 0;
687
688         return 0;
689 }
690 */
691
692 struct ipx_driver ipx_dos = {
693 //      NULL,
694         ipx_dos_init,
695         ipx_dos_close,
696         NULL,
697         NULL,
698         NULL,
699         NULL,
700         1,
701         ipx_dos_get_local_target,
702         ipx_dos_get_packet_data,
703         ipx_dos_send_packet_data
704 };
705
706 struct ipx_driver * arch_ipx_set_driver(char *arg)
707 {
708         return &ipx_dos;
709 }
710
711
712 //---typedef struct rip_entry {
713 //---   uint            network;
714 //---   ushort  nhops;
715 //---   ushort  nticks;
716 //---} rip_entry;
717 //---
718 //---typedef struct rip_packet {
719 //---   ushort          operation;              //1=request, 2=response
720 //---   rip_entry       rip[50];
721 //---} rip_packet;
722 //---
723 //---
724 //---void  ipx_find_all_servers()
725 //---{
726 //---   int i;
727 //---   rip_packet * rp;
728 //---   assert(ipx_installed);
729 //---
730 //---   ipx_change_default_socket( 0x0453 );
731 //---   //      ipx_change_default_socket( 0x5304 );
732 //---
733 //---   // Make sure no one is already sending something
734 //---   while( packets[0].ecb.in_use )
735 //---   {
736 //---   }
737 //---   
738 //---   if (packets[0].ecb.completion_code)     {
739 //---           printf( "AAAA:Send error %d for completion code\n", packets[0].ecb.completion_code );
740 //---           //exit(1);
741 //---   }
742 //---
743 //---   rp = (rip_packet *)&packets[0].pd;
744 //---
745 //---   // Fill in destination address
746 //---   {
747 //---           char mzero1[] = {0,0,0,1};
748 //---           char mzero[] = {0,0,0,0,0,1};
749 //---           char immediate[6];
750 //---           //memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
751 //---           //memcpy( packets[0].ipx.destination.node_id.address, ipx_my_node.address, 6 );
752 //---
753 //---           memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
754 //---           memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
755 //---
756 //---           memcpy( packets[0].ipx.destination.socket_id, &ipx_socket, 2 );
757 //---           memcpy( packets[0].ipx.source.network_id, &ipx_network, 4 );
758 //---           memcpy( packets[0].ipx.source.node_id.address, ipx_my_node.address, 6 );
759 //---           memcpy( packets[0].ipx.source.socket_id, &ipx_socket, 2 );
760 //---           //memcpy( packets[0].ecb.immediate_address.address, ipx_my_node.address, 6 );
761 //---           //mzero1[3] = 1;
762 //---           //memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
763 //---           //mzero[5] = 1;
764 //---           //memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
765 //---           //ipx_get_local_target( mzero1, mzero, immediate );
766 //---           //memcpy( packets[0].ecb.immediate_address.address, mzero, 6 );
767 //---           //memcpy( packets[0].ecb.immediate_address.address, immediate, 6 );
768 //---           //mzero[5] = 0;
769 //---   }
770 //---
771 //---   packets[0].ipx.packet_type = 1;         // RIP packet
772 //---
773 //---   // Fill in data to send
774 //---   packets[0].ecb.fragment_size = sizeof(ipx_header) + sizeof(rip_packet);
775 //---   assert( packets[0].ecb.fragment_size <= 576 );
776 //---
777 //---   rp->operation = 0;              // Request
778 //---   for (i=0;i<50; i++)     {
779 //---           rp->rip[i].network = 0xFFFFFFFF;
780 //---           rp->rip[i].nhops = 0;
781 //---           rp->rip[i].nticks = 0;
782 //---   }
783 //---
784 //---   // Send it
785 //---   ipx_send_packet( &packets[0].ecb );
786 //---
787 //---   for (i=0;i<50; i++)     {
788 //---           if ( rp->rip[i].network != 0xFFFFFFFF )
789 //---                   printf( "Network = %8x, Hops=%d, Ticks=%d\n", rp->rip[i].network, rp->rip[i].nhops, rp->rip[i].nticks );
790 //---   }
791 //---}
792 //---
793 //---