2 * $Source: /cvs/cvsroot/d2x/arch/linux_ipx_lin.c,v $
5 * $Date: 2001-01-29 13:35:08 $
9 * $Log: not supported by cvs2svn $
17 #include <sys/types.h>
18 #include <sys/socket.h>
21 #ifdef HAVE_NETIPX_IPX_H
22 #include <netipx/ipx.h>
24 # include <linux/ipx.h>
30 #include <netinet/in.h>
39 extern unsigned char ipx_MyAddress[10];
42 ipx_linux_GetMyAddress( void )
45 struct sockaddr_ipx ipxs;
46 struct sockaddr_ipx ipxs2;
50 sock=socket(AF_IPX,SOCK_DGRAM,PF_IPX);
53 n_printf("IPX: could not open socket in GetMyAddress\n");
57 /* bind this socket to network 0 */
58 ipxs.sipx_family=AF_IPX;
59 #ifdef IPX_MANUAL_ADDRESS
60 memcpy(&ipxs.sipx_network, ipx_MyAddress, 4);
66 if(bind(sock,(struct sockaddr *)&ipxs,sizeof(ipxs))==-1)
68 n_printf("IPX: could bind to network 0 in GetMyAddress\n");
74 if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) {
75 n_printf("IPX: could not get socket name in GetMyAddress\n");
80 memcpy(ipx_MyAddress, &ipxs2.sipx_network, 4);
81 for (i = 0; i < 6; i++) {
82 ipx_MyAddress[4+i] = ipxs2.sipx_node[i];
89 ipx_linux_OpenSocket(ipx_socket_t *sk, int port)
91 int sock; /* sock here means Linux socket handle */
93 struct sockaddr_ipx ipxs;
95 struct sockaddr_ipx ipxs2;
97 /* DANG_FIXTHIS - kludge to support broken linux IPX stack */
98 /* need to convert dynamic socket open into a real socket number */
100 n_printf("IPX: using socket %x\n", nextDynamicSocket);
101 port = nextDynamicSocket++;
104 /* do a socket call, then bind to this port */
105 sock = socket(AF_IPX, SOCK_DGRAM, PF_IPX);
107 n_printf("IPX: could not open IPX socket.\n");
113 /* turn on socket debugging */
116 if (setsockopt(sock, SOL_SOCKET, SO_DEBUG, &opt, sizeof(opt)) == -1) {
117 leave_priv_setting();
118 n_printf("IPX: could not set socket option for debugging.\n");
121 leave_priv_setting();
125 /* Permit broadcast output */
127 if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST,
128 &opt, sizeof(opt)) == -1) {
129 leave_priv_setting();
130 n_printf("IPX: could not set socket option for broadcast.\n");
134 /* allow setting the type field in the IPX header */
136 #if 0 /* this seems to be wrong: IPX_TYPE can only be set on level SOL_IPX */
137 if (setsockopt(sock, SOL_SOCKET, IPX_TYPE, &opt, sizeof(opt)) == -1) {
139 /* the socket _is_ an IPX socket, hence it first passes ipx_setsockopt()
140 * in file linux/net/ipx/af_ipx.c. This one handles SOL_IPX itself and
141 * passes SOL_SOCKET-levels down to sock_setsockopt().
142 * Hence I guess the below is correct (can somebody please verify this?)
143 * -- Hans, June 14 1997
145 if (setsockopt(sock, SOL_IPX, IPX_TYPE, &opt, sizeof(opt)) == -1) {
147 leave_priv_setting();
148 n_printf("IPX: could not set socket option for type.\n");
152 ipxs.sipx_family = AF_IPX;
153 ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]);
154 /* ipxs.sipx_network = htonl(MyNetwork); */
155 bzero(ipxs.sipx_node, 6); /* Please fill in my node name */
156 ipxs.sipx_port = htons(port);
158 /* now bind to this port */
159 if (bind(sock, (struct sockaddr *) &ipxs, sizeof(ipxs)) == -1) {
160 n_printf("IPX: could not bind socket to address\n");
162 leave_priv_setting();
168 if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) {
169 n_printf("IPX: could not get socket name in IPXOpenSocket\n");
171 leave_priv_setting();
174 port = htons(ipxs2.sipx_port);
175 n_printf("IPX: opened dynamic socket %04x\n", port);
178 leave_priv_setting();
184 void ipx_linux_CloseSocket(ipx_socket_t *mysock) {
185 /* now close the file descriptor for the socket, and free it */
186 n_printf("IPX: closing file descriptor on socket %x\n", mysock->socket);
190 int ipx_linux_SendPacket(ipx_socket_t *mysock, IPXPacket_t *IPXHeader,
191 u_char *data, int dataLen) {
192 struct sockaddr_ipx ipxs;
194 ipxs.sipx_family = AF_IPX;
195 /* get destination address from IPX packet header */
196 memcpy(&ipxs.sipx_network, IPXHeader->Destination.Network, 4);
197 /* if destination address is 0, then send to my net */
198 if (ipxs.sipx_network == 0) {
199 ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]);
200 /* ipxs.sipx_network = htonl(MyNetwork); */
202 memcpy(&ipxs.sipx_node, IPXHeader->Destination.Node, 6);
203 memcpy(&ipxs.sipx_port, IPXHeader->Destination.Socket, 2);
204 ipxs.sipx_type = IPXHeader->PacketType;
205 /* ipxs.sipx_port=htons(0x452); */
206 return sendto(mysock->fd, data, dataLen, 0,
207 (struct sockaddr *) &ipxs, sizeof(ipxs));
210 int ipx_linux_ReceivePacket(ipx_socket_t *s, char *buffer, int bufsize,
211 struct ipx_recv_data *rd) {
213 struct sockaddr_ipx ipxs;
216 if ((size = recvfrom(s->fd, buffer, bufsize, 0,
217 (struct sockaddr *) &ipxs, &sz)) <= 0)
219 memcpy(rd->src_network, &ipxs.sipx_network, 4);
220 memcpy(rd->src_node, ipxs.sipx_node, 6);
221 rd->src_socket = ipxs.sipx_port;
222 rd->dst_socket = s->socket;
223 rd->pkt_type = ipxs.sipx_type;