1 /* $Id: ipx_kali.c,v 1.5 2003-03-13 00:20:21 btb Exp $ */
4 * IPX driver for KaliNix interface
14 #include <netinet/in.h> /* for htons & co. */
18 extern unsigned char ipx_MyAddress[10];
20 static int open_sockets = 0;
21 static int dynamic_socket = 0x401;
22 static int last_socket = 0;
24 int have_empty_address() {
26 for (i = 0; i < 10 && !ipx_MyAddress[i]; i++) ;
30 int ipx_kali_GetMyAddress(void)
33 kaliaddr_ipx mKaliAddr;
35 if (!have_empty_address())
38 if (KaliGetNodeNum(&mKaliAddr) < 0)
41 memset(ipx_MyAddress, 0, 4);
42 memcpy(ipx_MyAddress + 4, mKaliAddr.sa_nodenum, sizeof(mKaliAddr.sa_nodenum));
47 int ipx_kali_OpenSocket(ipx_socket_t *sk, int port)
49 printf("IPX_kali: OpenSocket on port(%d)\n", port);
52 if (have_empty_address()) {
53 if (ipx_kali_GetMyAddress() < 0) {
54 printf("IPX_kali: Error communicating with KaliNix\n");
60 port = dynamic_socket++;
62 if ((sk->fd = KaliOpenSocket(htons(port))) < 0) {
63 printf("IPX_kali: OpenSocket Failed on port(%d)\n", port);
73 void ipx_kali_CloseSocket(ipx_socket_t *mysock)
76 printf("IPX_kali: close w/o open\n");
79 printf("IPX_kali: CloseSocket on port(%d)\n", mysock->socket);
80 KaliCloseSocket(mysock->fd);
82 printf("IPX_kali: (closesocket) %d sockets left\n", open_sockets);
87 int ipx_kali_SendPacket(ipx_socket_t *mysock, IPXPacket_t *IPXHeader,
88 u_char *data, int dataLen)
93 memcpy(toaddr.sa_nodenum, IPXHeader->Destination.Node, sizeof(toaddr.sa_nodenum));
94 memcpy(&toaddr.sa_socket, IPXHeader->Destination.Socket, sizeof(toaddr.sa_socket));
96 if ((i = KaliSendPacket(mysock->fd, (char *)data, dataLen, &toaddr)) < 0)
102 int ipx_kali_ReceivePacket(ipx_socket_t *s, char *outbuf, int outbufsize,
103 struct ipx_recv_data *rd)
106 kaliaddr_ipx fromaddr;
108 if ((size = KaliReceivePacket(s->fd, outbuf, outbufsize, &fromaddr)) < 0)
111 rd->dst_socket = s->socket;
112 rd->src_socket = ntohs(fromaddr.sa_socket);
113 memcpy(rd->src_node, fromaddr.sa_nodenum, sizeof(fromaddr.sa_nodenum));
114 memset(rd->src_network, 0, 4);
120 struct ipx_driver ipx_kali = {
121 ipx_kali_GetMyAddress,
123 ipx_kali_CloseSocket,
125 ipx_kali_ReceivePacket,
126 ipx_general_PacketReady