2 * Copyright (c) 2006 Robert N. M. Watson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Simple netipx regression test that attempts to build an IPX datagram
31 * socket pair and send a packet from one to the other.
34 #include <sys/types.h>
35 #include <sys/socket.h>
37 #include <netipx/ipx.h>
44 #define IPX_ENDPOINT "0xbebe.1.0x8a13"
48 main(int argc, char *argv[])
50 struct sockaddr_ipx sipx_recv, sipx_send;
51 u_char packet[PACKETLEN];
52 int i, sock_recv, sock_send;
56 * Socket to receive with.
58 sock_recv = socket(PF_IPX, SOCK_DGRAM, 0);
60 err(-1, "sock_recv = socket(PF_IPX, SOCK_DGRAM, 0)");
62 bzero(&sipx_recv, sizeof(sipx_recv));
63 sipx_recv.sipx_len = sizeof(sipx_recv);
64 sipx_recv.sipx_family = AF_IPX;
65 sipx_recv.sipx_addr = ipx_addr(IPX_ENDPOINT);
67 if (bind(sock_recv, (struct sockaddr *)&sipx_recv, sizeof(sipx_recv))
69 err(-1, "bind(sock_recv)");
72 * Set non-blocking to try to avoid blocking indefinitely if the
73 * packet doesn't end up in the right place.
75 if (fcntl(sock_recv, F_SETFL, O_NONBLOCK) < 0)
76 err(-1, "fcntl(O_NONBLOCK, sock_recv)");
79 * Socket to send with.
81 sock_send = socket(PF_IPX, SOCK_DGRAM, 0);
83 err(-1, "sock_send = socket(PF_IPX, SOCK_DGRAM, 0)");
85 bzero(&sipx_send, sizeof(sipx_send));
86 sipx_send.sipx_len = sizeof(sipx_send);
87 sipx_send.sipx_family = AF_IPX;
88 sipx_send.sipx_addr = ipx_addr(IPX_ENDPOINT);
90 for (i = 0; i < PACKETLEN; i++)
91 packet[i] = (i & 0xff);
93 len = sendto(sock_send, packet, sizeof(packet), 0,
94 (struct sockaddr *)&sipx_send, sizeof(sipx_send));
97 if (len != sizeof(packet))
98 errx(-1, "sendto(): short send (%d length, %d sent)",
101 sleep(1); /* Arbitrary non-zero amount. */
103 bzero(packet, sizeof(packet));
104 len = recv(sock_recv, packet, sizeof(packet), 0);
107 if (len != sizeof(packet))
108 errx(-1, "recv(): short receive (%d length, %d received)",
109 sizeof(packet), len);
111 for (i = 0; i < PACKETLEN; i++) {
112 if (packet[i] != (i & 0xff))
113 errx(-1, "recv(): byte %d wrong (%d instead of %d)",
114 i, packet[i], i & 0xff);