5 #include <sys/socket.h>
8 #ifdef HAVE_NETIPX_IPX_H
9 #include <netipx/ipx.h>
11 # include <linux/ipx.h>
17 #include <netinet/in.h>
26 extern unsigned char ipx_MyAddress[10];
29 ipx_linux_GetMyAddress( void )
32 struct sockaddr_ipx ipxs;
33 struct sockaddr_ipx ipxs2;
37 sock=socket(AF_IPX,SOCK_DGRAM,PF_IPX);
40 n_printf("IPX: could not open socket in GetMyAddress\n");
44 /* bind this socket to network 0 */
45 ipxs.sipx_family=AF_IPX;
46 #ifdef IPX_MANUAL_ADDRESS
47 memcpy(&ipxs.sipx_network, ipx_MyAddress, 4);
53 if(bind(sock,(struct sockaddr *)&ipxs,sizeof(ipxs))==-1)
55 n_printf("IPX: could bind to network 0 in GetMyAddress\n");
61 if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) {
62 n_printf("IPX: could not get socket name in GetMyAddress\n");
67 memcpy(ipx_MyAddress, &ipxs2.sipx_network, 4);
68 for (i = 0; i < 6; i++) {
69 ipx_MyAddress[4+i] = ipxs2.sipx_node[i];
76 ipx_linux_OpenSocket(ipx_socket_t *sk, int port)
78 int sock; /* sock here means Linux socket handle */
80 struct sockaddr_ipx ipxs;
82 struct sockaddr_ipx ipxs2;
84 /* DANG_FIXTHIS - kludge to support broken linux IPX stack */
85 /* need to convert dynamic socket open into a real socket number */
87 n_printf("IPX: using socket %x\n", nextDynamicSocket);
88 port = nextDynamicSocket++;
91 /* do a socket call, then bind to this port */
92 sock = socket(AF_IPX, SOCK_DGRAM, PF_IPX);
94 n_printf("IPX: could not open IPX socket.\n");
100 /* turn on socket debugging */
103 if (setsockopt(sock, SOL_SOCKET, SO_DEBUG, &opt, sizeof(opt)) == -1) {
104 leave_priv_setting();
105 n_printf("IPX: could not set socket option for debugging.\n");
108 leave_priv_setting();
112 /* Permit broadcast output */
114 if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST,
115 &opt, sizeof(opt)) == -1) {
116 leave_priv_setting();
117 n_printf("IPX: could not set socket option for broadcast.\n");
121 /* allow setting the type field in the IPX header */
123 #if 0 /* this seems to be wrong: IPX_TYPE can only be set on level SOL_IPX */
124 if (setsockopt(sock, SOL_SOCKET, IPX_TYPE, &opt, sizeof(opt)) == -1) {
126 /* the socket _is_ an IPX socket, hence it first passes ipx_setsockopt()
127 * in file linux/net/ipx/af_ipx.c. This one handles SOL_IPX itself and
128 * passes SOL_SOCKET-levels down to sock_setsockopt().
129 * Hence I guess the below is correct (can somebody please verify this?)
130 * -- Hans, June 14 1997
132 if (setsockopt(sock, SOL_IPX, IPX_TYPE, &opt, sizeof(opt)) == -1) {
134 leave_priv_setting();
135 n_printf("IPX: could not set socket option for type.\n");
139 ipxs.sipx_family = AF_IPX;
140 ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]);
141 /* ipxs.sipx_network = htonl(MyNetwork); */
142 bzero(ipxs.sipx_node, 6); /* Please fill in my node name */
143 ipxs.sipx_port = htons(port);
145 /* now bind to this port */
146 if (bind(sock, (struct sockaddr *) &ipxs, sizeof(ipxs)) == -1) {
147 n_printf("IPX: could not bind socket to address\n");
149 leave_priv_setting();
155 if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) {
156 n_printf("IPX: could not get socket name in IPXOpenSocket\n");
158 leave_priv_setting();
161 port = htons(ipxs2.sipx_port);
162 n_printf("IPX: opened dynamic socket %04x\n", port);
165 leave_priv_setting();
171 void ipx_linux_CloseSocket(ipx_socket_t *mysock) {
172 /* now close the file descriptor for the socket, and free it */
173 n_printf("IPX: closing file descriptor on socket %x\n", mysock->socket);
177 int ipx_linux_SendPacket(ipx_socket_t *mysock, IPXPacket_t *IPXHeader,
178 u_char *data, int dataLen) {
179 struct sockaddr_ipx ipxs;
181 ipxs.sipx_family = AF_IPX;
182 /* get destination address from IPX packet header */
183 memcpy(&ipxs.sipx_network, IPXHeader->Destination.Network, 4);
184 /* if destination address is 0, then send to my net */
185 if (ipxs.sipx_network == 0) {
186 ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]);
187 /* ipxs.sipx_network = htonl(MyNetwork); */
189 memcpy(&ipxs.sipx_node, IPXHeader->Destination.Node, 6);
190 memcpy(&ipxs.sipx_port, IPXHeader->Destination.Socket, 2);
191 ipxs.sipx_type = IPXHeader->PacketType;
192 /* ipxs.sipx_port=htons(0x452); */
193 return sendto(mysock->fd, data, dataLen, 0,
194 (struct sockaddr *) &ipxs, sizeof(ipxs));
197 int ipx_linux_ReceivePacket(ipx_socket_t *s, char *buffer, int bufsize,
198 struct ipx_recv_data *rd) {
200 struct sockaddr_ipx ipxs;
203 if ((size = recvfrom(s->fd, buffer, bufsize, 0,
204 (struct sockaddr *) &ipxs, &sz)) <= 0)
206 memcpy(rd->src_network, &ipxs.sipx_network, 4);
207 memcpy(rd->src_node, ipxs.sipx_node, 6);
208 rd->src_socket = ipxs.sipx_port;
209 rd->dst_socket = s->socket;
210 rd->pkt_type = ipxs.sipx_type;