diff options
author | rwatson <rwatson@FreeBSD.org> | 2006-03-26 18:25:53 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2006-03-26 18:25:53 +0000 |
commit | 5d9ced7701c1899404b342b4eb50fafb0e49a259 (patch) | |
tree | 4a973e3f4c49bbe6c3fde160be1a981f4d74e8d1 /tools | |
parent | deeedd413a54567b4af5de5e3b8e4c30ac5f1be8 (diff) | |
download | FreeBSD-src-5d9ced7701c1899404b342b4eb50fafb0e49a259.zip FreeBSD-src-5d9ced7701c1899404b342b4eb50fafb0e49a259.tar.gz |
Add a simple IPX datagram regression test, which opens two IPX datagram
sockets, binds a local port, sends a datagram, and confirms that it is
received.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/regression/netipx/ipxdgramloopback/Makefile | 12 | ||||
-rw-r--r-- | tools/regression/netipx/ipxdgramloopback/ipxdgramloopback.c | 118 |
2 files changed, 130 insertions, 0 deletions
diff --git a/tools/regression/netipx/ipxdgramloopback/Makefile b/tools/regression/netipx/ipxdgramloopback/Makefile new file mode 100644 index 0000000..13dbbf5 --- /dev/null +++ b/tools/regression/netipx/ipxdgramloopback/Makefile @@ -0,0 +1,12 @@ +# +# $FreeBSD$ +# + +PROG= ipxdgramloopback +NO_MAN= + +DPADD= ${LIBIPX}; +LDADD= -lipx +WARNS= 3 + +.include <bsd.prog.mk> diff --git a/tools/regression/netipx/ipxdgramloopback/ipxdgramloopback.c b/tools/regression/netipx/ipxdgramloopback/ipxdgramloopback.c new file mode 100644 index 0000000..b969b48 --- /dev/null +++ b/tools/regression/netipx/ipxdgramloopback/ipxdgramloopback.c @@ -0,0 +1,118 @@ +/*- + * Copyright (c) 2006 Robert N. M. Watson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Simple netipx regression test that attempts to build an IPX datagram + * socket pair and send a packet from one to the other. + */ + +#include <sys/types.h> +#include <sys/socket.h> + +#include <netipx/ipx.h> + +#include <err.h> +#include <fcntl.h> +#include <string.h> +#include <unistd.h> + +#define IPX_ENDPOINT "0xbebe.1.0x8a13" +#define PACKETLEN 128 + +int +main(int argc, char *argv[]) +{ + struct sockaddr_ipx sipx_recv, sipx_send; + u_char packet[PACKETLEN]; + int i, sock_recv, sock_send; + ssize_t len; + + /* + * Socket to receive with. + */ + sock_recv = socket(PF_IPX, SOCK_DGRAM, 0); + if (sock_recv < 0) + err(-1, "sock_recv = socket(PF_IPX, SOCK_DGRAM, 0)"); + + bzero(&sipx_recv, sizeof(sipx_recv)); + sipx_recv.sipx_len = sizeof(sipx_recv); + sipx_recv.sipx_family = AF_IPX; + sipx_recv.sipx_addr = ipx_addr(IPX_ENDPOINT); + + if (bind(sock_recv, (struct sockaddr *)&sipx_recv, sizeof(sipx_recv)) + < 0) + err(-1, "bind(sock_recv)"); + + /* + * Set non-blocking to try to avoid blocking indefinitely if the + * packet doesn't end up in the right place. + */ + if (fcntl(sock_recv, F_SETFL, O_NONBLOCK) < 0) + err(-1, "fcntl(O_NONBLOCK, sock_recv)"); + + /* + * Socket to send with. + */ + sock_send = socket(PF_IPX, SOCK_DGRAM, 0); + if (sock_send < 0) + err(-1, "sock_send = socket(PF_IPX, SOCK_DGRAM, 0)"); + + bzero(&sipx_send, sizeof(sipx_send)); + sipx_send.sipx_len = sizeof(sipx_send); + sipx_send.sipx_family = AF_IPX; + sipx_send.sipx_addr = ipx_addr(IPX_ENDPOINT); + + for (i = 0; i < PACKETLEN; i++) + packet[i] = (i & 0xff); + + len = sendto(sock_send, packet, sizeof(packet), 0, + (struct sockaddr *)&sipx_send, sizeof(sipx_send)); + if (len < 0) + err(-1, "sendto()"); + if (len != sizeof(packet)) + errx(-1, "sendto(): short send (%d length, %d sent)", + sizeof(packet), len); + + sleep(1); /* Arbitrary non-zero amount. */ + + bzero(packet, sizeof(packet)); + len = recv(sock_recv, packet, sizeof(packet), 0); + if (len < 0) + err(-1, "recv()"); + if (len != sizeof(packet)) + errx(-1, "recv(): short receive (%d length, %d received)", + sizeof(packet), len); + + for (i = 0; i < PACKETLEN; i++) { + if (packet[i] != (i & 0xff)) + errx(-1, "recv(): byte %d wrong (%d instead of %d)", + i, packet[i], i & 0xff); + } + + return (0); +} |