aboutsummaryrefslogtreecommitdiff
path: root/socket_udp6.c
diff options
context:
space:
mode:
authorHenryk Plötz <henryk@ploetzli.ch>2014-10-03 20:04:14 +0200
committerHenryk Plötz <henryk@ploetzli.ch>2014-10-03 20:04:14 +0200
commitc44d8b51ffb5a413f8bbdbd9991bbc573853e397 (patch)
treee7f2e644de620879f610c909c405cbc4e44d6062 /socket_udp6.c
parent0e5b2871ca6456b01d4bf037a6e68badf1ff1a41 (diff)
downloadtinydnssec-c44d8b51ffb5a413f8bbdbd9991bbc573853e397.tar.gz
tinydnssec-c44d8b51ffb5a413f8bbdbd9991bbc573853e397.tar.bz2
Apply patch djbdns-1.05-test27.diff.bz2
Source was http://www.fefe.de/dns/djbdns-1.05-test27.diff.bz2, SHA1 f0380ec1866f49c0bcf6369a923ac0a4a5095da8
Diffstat (limited to 'socket_udp6.c')
-rw-r--r--socket_udp6.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/socket_udp6.c b/socket_udp6.c
new file mode 100644
index 0000000..b58b55c
--- /dev/null
+++ b/socket_udp6.c
@@ -0,0 +1,49 @@
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <errno.h>
+#include <unistd.h>
+#include "ndelay.h"
+#include "socket.h"
+#include "haveip6.h"
+#include "error.h"
+
+#ifndef EAFNOSUPPORT
+#define EAFNOSUPPORT EINVAL
+#endif
+#ifndef EPFNOSUPPORT
+#define EPFNOSUPPORT EAFNOSUPPORT
+#endif
+#ifndef EPROTONOSUPPORT
+#define EPROTONOSUPPORT EAFNOSUPPORT
+#endif
+
+int socket_udp6(void)
+{
+#ifdef LIBC_HAS_IP6
+ int s;
+
+ if (noipv6) goto compat;
+ s = socket(PF_INET6,SOCK_DGRAM,0);
+ if (s == -1) {
+ if (errno == EINVAL || errno == EAFNOSUPPORT || errno == EPFNOSUPPORT || errno == EPROTONOSUPPORT) {
+compat:
+ s=socket(AF_INET,SOCK_DGRAM,0);
+ noipv6=1;
+ if (s==-1) return -1;
+ } else
+ return -1;
+ }
+ if (ndelay_on(s) == -1) { close(s); return -1; }
+#ifdef IPV6_V6ONLY
+ {
+ int zero=0;
+ setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero));
+ }
+#endif
+ return s;
+#else
+ return socket_udp();
+#endif
+}