stun

simple point to point tunnel
git clone git://git.2f30.org/stun.git
Log | Files | Refs | README

commit 14686b511753b2bda0e867c01050af04451dbf7d
parent a2e8c181bfeb27a3b7d10a2402ca3807d2f5f02e
Author: sin <sin@2f30.org>
Date:   Mon May  2 17:22:29 +0100

Implement mypledge() to hide ugly ifdefs

Diffstat:
stun.c | 14++------------
stun.h | 1+
util.c | 13+++++++++++++
3 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/stun.c b/stun.c @@ -53,13 +53,8 @@ chldrun(void) /* invoked as server */ listenfd = serverinit(netconfig.bindaddr, netconfig.port); revokeprivs(netconfig.user); -#if defined(__OpenBSD__) -#include <sys/param.h> -#if OpenBSD >= 201605 - if (pledge("stdio inet", NULL) < 0) + if (mypledge("stdio inet", NULL) < 0) fatal("pledge"); -#endif -#endif for (;;) { if ((netfd = serveraccept(listenfd)) < 0) { netreset(); @@ -74,13 +69,8 @@ chldrun(void) } else { /* invoked as client */ revokeprivs(netconfig.user); -#if defined(__OpenBSD__) -#include <sys/param.h> -#if OpenBSD >= 201605 - if (pledge("stdio dns inet", NULL) < 0) + if (mypledge("stdio dns inet", NULL) < 0) fatal("pledge"); -#endif -#endif for (;;) { if ((netfd = clientconnect(netconfig.host, netconfig.port)) < 0) { diff --git a/stun.h b/stun.h @@ -124,3 +124,4 @@ char *saddr_ntop(struct sockaddr *, socklen_t); char *peer_ntop(int); int ipversion(unsigned char *); void setsockopts(int); +int mypledge(const char *, const char *[]); diff --git a/util.c b/util.c @@ -157,3 +157,16 @@ setsockopts(int fd) logwarn("setsockopt SO_SNDBUF"); } } + +/* only works on OpenBSD 5.9 onwards */ +int +mypledge(const char *promises, const char *paths[]) +{ +#if defined(__OpenBSD__) +#include <sys/param.h> +#if OpenBSD >= 201605 + return pledge(promises, paths); +#endif +#endif + return 0; +}