From 4b9d1fad7ef3fd63ec8ee64ad14789a6e5285031 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 6 Jun 2018 19:40:29 +0100 Subject: [PATCH] noip.c: Replace `WANT_...' constants with flags for `encode_inet_addr'. I originally expected that I'd want to add some more flags here, but it turned out that I was mistaken. I think this is better anyway, and I intend to continue this pattern elsewhere. No functional change. --- noip.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/noip.c b/noip.c index 68f4e1e..57cc33e 100644 --- a/noip.c +++ b/noip.c @@ -60,7 +60,6 @@ /*----- Data structures ---------------------------------------------------*/ enum { UNUSED, STALE, USED }; /* Unix socket status values */ -enum { WANT_FRESH, WANT_EXISTING }; /* Socket address dispositions */ enum { DENY, ALLOW }; /* ACL verdicts */ static int address_families[] = { AF_INET, AF_INET6, -1 }; @@ -694,15 +693,16 @@ static int encode_unused_inet_addr(struct sockaddr *sa, return (0); } -/* Encode the Internet address SA as a Unix-domain address SUN. If WANT is - * WANT_FRESH, and SA's port number is zero, then we pick an arbitrary local - * port. Otherwise we pick the port given. There's an unpleasant hack to - * find servers bound to local wildcard addresses. Returns zero on success; - * -1 on failure. +/* Encode the Internet address SA as a Unix-domain address SUN. If the flag + * `ENCF_FRESH' is set, and SA's port number is zero, then we pick an + * arbitrary local port. Otherwise we pick the port given. There's an + * unpleasant hack to find servers bound to local wildcard addresses. + * Returns zero on success; -1 on failure. */ +#define ENCF_FRESH 1u static int encode_inet_addr(struct sockaddr_un *sun, const struct sockaddr *sa, - int want) + unsigned f) { int i; int desperatep = 0; @@ -713,14 +713,14 @@ static int encode_inet_addr(struct sockaddr_un *sun, D( fprintf(stderr, "noip(%d): encode %s (%s)", getpid(), present_sockaddr(sa, 0, buf, sizeof(buf)), - want == WANT_EXISTING ? "EXISTING" : "FRESH"); ) + (f&ENCF_FRESH) ? "FRESH" : "EXISTING"); ) sun->sun_family = AF_UNIX; - if (port || want == WANT_EXISTING) { + if (port || !(f&ENCF_FRESH)) { snprintf(sun->sun_path, sizeof(sun->sun_path), "%s/%s", sockdir, present_sockaddr(sa, 0, buf, sizeof(buf))); rc = unix_socket_status(sun, 0); if (rc == STALE) unlink(sun->sun_path); - if (rc != USED && want == WANT_EXISTING) { + if (rc != USED && !(f&ENCF_FRESH)) { wildcard_address(sa->sa_family, &addr.sa); port_to_sockaddr(&addr.sa, port); snprintf(sun->sun_path, sizeof(sun->sun_path), "%s/%s", sockdir, @@ -939,10 +939,10 @@ static int do_implicit_bind(int sk, const struct sockaddr **sa, D( fprintf(stderr, "noip(%d): no match; using wildcard\n", pid); ) wildcard_address((*sa)->sa_family, &addr.sa); found: - encode_inet_addr(sun, &addr.sa, WANT_FRESH); + encode_inet_addr(sun, &addr.sa, ENCF_FRESH); if (real_bind(sk, SA(sun), SUN_LEN(sun))) return (-1); } - encode_inet_addr(sun, *sa, WANT_EXISTING); + encode_inet_addr(sun, *sa, 0); *sa = SA(sun); *len = SUN_LEN(sun); } @@ -1503,7 +1503,7 @@ int bind(int sk, const struct sockaddr *sa, socklen_t len) if (fixup_real_ip_socket(sk, sa->sa_family, 0)) return (-1); } else { - encode_inet_addr(&sun, sa, WANT_FRESH); + encode_inet_addr(&sun, sa, ENCF_FRESH); sa = SA(&sun); len = SUN_LEN(&sun); } -- 2.11.0