2 * $Source: /cvs/cvsroot/d2x/arch/linux/ipx_kali.c,v $
5 * $Date: 2001-10-19 07:39:26 $
7 * IPX driver for KaliNix interface
9 * $Log: not supported by cvs2svn $
10 * Revision 1.2 2001/10/19 07:29:36 bradleyb
11 * Brought linux networking in line with d1x, moved some arch/linux_* stuff to arch/linux/
22 #include <netinet/in.h> /* for htons & co. */
26 static ipx_socket_t mysock;
28 static int open_sockets = 0;
29 static int dynamic_socket = 0x401;
30 //static int last_socket = 0;
32 int have_empty_address() {
34 for (i = 0; i < 10 && !ipx_MyAddress[i]; i++) ;
38 int ipx_kali_GetMyAddress(void) {
40 kaliaddr_ipx mKaliAddr;
42 if (!have_empty_address())
45 if (KaliGetNodeNum(&mKaliAddr) < 0)
48 memset(ipx_MyAddress, 0, 4);
49 memcpy(ipx_MyAddress + 4, mKaliAddr.sa_nodenum, sizeof(mKaliAddr.sa_nodenum));
54 int ipx_kali_OpenSocket(int port) {
55 printf("IPX_kali: OpenSocket on port(%d)\n", port);
58 if (have_empty_address()) {
59 if (ipx_kali_GetMyAddress() < 0) {
60 printf("IPX_kali: Error communicating with KaliNix\n");
66 port = dynamic_socket++;
68 if ((mysock.fd = KaliOpenSocket(htons(port))) < 0) {
69 printf("IPX_kali: OpenSocket Failed on port(%d)\n", port);
74 // last_socket = port;
79 void ipx_kali_CloseSocket(void) {
81 printf("IPX_kali: close w/o open\n");
84 printf("IPX_kali: CloseSocket on port(%d)\n", mysock.socket);
85 KaliCloseSocket(mysock.fd);
87 printf("IPX_kali: (closesocket) %d sockets left\n", open_sockets);
92 int ipx_kali_SendPacket(IPXPacket_t *IPXHeader,
93 u_char *data, int dataLen) {
97 memcpy(toaddr.sa_nodenum, IPXHeader->Destination.Node, sizeof(toaddr.sa_nodenum));
98 // memcpy(&toaddr.sa_socket, IPXHeader->Destination.Socket, sizeof(toaddr.sa_socket));
99 toaddr.sa_socket=htons(mysock.socket);
101 if ((i = KaliSendPacket(mysock.fd, (char *)data, dataLen, &toaddr)) < 0)
107 int ipx_kali_ReceivePacket(char *outbuf, int outbufsize,
108 struct ipx_recv_data *rd) {
110 kaliaddr_ipx fromaddr;
112 if ((size = KaliReceivePacket(mysock.fd, outbuf, outbufsize, &fromaddr)) < 0)
115 rd->dst_socket = mysock.socket;
116 rd->src_socket = ntohs(fromaddr.sa_socket);
117 memcpy(rd->src_node, fromaddr.sa_nodenum, sizeof(fromaddr.sa_nodenum));
118 memset(rd->src_network, 0, 4);
124 static int ipx_kali_general_PacketReady(void) {
125 return ipx_general_PacketReady(mysock.fd);
128 struct ipx_driver ipx_kali = {
129 // ipx_kali_GetMyAddress,
131 ipx_kali_CloseSocket,
133 ipx_kali_ReceivePacket,
134 ipx_kali_general_PacketReady,