summaryrefslogtreecommitdiff
path: root/lib/util/util_net.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2017-11-13 16:54:09 +0100
committerJeremy Allison <jra@samba.org>2017-11-18 00:09:16 +0100
commit98dd651f8dd728aaeb09aa53c4c38d132b02fa50 (patch)
tree3d3e25d67c873a3d83d14e79c135a7ac2249af72 /lib/util/util_net.c
parent2a86876c223aca33865fcb11ba59af1faf91f86c (diff)
downloadsamba-98dd651f8dd728aaeb09aa53c4c38d132b02fa50.tar.gz
lib: Simplify is_ipaddress_v6
Do an early return, avoid an "else", avoid an indentation level Review with git show -b Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/util/util_net.c')
-rw-r--r--lib/util/util_net.c107
1 files changed, 53 insertions, 54 deletions
diff --git a/lib/util/util_net.c b/lib/util/util_net.c
index b3ed9f262fe..d52d401e4c7 100644
--- a/lib/util/util_net.c
+++ b/lib/util/util_net.c
@@ -490,76 +490,75 @@ bool is_ipaddress_v6(const char *str)
#if defined(HAVE_IPV6)
int ret = -1;
char *p = NULL;
+ char buf[INET6_ADDRSTRLEN] = { 0, };
+ size_t len;
+ const char *addr = str;
+ const char *idxs = NULL;
+ unsigned int idx = 0;
+ struct in6_addr ip6;
p = strchr_m(str, ':');
if (p == NULL) {
return is_ipv6_literal(str);
- } else {
- char buf[INET6_ADDRSTRLEN] = { 0, };
- size_t len;
- const char *addr = str;
- const char *idxs = NULL;
- unsigned int idx = 0;
- struct in6_addr ip6;
-
- p = strchr_m(str, SCOPE_DELIMITER);
- if (p && (p > str)) {
- len = PTR_DIFF(p, str);
- idxs = p + 1;
- } else {
- len = strlen(str);
- }
+ }
- if (len >= sizeof(buf)) {
- return false;
- }
- if (idxs != NULL) {
- strncpy(buf, str, len);
- addr = buf;
- }
+ p = strchr_m(str, SCOPE_DELIMITER);
+ if (p && (p > str)) {
+ len = PTR_DIFF(p, str);
+ idxs = p + 1;
+ } else {
+ len = strlen(str);
+ }
- /*
- * Cope with link-local.
- * This is IP:v6:addr%ifidx.
- */
- if (idxs != NULL) {
- char c;
+ if (len >= sizeof(buf)) {
+ return false;
+ }
+ if (idxs != NULL) {
+ strncpy(buf, str, len);
+ addr = buf;
+ }
- ret = sscanf(idxs, "%5u%c", &idx, &c);
- if (ret != 1) {
- idx = 0;
- }
+ /*
+ * Cope with link-local.
+ * This is IP:v6:addr%ifidx.
+ */
+ if (idxs != NULL) {
+ char c;
- if (idx > 0 && idx < UINT16_MAX) {
- /* a valid index */
- idxs = NULL;
- }
+ ret = sscanf(idxs, "%5u%c", &idx, &c);
+ if (ret != 1) {
+ idx = 0;
}
- /*
- * Cope with link-local.
- * This is IP:v6:addr%ifname.
- */
- if (idxs != NULL) {
- idx = if_nametoindex(idxs);
-
- if (idx > 0) {
- /* a valid index */
- idxs = NULL;
- }
+ if (idx > 0 && idx < UINT16_MAX) {
+ /* a valid index */
+ idxs = NULL;
}
+ }
- if (idxs != NULL) {
- return false;
- }
+ /*
+ * Cope with link-local.
+ * This is IP:v6:addr%ifname.
+ */
+ if (idxs != NULL) {
+ idx = if_nametoindex(idxs);
- ret = inet_pton(AF_INET6, addr, &ip6);
- if (ret <= 0) {
- return false;
+ if (idx > 0) {
+ /* a valid index */
+ idxs = NULL;
}
+ }
- return true;
+ if (idxs != NULL) {
+ return false;
+ }
+
+ ret = inet_pton(AF_INET6, addr, &ip6);
+ if (ret <= 0) {
+ return false;
}
+
+ return true;
#endif
return false;
}