summaryrefslogtreecommitdiff
path: root/regress/sys/kern/bind
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2015-02-10 00:44:56 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2015-02-10 00:44:56 +0000
commit738e8b51887eebc31beb93ffb10942b143fe8a42 (patch)
tree24a6cf41d933d519b68ad14f0b5edb5c51c2d4cd /regress/sys/kern/bind
parent8e4a989a6afc2cf438deae3c629bdaeba0e40ce9 (diff)
Test that bind works the way it should. This fails at the moment because
of the garbage in sin_zero.
Diffstat (limited to 'regress/sys/kern/bind')
-rw-r--r--regress/sys/kern/bind/Makefile5
-rw-r--r--regress/sys/kern/bind/bind.c46
2 files changed, 51 insertions, 0 deletions
diff --git a/regress/sys/kern/bind/Makefile b/regress/sys/kern/bind/Makefile
new file mode 100644
index 00000000000..5a150163e50
--- /dev/null
+++ b/regress/sys/kern/bind/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2015/02/10 00:44:55 claudio Exp $
+
+PROG= bind
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/bind/bind.c b/regress/sys/kern/bind/bind.c
new file mode 100644
index 00000000000..3d235063d27
--- /dev/null
+++ b/regress/sys/kern/bind/bind.c
@@ -0,0 +1,46 @@
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <strings.h>
+#include <err.h>
+
+int
+main(int argc, char **argv)
+{
+ struct sockaddr_in addr1, addr2;
+ int fd1, fd2, enable = 1;
+
+ addr1.sin_family = AF_INET;
+ addr1.sin_port = htons(6666);
+ addr1.sin_addr.s_addr = INADDR_ANY;
+ /* fill sin_zero explicitly with garbage */
+ memset(addr1.sin_zero, 0xd0, sizeof(addr1.sin_zero));
+
+ addr2.sin_family = AF_INET;
+ addr2.sin_port = htons(6666);
+ addr2.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ /* fill sin_zero explicitly with garbage */
+ memset(addr2.sin_zero, 0xd0, sizeof(addr2.sin_zero));
+
+
+ if ((fd1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
+ err(1, "socket1");
+
+ if (setsockopt(fd1, SOL_SOCKET, SO_REUSEPORT, &enable,
+ sizeof(int)) < 0)
+ err(1, "setsockopt1");
+
+ if (bind(fd1, (struct sockaddr *)&addr1, sizeof(addr1)) == -1)
+ err(1, "bind1");
+
+ if ((fd2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
+ err(1, "socket1");
+
+ if (setsockopt(fd2, SOL_SOCKET, SO_REUSEPORT, &enable,
+ sizeof(int)) < 0)
+ err(1, "setsockopt2");
+
+ if (bind(fd2, (struct sockaddr *)&addr2, sizeof(addr2)) == -1)
+ err(1, "bind2");
+
+ return 0;
+}