1 /* IPX driver for KaliNix interface */
4 #include <netinet/in.h> /* for htons & co. */
8 extern unsigned char ipx_MyAddress[10];
10 static int open_sockets = 0;
11 static int dynamic_socket = 0x401;
12 static int last_socket = 0;
14 int have_empty_address() {
16 for (i = 0; i < 10 && !ipx_MyAddress[i]; i++) ;
20 int ipx_kali_GetMyAddress(void) {
22 kaliaddr_ipx mKaliAddr;
24 if (!have_empty_address())
27 if (KaliGetNodeNum(&mKaliAddr) < 0)
30 memset(ipx_MyAddress, 0, 4);
31 memcpy(ipx_MyAddress + 4, mKaliAddr.sa_nodenum, sizeof(mKaliAddr.sa_nodenum));
36 int ipx_kali_OpenSocket(ipx_socket_t *sk, int port) {
37 printf("IPX_kali: OpenSocket on port(%d)\n", port);
40 if (have_empty_address()) {
41 if (ipx_kali_GetMyAddress() < 0) {
42 printf("IPX_kali: Error communicating with KaliNix\n");
48 port = dynamic_socket++;
50 if ((sk->fd = KaliOpenSocket(htons(port))) < 0) {
51 printf("IPX_kali: OpenSocket Failed on port(%d)\n", port);
61 void ipx_kali_CloseSocket(ipx_socket_t *mysock) {
63 printf("IPX_kali: close w/o open\n");
66 printf("IPX_kali: CloseSocket on port(%d)\n", mysock->socket);
67 KaliCloseSocket(mysock->fd);
69 printf("IPX_kali: (closesocket) %d sockets left\n", open_sockets);
74 int ipx_kali_SendPacket(ipx_socket_t *mysock, IPXPacket_t *IPXHeader,
75 u_char *data, int dataLen) {
79 memcpy(toaddr.sa_nodenum, IPXHeader->Destination.Node, sizeof(toaddr.sa_nodenum));
80 memcpy(&toaddr.sa_socket, IPXHeader->Destination.Socket, sizeof(toaddr.sa_socket));
82 if ((i = KaliSendPacket(mysock->fd, (char *)data, dataLen, &toaddr)) < 0)
88 int ipx_kali_ReceivePacket(ipx_socket_t *s, char *outbuf, int outbufsize,
89 struct ipx_recv_data *rd) {
91 kaliaddr_ipx fromaddr;
93 if ((size = KaliReceivePacket(s->fd, outbuf, outbufsize, &fromaddr)) < 0)
96 rd->dst_socket = s->socket;
97 rd->src_socket = ntohs(fromaddr.sa_socket);
98 memcpy(rd->src_node, fromaddr.sa_nodenum, sizeof(fromaddr.sa_nodenum));
99 memset(rd->src_network, 0, 4);
105 struct ipx_driver ipx_kali = {
106 ipx_kali_GetMyAddress,
108 ipx_kali_CloseSocket,
110 ipx_kali_ReceivePacket,
111 ipx_general_PacketReady