]> icculus.org git repositories - btb/d2x.git/blob - arch/linux/ipx_udp.c
remove rcs tags
[btb/d2x.git] / arch / linux / ipx_udp.c
1 /*
2  *
3  * IPX driver for native Linux TCP/IP networking (UDP implementation)
4  *   Version 0.99.2
5  * Contact Jan [Lace] Kratochvil <short@ucw.cz> for assistance
6  * (no "It somehow doesn't work! What should I do?" complaints, please)
7  * Special thanks to Vojtech Pavlik <vojtech@ucw.cz> for testing.
8  *
9  * Also you may see KIX - KIX kix out KaliNix (in Linux-Linux only):
10  *   http://atrey.karlin.mff.cuni.cz/~short/sw/kix.c.gz
11  *
12  * Primarily based on ipx_kali.c - "IPX driver for KaliNix interface"
13  *   which is probably mostly by Jay Cotton <jay@kali.net>.
14  * Parts shamelessly stolen from my KIX v0.99.2 and GGN v0.100
15  *
16  * Changes:
17  * --------
18  * 0.99.1 - now the default broadcast list also contains all point-to-point
19  *          links with their destination peer addresses
20  * 0.99.2 - commented a bit :-) 
21  *        - now adds to broadcast list each host it gets some packet from
22  *          which is already not covered by local physical ethernet broadcast
23  *        - implemented short-signature packet format
24  *        - compatibility mode for old D1X releases due to the previous bullet
25  *
26  * Configuration:
27  * --------------
28  * No network server software is needed, neither KIX nor KaliNIX.
29  *
30  *    NOTE: with the change to allow the user to choose the network
31  *    driver from the game menu, the following is not anymore precise:
32  *    the command line argument "-udp" is only necessary to supply udp
33  *    options!
34  *
35  * Add command line argument "-udp". In default operation D1X will send
36  * broadcasts too all the local interfaces found. But you may also use
37  * additional parameter specified after "-udp" to modify the default
38  * broadcasting style and UDP port numbers binding:
39  *
40  * ./d1x -udp [@SHIFT]=HOST_LIST   Broadcast ONLY to HOST_LIST
41  * ./d1x -udp [@SHIFT]+HOST_LIST   Broadcast both to local ifaces & to HOST_LIST
42  *
43  * HOST_LIST is a comma (',') separated list of HOSTs:
44  * HOST is an IPv4 address (so-called quad like 192.168.1.2) or regular hostname
45  * HOST can also be in form 'address:SHIFT'
46  * SHIFT sets the UDP port base offset (e.g. +2), can be used to run multiple
47  *       clients on one host simultaneously. This SHIFT has nothing to do
48  *       with the dynamic-sockets (PgUP/PgDOWN) option in Descent, it's another
49  *       higher-level differentiation option.
50  *
51  * Examples:
52  * ---------
53  * ./d1x -udp
54  *  - Run D1X to participate in normal local network (Linux only, of course)
55  *
56  * ./d1x -udp @1=localhost:2 & ./d1x -udp @2=localhost:1
57  *  - Run two clients simultaneously fighting each other (only each other)
58  *
59  * ./d1x -udp =192.168.4.255
60  *  - Run distant Descent which will participate with remote network
61  *    192.168.4.0 with netmask 255.255.255.0 (broadcast has 192.168.4.255)
62  *  - You'll have to also setup hosts in that network accordingly:
63  * ./d1x -udp +UPPER_DISTANT_MACHINE_NAME
64  *
65  * Have fun!
66  *
67  */
68
69 #ifdef HAVE_CONFIG_H
70 #include <conf.h>
71 #endif
72
73 #include <stdio.h>
74 #include <string.h>
75 #include <arpa/inet.h>
76 #include <netinet/in.h> /* for htons & co. */
77 #include <unistd.h>
78 #include <stdarg.h>
79 #include <netdb.h>
80 #include <stdlib.h>
81 #ifdef __sun
82 #  include <alloca.h>
83 #endif
84 #include <sys/ioctl.h>
85 #include <sys/socket.h>
86 #ifdef __sun__
87 #  include <sys/sockio.h>
88 #endif
89 #include <net/if.h>
90 #include <ctype.h>
91
92 #include "ipx_drv.h"
93 #include "args.h"
94
95 extern unsigned char ipx_MyAddress[10];
96
97 // #define UDPDEBUG
98
99 #define UDP_BASEPORT 28342
100 #define PORTSHIFT_TOLERANCE 0x100
101 #define MAX_PACKETSIZE 8192
102
103 /* Packet format: first is the signature { 0xD1,'X' } which can be also
104  * { 'D','1','X','u','d','p'} for old-fashioned packets.
105  * Then follows virtual socket number (as changed during PgDOWN/PgUP)
106  * in network-byte-order as 2 bytes (u_short). After such 4/8 byte header
107  * follows raw data as communicated with D1X network core functions.
108  */
109
110 // Length HAS TO BE 6!
111 #define D1Xudp "D1Xudp"
112 // Length HAS TO BE 2!
113 #define D1Xid "\xD1X"
114
115 static int open_sockets = 0;
116 static int dynamic_socket = 0x401;
117 static const int val_one=1;
118
119 /* OUR port. Can be changed by "@X[+=]..." argument (X is the shift value)
120  */
121
122 static int baseport=UDP_BASEPORT;
123
124 /* Have we some old D1X in network and have we to maintain compatibility?
125  * FIXME: Following scenario is braindead:
126  *                                           A  (NEW) , B  (OLD) , C  (NEW)
127  *   host A) We start new D1X.               A-newcomm, B-none   , C-none
128  *   host B) We start OLD D1X.               A-newcomm, B-oldcomm, C-none
129  *   Now host A hears host B and switches:   A-oldcomm, B-oldcomm, C-none
130  *   host C) We start new D1X.               A-oldcomm, B-oldcomm, C-newcomm
131  *   Now host C hears host A/B and switches: A-oldcomm, B-oldcomm, C-oldcomm
132  *   Now host B finishes:                    A-oldcomm, B-none   , C-oldcomm
133  *
134  * But right now we have hosts A and C, both new code equipped but
135  * communicating wastefully by the OLD protocol! Bummer.
136  */
137
138 static char compatibility=0;
139
140 static int have_empty_address() {
141         int i;
142         for (i = 0; i < 10 && !ipx_MyAddress[i]; i++) ;
143         return i == 10;
144 }
145
146 #define MSGHDR "IPX_udp: "
147
148 static void msg(const char *fmt,...)
149 {
150 va_list ap;
151         fputs(MSGHDR,stdout);
152         va_start(ap,fmt);
153         vprintf(fmt,ap);
154         va_end(ap);
155         putchar('\n');
156 }
157
158 static void chk(void *p)
159 {
160         if (p) return;
161         msg("FATAL: Virtual memory exhausted!");
162         exit(EXIT_FAILURE);
163 }
164
165 #define FAIL(m...) do { msg(#m); return -1; } while (0)
166
167 /* Find as much as MAX_BRDINTERFACES during local iface autoconfiguration.
168  * Note that more interfaces can be added during manual configuration
169  * or host-received-packet autoconfiguration
170  */
171
172 #define MAX_BRDINTERFACES 16
173
174 /* We require the interface to be UP and RUNNING to accept it.
175  */
176
177 #define IF_REQFLAGS (IFF_UP|IFF_RUNNING)
178
179 /* We reject any interfaces declared as LOOPBACK type.
180  */
181 #define IF_NOTFLAGS (IFF_LOOPBACK)
182
183 static struct sockaddr_in *broads,broadmasks[MAX_BRDINTERFACES];
184 static int broadnum,masksnum,broadsize;
185
186 /* We'll check whether the "broads" array of destination addresses is now
187  * full and so needs expanding.
188  */
189
190 static void chkbroadsize(void)
191 {
192         if (broadnum<broadsize) return;
193         broadsize=broadsize?broadsize*2:8;
194         chk(broads=realloc(broads,sizeof(*broads)*broadsize));
195 }
196
197 /* This function is called during init and has to grab all system interfaces
198  * and collect their broadcast-destination addresses (and their netmasks).
199  * Typically it founds only one ethernet card and so returns address in
200  * the style "192.168.1.255" with netmask "255.255.255.0".
201  * Broadcast addresses are filled into "broads", netmasks to "broadmasks".
202  */
203
204 /* Stolen from my GGN */
205 static int addiflist(void)
206 {
207 unsigned cnt=MAX_BRDINTERFACES,i,j;
208 struct ifconf ifconf;
209 int sock;
210 struct sockaddr_in *sinp,*sinmp;
211
212         free(broads);
213         if ((sock=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP))<0)
214                 FAIL("Creating socket() failure during broadcast detection: %m");
215
216 #ifdef SIOCGIFCOUNT
217         if (ioctl(sock,SIOCGIFCOUNT,&cnt))
218                 { /* msg("Getting iterface count error: %m"); */ }
219         else
220                 cnt=cnt*2+2;
221 #endif
222
223         chk(ifconf.ifc_req=alloca((ifconf.ifc_len=cnt*sizeof(struct ifreq))));
224         if (ioctl(sock,SIOCGIFCONF,&ifconf)||ifconf.ifc_len%sizeof(struct ifreq)) {
225                 close(sock);
226                 FAIL("ioctl(SIOCGIFCONF) failure during broadcast detection: %m");
227                 }
228         cnt=ifconf.ifc_len/sizeof(struct ifreq);
229         chk(broads=malloc(cnt*sizeof(*broads)));
230         broadsize=cnt;
231         for (i=j=0;i<cnt;i++) {
232                 if (ioctl(sock,SIOCGIFFLAGS,ifconf.ifc_req+i)) {
233                         close(sock);
234                         FAIL("ioctl(udp,\"%s\",SIOCGIFFLAGS) error: %m",ifconf.ifc_req[i].ifr_name);
235                         }
236                 if (((ifconf.ifc_req[i].ifr_flags&IF_REQFLAGS)!=IF_REQFLAGS)||
237                                  (ifconf.ifc_req[i].ifr_flags&IF_NOTFLAGS))
238                         continue;
239                 if (ioctl(sock,(ifconf.ifc_req[i].ifr_flags&IFF_BROADCAST?SIOCGIFBRDADDR:SIOCGIFDSTADDR),ifconf.ifc_req+i)) {
240                         close(sock);
241                         FAIL("ioctl(udp,\"%s\",SIOCGIF{DST/BRD}ADDR) error: %m",ifconf.ifc_req[i].ifr_name);
242                         }
243
244                 sinp = (struct sockaddr_in *)&ifconf.ifc_req[i].ifr_broadaddr;
245 #if 0 // old, not portable code
246                 sinmp = (struct sockaddr_in *)&ifconf.ifc_req[i].ifr_netmask;
247 #else // portable code
248                 if (ioctl(sock, SIOCGIFNETMASK, ifconf.ifc_req+i)) {
249                         close(sock);
250                         FAIL("ioctl(udp,\"%s\",SIOCGIFNETMASK) error: %m", ifconf.ifc_req[i].ifr_name);
251                 }
252                 sinmp = (struct sockaddr_in *)&ifconf.ifc_req[i].ifr_addr;
253 #endif
254                 if (sinp->sin_family!=AF_INET || sinmp->sin_family!=AF_INET) continue;
255                 broads[j]=*sinp;
256                 broads[j].sin_port=UDP_BASEPORT; //FIXME: No possibility to override from cmdline
257                 broadmasks[j]=*sinmp;
258                 j++;
259                 }
260         broadnum=j;
261         masksnum=j;
262         return(0);
263 }
264
265 #define addreq(a,b) ((a).sin_port==(b).sin_port&&(a).sin_addr.s_addr==(b).sin_addr.s_addr)
266
267 /* Previous function addiflist() can (and probably will) report multiple
268  * same addresses. On some Linux boxes is present both device "eth0" and
269  * "dummy0" with the same IP addreesses - we'll filter it here.
270  */
271
272 static void unifyiflist(void)
273 {
274 int d=0,s,i;
275
276         for (s=0;s<broadnum;s++) {
277                 for (i=0;i<s;i++)
278                         if (addreq(broads[s],broads[i])) break;
279                 if (i>=s) broads[d++]=broads[s];
280                 }
281         broadnum=d;
282 }
283
284 static unsigned char qhbuf[6];
285
286 /* Parse PORTSHIFT numeric parameter
287  */
288
289 static void portshift(const char *cs)
290 {
291 long port;
292 unsigned short ports=0;
293
294         port=atol(cs);
295         if (port<-PORTSHIFT_TOLERANCE || port>+PORTSHIFT_TOLERANCE)
296                 msg("Invalid portshift in \"%s\", tolerance is +/-%d",cs,PORTSHIFT_TOLERANCE);
297         else ports=htons(port);
298         memcpy(qhbuf+4,&ports,2);
299 }
300
301 /* Do hostname resolve on name "buf" and return the address in buffer "qhbuf".
302  */
303 static unsigned char *queryhost(char *buf)
304 {
305 struct hostent *he;
306 char *s;
307 char c=0;
308
309         if ((s=strrchr(buf,':'))) {
310           c=*s;
311           *s='\0';
312           portshift(s+1);
313           }
314         else memset(qhbuf+4,0,2);
315         he=gethostbyname((char *)buf);
316         if (s) *s=c;
317         if (!he) {
318                 msg("Error resolving my hostname \"%s\"",buf);
319                 return(NULL);
320                 }
321         if (he->h_addrtype!=AF_INET || he->h_length!=4) {
322           msg("Error parsing resolved my hostname \"%s\"",buf);
323                 return(NULL);
324                 }
325         if (!*he->h_addr_list) {
326           msg("My resolved hostname \"%s\" address list empty",buf);
327                 return(NULL);
328                 }
329         memcpy(qhbuf,(*he->h_addr_list),4);
330         return(qhbuf);
331 }
332
333 /* Dump raw form of IP address/port by fancy output to user
334  */
335 static void dumpraddr(unsigned char *a)
336 {
337 short port;
338         printf("[%u.%u.%u.%u]",a[0],a[1],a[2],a[3]);
339         port=(signed short)ntohs(*(unsigned short *)(a+4));
340         if (port) printf(":%+d",port);
341 }
342
343 /* Like dumpraddr() but for structure "sockaddr_in"
344  */
345
346 static void dumpaddr(struct sockaddr_in *sin)
347 {
348 unsigned short ports;
349
350         memcpy(qhbuf+0,&sin->sin_addr,4);
351         ports=htons(((short)ntohs(sin->sin_port))-UDP_BASEPORT);
352         memcpy(qhbuf+4,&ports,2);
353         dumpraddr(qhbuf);
354 }
355
356 /* Startup... Uninteresting parsing...
357  */
358
359 int ipx_udp_GetMyAddress(void) {
360
361 char buf[256];
362 int i;
363 char *s,*s2,*ns;
364
365         if (!have_empty_address())
366                 return 0;
367
368         if (!((i=FindArg("-udp")) && (s=Args[i+1]) && (*s=='=' || *s=='+' || *s=='@'))) s=NULL;
369
370         if (gethostname(buf,sizeof(buf))) FAIL("Error getting my hostname");
371         if (!(queryhost(buf))) FAIL("Querying my own hostname \"%s\"",buf);
372
373         if (s) while (*s=='@') {
374                 portshift(++s);
375                 while (isdigit(*s)) s++;
376                 }
377
378         memset(ipx_MyAddress+0,0,4);
379         memcpy(ipx_MyAddress+4,qhbuf,6);
380         baseport+=(short)ntohs(*(unsigned short *)(qhbuf+4));
381
382         if (!s || (s && !*s)) addiflist();
383         else {
384                 if (*s=='+') addiflist();
385                 s++;
386                 for (;;) {
387 struct sockaddr_in *sin;
388                         while (isspace(*s)) s++;
389                         if (!*s) break;
390                         for (s2=s;*s2 && *s2!=',';s2++);
391                         chk(ns=malloc(s2-s+1));
392                         memcpy(ns,s,s2-s);
393                         ns[s2-s]='\0';
394                         if (!queryhost(ns)) msg("Ignored broadcast-destination \"%s\" as being invalid",ns);
395                         free(ns);
396                         chkbroadsize();
397                         sin=broads+(broadnum++);
398                         sin->sin_family=AF_INET;
399                         memcpy(&sin->sin_addr,qhbuf+0,4);
400                         sin->sin_port=htons(((short)ntohs(*(unsigned short *)(qhbuf+4)))+UDP_BASEPORT);
401                         s=s2+(*s2==',');
402                         }
403                 }
404
405         unifyiflist();
406
407         printf(MSGHDR "Using TCP/IP address ");
408         dumpraddr(ipx_MyAddress+4);
409         putchar('\n');
410         if (broadnum) {
411                 printf(MSGHDR "Using %u broadcast-dest%s:",broadnum,(broadnum==1?"":"s"));
412                 for (i=0;i<broadnum;i++) {
413                         putchar(' ');
414                         dumpaddr(broads+i);
415                         }
416                 putchar('\n');
417                 }
418
419         return 0;
420 }
421
422 /* We should probably avoid such insanity here as during PgUP/PgDOWN
423  * (virtual port number change) we wastefully destroy/create the same
424  * socket here (binded always to "baseport"). FIXME.
425  * "open_sockets" can be only 0 or 1 anyway.
426  */
427
428 static int ipx_udp_OpenSocket(ipx_socket_t *sk, int port) {
429 struct sockaddr_in sin;
430
431         if (!open_sockets)
432                 if (have_empty_address())
433                 if (ipx_udp_GetMyAddress() < 0) FAIL("Error getting my address");
434
435         msg("OpenSocket on D1X socket port %d",port);
436
437         if (!port)
438                 port = dynamic_socket++;
439
440         if ((sk->fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP)) < 0) {
441                 sk->fd = -1;
442                 FAIL("socket() creation failed on port %d: %m",port);
443                 }
444   if (setsockopt(sk->fd,SOL_SOCKET,SO_BROADCAST,&val_one,sizeof(val_one))) {
445                 if (close(sk->fd)) msg("close() failed during error recovery: %m");
446                 sk->fd=-1;
447                 FAIL("setsockopt(SO_BROADCAST) failed: %m");
448                 }
449         sin.sin_family=AF_INET;
450         sin.sin_addr.s_addr=htonl(INADDR_ANY);
451         sin.sin_port=htons(baseport);
452         if (bind(sk->fd,(struct sockaddr *)&sin,sizeof(sin))) {
453                 if (close(sk->fd)) msg("close() failed during error recovery: %m");
454                 sk->fd=-1;
455                 FAIL("bind() to UDP port %d failed: %m",baseport);
456                 }
457
458         open_sockets++;
459         sk->socket = port;
460         return 0;
461 }
462
463 /* The same comment as in previous "ipx_udp_OpenSocket"...
464  */
465
466 static void ipx_udp_CloseSocket(ipx_socket_t *mysock) {
467         if (!open_sockets) {
468                 msg("close w/o open");
469                 return;
470         }
471         msg("CloseSocket on D1X socket port %d",mysock->socket);
472         if (close(mysock->fd))
473                 msg("close() failed on CloseSocket D1X socket port %d: %m",mysock->socket);
474         mysock->fd=-1;
475         if (--open_sockets) {
476                 msg("(closesocket) %d sockets left", open_sockets);
477                 return;
478         }
479 }
480
481 /* Here we'll send the packet to our host. If it is unicast packet, send
482  * it to IP address/port as retrieved from IPX address. Otherwise (broadcast)
483  * we'll repeat the same data to each host in our broadcasting list.
484  */
485
486 static int ipx_udp_SendPacket(ipx_socket_t *mysock, IPXPacket_t *IPXHeader,
487  u_char *data, int dataLen) {
488         struct sockaddr_in toaddr,*dest;
489         int i=dataLen;
490         int bcast;
491         char *buf;
492
493 #ifdef UDPDEBUG
494         msg("SendPacket enter, dataLen=%d",dataLen);
495 #endif
496         if (dataLen<0 || dataLen>MAX_PACKETSIZE) return -1;
497         chk(buf=alloca(8+dataLen));
498         if (compatibility) memcpy(buf+0,D1Xudp,6),buf+=6;
499         else               memcpy(buf+0,D1Xid ,2),buf+=2;
500         memcpy(buf+0,IPXHeader->Destination.Socket,2);
501         memcpy(buf+2,data,dataLen);
502  
503         toaddr.sin_family=AF_INET;
504         memcpy(&toaddr.sin_addr,IPXHeader->Destination.Node+0,4);
505         toaddr.sin_port=htons(((short)ntohs(*(unsigned short *)(IPXHeader->Destination.Node+4)))+UDP_BASEPORT);
506
507         for (bcast=(toaddr.sin_addr.s_addr==htonl(INADDR_BROADCAST)?0:-1);bcast<broadnum;bcast++) {
508                 if (bcast>=0) dest=broads+bcast;
509                 else dest=&toaddr;
510         
511 #ifdef UDPDEBUG
512                 printf(MSGHDR "sendto((%d),Node=[4] %02X %02X,Socket=%02X %02X,s_port=%u,",
513                         dataLen,
514                         IPXHeader->Destination.Node  [4],IPXHeader->Destination.Node  [5],
515                         IPXHeader->Destination.Socket[0],IPXHeader->Destination.Socket[1],
516                         ntohs(dest->sin_port));
517                 dumpaddr(dest);
518                 puts(").");
519 #endif
520                 i=sendto(mysock->fd,buf-(compatibility?6:2),(compatibility?8:4)+dataLen,
521                         0,(struct sockaddr *)dest,sizeof(*dest));
522                 if (bcast==-1) return (i<8?-1:i-8);
523                 }
524         return(dataLen);
525 }
526
527 /* Here we will receive new packet to the given buffer. Both formats of packets
528  * are supported, we fallback to old format when first obsolete packet is seen.
529  * If the (valid) packet is received from unknown host, we will add it to our
530  * broadcasting list. FIXME: For now such autoconfigured hosts are NEVER removed.
531  */
532
533 static int ipx_udp_ReceivePacket(ipx_socket_t *s, char *outbuf, int outbufsize, 
534  struct ipx_recv_data *rd) {
535         int size;
536         struct sockaddr_in fromaddr;
537         uint fromaddrsize=sizeof(fromaddr);
538         unsigned short ports;
539         size_t offs;
540         int i;
541
542         if ((size=recvfrom(s->fd,outbuf,outbufsize,0,(struct sockaddr *)&fromaddr,&fromaddrsize))<0)
543                 return -1;
544 #ifdef UDPDEBUG
545         printf(MSGHDR "recvfrom((%d-8=%d),",size,size-8);
546         dumpaddr(&fromaddr);
547         puts(").");
548 #endif
549         if (fromaddr.sin_family!=AF_INET) return -1;
550         if (size<4) return -1;
551         if (memcmp(outbuf+0,D1Xid,2)) {
552                 if (size<8 || memcmp(outbuf+0,D1Xudp,6)) return -1;
553                 if (!compatibility) {
554                         compatibility=1;
555                         fputs(MSGHDR "Received obsolete packet from ",stdout);
556                         dumpaddr(&fromaddr);
557                         puts(", upgrade that machine.\n" MSGHDR "Turning on compatibility mode...");
558                         }
559                 offs=6;
560                 }
561         else offs=2;
562
563         /* Lace: (dst_socket & src_socket) should be network-byte-order by comment in include/ipx_drv.h */
564         /*       This behaviour presented here is broken. It is not used anywhere, so why bother? */
565         rd->src_socket = ntohs(*(unsigned short *)(outbuf+offs));
566         if (rd->src_socket != s->socket) {
567 #ifdef UDPDEBUG
568                 msg(" - pkt was dropped (dst=%d,my=%d)",rd->src_socket,s->socket);
569 #endif
570                 return -1;
571                 }
572         rd->dst_socket = s->socket;
573
574         // check if we already have sender of this packet in broadcast list
575         for (i=0;i<broadnum;i++) {
576                 if (i>=masksnum) {
577                         if (addreq(fromaddr,broads[i])) break; 
578                         }
579                 else {
580                         if (fromaddr.sin_port==broads[i].sin_port
581                         &&( fromaddr.sin_addr.s_addr & broadmasks[i].sin_addr.s_addr)
582                         ==(broads[i].sin_addr.s_addr & broadmasks[i].sin_addr.s_addr)) break;
583                         }
584                 }
585         if (i>=broadnum) { // we don't have sender of this packet in our broadcast list
586                 chkbroadsize();
587                 broads[broadnum++]=fromaddr;
588                 fputs(MSGHDR "Adding host ",stdout);
589                 dumpaddr(&fromaddr);
590                 puts(" to broadcasting address list");
591                 }
592
593         memmove(outbuf,outbuf+offs+2,size-(offs+2));
594         size-=offs+2;
595
596         memcpy(rd->src_node+0,&fromaddr.sin_addr,4);
597         ports=htons(ntohs(fromaddr.sin_port)-UDP_BASEPORT);
598         memcpy(rd->src_node+4,&ports,2);
599         memset(rd->src_network, 0, 4);
600         rd->pkt_type = 0;
601 #ifdef UDPDEBUG
602         printf(MSGHDR "ReceivePacket: size=%d,from=",size);
603         dumpraddr(rd->src_node);
604         putchar('\n');
605 #endif
606
607         return size;
608 }
609
610 struct ipx_driver ipx_udp = {
611         ipx_udp_GetMyAddress,
612         ipx_udp_OpenSocket,
613         ipx_udp_CloseSocket,
614         ipx_udp_SendPacket,
615         ipx_udp_ReceivePacket,
616         ipx_general_PacketReady,
617         NULL,   // InitNetgameAuxData
618         NULL,   // HandleNetgameAuxData
619         NULL,   // HandleLeaveGame
620         NULL    // SendGamePacket
621 };