1 /* $Id: ipx_kali.c,v 1.7 2003-12-08 22:55:27 btb Exp $ */
4 * IPX driver for KaliNix interface
14 #include <arpa/inet.h>
15 #include <netinet/in.h> /* for htons & co. */
19 extern unsigned char ipx_MyAddress[10];
21 static int open_sockets = 0;
22 static int dynamic_socket = 0x401;
23 static int last_socket = 0;
25 int have_empty_address() {
27 for (i = 0; i < 10 && !ipx_MyAddress[i]; i++) ;
31 int ipx_kali_GetMyAddress(void)
34 kaliaddr_ipx mKaliAddr;
36 if (!have_empty_address())
39 if (KaliGetNodeNum(&mKaliAddr) < 0)
42 memset(ipx_MyAddress, 0, 4);
43 memcpy(ipx_MyAddress + 4, mKaliAddr.sa_nodenum, sizeof(mKaliAddr.sa_nodenum));
48 int ipx_kali_OpenSocket(ipx_socket_t *sk, int port)
50 printf("IPX_kali: OpenSocket on port(%d)\n", port);
53 if (have_empty_address()) {
54 if (ipx_kali_GetMyAddress() < 0) {
55 printf("IPX_kali: Error communicating with KaliNix\n");
61 port = dynamic_socket++;
63 if ((sk->fd = KaliOpenSocket(htons(port))) < 0) {
64 printf("IPX_kali: OpenSocket Failed on port(%d)\n", port);
74 void ipx_kali_CloseSocket(ipx_socket_t *mysock)
77 printf("IPX_kali: close w/o open\n");
80 printf("IPX_kali: CloseSocket on port(%d)\n", mysock->socket);
81 KaliCloseSocket(mysock->fd);
83 printf("IPX_kali: (closesocket) %d sockets left\n", open_sockets);
88 int ipx_kali_SendPacket(ipx_socket_t *mysock, IPXPacket_t *IPXHeader,
89 u_char *data, int dataLen)
94 memcpy(toaddr.sa_nodenum, IPXHeader->Destination.Node, sizeof(toaddr.sa_nodenum));
95 memcpy(&toaddr.sa_socket, IPXHeader->Destination.Socket, sizeof(toaddr.sa_socket));
97 if ((i = KaliSendPacket(mysock->fd, (char *)data, dataLen, &toaddr)) < 0)
103 int ipx_kali_ReceivePacket(ipx_socket_t *s, char *outbuf, int outbufsize,
104 struct ipx_recv_data *rd)
107 kaliaddr_ipx fromaddr;
109 if ((size = KaliReceivePacket(s->fd, outbuf, outbufsize, &fromaddr)) < 0)
112 rd->dst_socket = s->socket;
113 rd->src_socket = ntohs(fromaddr.sa_socket);
114 memcpy(rd->src_node, fromaddr.sa_nodenum, sizeof(fromaddr.sa_nodenum));
115 memset(rd->src_network, 0, 4);
121 struct ipx_driver ipx_kali = {
122 ipx_kali_GetMyAddress,
124 ipx_kali_CloseSocket,
126 ipx_kali_ReceivePacket,
127 ipx_general_PacketReady,
128 NULL, // InitNetgameAuxData
129 NULL, // HandleNetgameAuxData
130 NULL, // HandleLeaveGame
131 NULL // SendGamePacket