stun

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

commit 9bf80ca955247daab44e14893aeaa251e2653483
parent d5f6d622127dc126c53ab903ce12686da1e69072
Author: sin <sin@2f30.org>
Date:   Tue, 21 Mar 2017 23:00:56 +0000

Add pledge() wrapper to localize ifdefs

Diffstat:
Mstun.c | 14++------------
Mstun.h | 1+
Mutil.c | 9+++++++++
3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/stun.c b/stun.c @@ -155,13 +155,8 @@ main(int argc, char *argv[]) /* invoked as server */ listenfd = serverinit(bindaddr, port); revokeprivs(user); -#if defined(__OpenBSD__) -#include <sys/param.h> -#if OpenBSD >= 201605 - if (pledge("stdio inet", NULL) < 0) + if (mypledge("stdio inet", NULL) < 0) logerr("pledge failed"); -#endif -#endif for (;;) { if ((netfd = serveraccept(listenfd)) < 0) { netreset(); @@ -176,13 +171,8 @@ main(int argc, char *argv[]) } else { /* invoked as client */ revokeprivs(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) logerr("pledge failed"); -#endif -#endif for (;;) { if ((netfd = clientconnect(host, port)) < 0) { netreset(); diff --git a/stun.h b/stun.h @@ -83,3 +83,4 @@ int setnonblock(int, int); char *saddr_ntop(struct sockaddr *, socklen_t); char *peer_ntop(int); int ipversion(unsigned char *); +int mypledge(const char *, const char *[]); diff --git a/util.c b/util.c @@ -129,3 +129,12 @@ ipversion(unsigned char *pkt) } return -1; } + +int +mypledge(const char *promises, const char *paths[]) +{ +#if defined(__OpenBSD__) + return pledge(promises, paths); +#endif + return 0; +}