summaryrefslogtreecommitdiffstats
path: root/if.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2016-04-17 14:00:09 +0000
committerRoy Marples <roy@marples.name>2016-04-17 14:00:09 +0000
commitcaf646d455672631f61f5da4de25597c43d0e1a7 (patch)
tree4dcc91988bd2b6a8b2fea4190e656b5db9804c6e /if.c
parente3883bfcbccb22af0d2caf03f987867e6a77c7be (diff)
downloaddhcpcd-caf646d455672631f61f5da4de25597c43d0e1a7.tar.xz
Improve xsocket to have the same API as socket.
Diffstat (limited to 'if.c')
-rw-r--r--if.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/if.c b/if.c
index c840bfba..8715a9e6 100644
--- a/if.c
+++ b/if.c
@@ -93,12 +93,12 @@ if_opensockets(struct dhcpcd_ctx *ctx)
return -1;
/* We use this socket for some operations without INET. */
- ctx->pf_inet_fd = xsocket(PF_INET, SOCK_DGRAM, 0, SOCK_CLOEXEC);
+ ctx->pf_inet_fd = xsocket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (ctx->pf_inet_fd == -1)
return -1;
#ifdef IFLR_ACTIVE
- ctx->pf_link_fd = xsocket(PF_LINK, SOCK_DGRAM, 0, SOCK_CLOEXEC);
+ ctx->pf_link_fd = xsocket(PF_LINK, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (ctx->pf_link_fd == -1)
return -1;
#endif
@@ -683,32 +683,32 @@ if_sortinterfaces(struct dhcpcd_ctx *ctx)
}
int
-xsocket(int domain, int type, int protocol, int flags)
+xsocket(int domain, int type, int protocol)
{
int s;
#if !defined(HAVE_SOCK_CLOEXEC) || !defined(HAVE_SOCK_NONBLOCK)
- int xflags;
+ int xflags, xtype = type;
#endif
-#ifdef HAVE_SOCK_CLOEXEC
- if (flags & SOCK_CLOEXEC)
- type |= SOCK_CLOEXEC;
+#ifndef HAVE_SOCK_CLOEXEC
+ if (xtype & SOCK_CLOEXEC)
+ type &= ~SOCK_CLOEXEC;
#endif
-#ifdef HAVE_SOCK_NONBLOCK
- if (flags & SOCK_NONBLOCK)
- type |= SOCK_NONBLOCK;
+#ifndef HAVE_SOCK_NONBLOCK
+ if (xtype & SOCK_NONBLOCK)
+ type &= ~SOCK_NONBLOCK;
#endif
if ((s = socket(domain, type, protocol)) == -1)
return -1;
#ifndef HAVE_SOCK_CLOEXEC
- if ((flags & SOCK_CLOEXEC) && ((xflags = fcntl(s, F_GETFD)) == -1 ||
+ if ((xtype & SOCK_CLOEXEC) && ((xflags = fcntl(s, F_GETFD)) == -1 ||
fcntl(s, F_SETFD, xflags | FD_CLOEXEC) == -1))
goto out;
#endif
#ifndef HAVE_SOCK_NONBLOCK
- if ((flags & SOCK_NONBLOCK) && ((xflags = fcntl(s, F_GETFL)) == -1 ||
+ if ((xtype & SOCK_NONBLOCK) && ((xflags = fcntl(s, F_GETFL)) == -1 ||
fcntl(s, F_SETFL, xflags | O_NONBLOCK) == -1))
goto out;
#endif