if (withService) {
if (virAsprintf(&addrstr, VIR_LOOPBACK_IPV4_ADDR"%s0",
separator ? separator : ":") < 0)
- goto error;
+ return NULL;
} else {
if (VIR_STRDUP(addrstr, VIR_LOOPBACK_IPV4_ADDR) < 0)
- goto error;
+ return NULL;
}
return addrstr;
}
}
if (withService) {
- char *ipv6_host = NULL;
+ VIR_AUTOFREE(char *) ipv6_host = NULL;
/* sasl_new_client demands the socket address to be in an odd format:
* a.b.c.d;port or e:f:g:h:i:j:k:l;port, so use square brackets for
* IPv6 only if no separator is passed to the function
*/
if (!separator && VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET6) {
if (virAsprintf(&ipv6_host, "[%s]", host) < 0)
- goto error;
+ return NULL;
}
if (virAsprintf(&addrstr, "%s%s%s",
ipv6_host ? ipv6_host : host,
separator ? separator : ":", port) == -1) {
- VIR_FREE(ipv6_host);
- goto error;
+ return NULL;
}
-
- VIR_FREE(ipv6_host);
} else {
if (VIR_STRDUP(addrstr, host) < 0)
- goto error;
+ return NULL;
}
return addrstr;
-
- error:
- return NULL;
}
int ret = 0;
size_t i;
virSocketAddr netmask;
- char *startStr = NULL, *endStr = NULL, *netStr = NULL;
+ VIR_AUTOFREE(char *) startStr = NULL;
+ VIR_AUTOFREE(char *) endStr = NULL;
+ VIR_AUTOFREE(char *) netStr = NULL;
if (start == NULL || end == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("NULL argument - %p %p"), start, end);
- goto error;
+ return -1;
}
startStr = virSocketAddrFormat(start);
endStr = virSocketAddrFormat(end);
if (!startStr || !endStr)
- goto error; /*error already reported */
+ return -1; /*error already reported */
if (VIR_SOCKET_ADDR_FAMILY(start) != VIR_SOCKET_ADDR_FAMILY(end)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("mismatch of address family in range %s - %s"),
startStr, endStr);
- goto error;
+ return -1;
}
if (network) {
* network the range should be within
*/
if (!(netStr = virSocketAddrFormat(network)))
- goto error;
+ return -1;
if (VIR_SOCKET_ADDR_FAMILY(start) != VIR_SOCKET_ADDR_FAMILY(network)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("mismatch of address family in "
"range %s - %s for network %s"),
startStr, endStr, netStr);
- goto error;
+ return -1;
}
if (prefix < 0 ||
_("bad prefix %d for network %s when "
" checking range %s - %s"),
prefix, netStr, startStr, endStr);
- goto error;
+ return -1;
}
/* both start and end of range need to be within network */
_("range %s - %s is not entirely within "
"network %s/%d"),
startStr, endStr, netStr, prefix);
- goto error;
+ return -1;
}
if (VIR_SOCKET_ADDR_IS_FAMILY(start, AF_INET)) {
_("failed to construct broadcast or network "
"address for network %s/%d"),
netStr, prefix);
- goto error;
+ return -1;
}
/* Don't allow the start of the range to be the network
_("start of range %s - %s in network %s/%d "
"is the network address"),
startStr, endStr, netStr, prefix);
- goto error;
+ return -1;
}
if (virSocketAddrEqual(end, &broadcast)) {
_("end of range %s - %s in network %s/%d "
"is the broadcast address"),
startStr, endStr, netStr, prefix);
- goto error;
+ return -1;
}
}
}
_("failed to get IPv4 address "
"for start or end of range %s - %s"),
startStr, endStr);
- goto error;
+ return -1;
}
/* legacy check that everything except the last two bytes
*/
for (i = 0; i < 2; i++) {
if (t1[i] != t2[i]) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("range %s - %s is too large (> 65535)"),
- startStr, endStr);
- goto error;
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("range %s - %s is too large (> 65535)"),
+ startStr, endStr);
+ return -1;
}
}
ret = (t2[2] - t1[2]) * 256 + (t2[3] - t1[3]);
virReportError(VIR_ERR_INTERNAL_ERROR,
_("range %s - %s is reversed "),
startStr, endStr);
- goto error;
+ return -1;
}
ret++;
} else if (VIR_SOCKET_ADDR_IS_FAMILY(start, AF_INET6)) {
_("failed to get IPv6 address "
"for start or end of range %s - %s"),
startStr, endStr);
- goto error;
+ return -1;
}
/* legacy check that everything except the last two bytes are
virReportError(VIR_ERR_INTERNAL_ERROR,
_("range %s - %s is too large (> 65535)"),
startStr, endStr);
- goto error;
+ return -1;
}
}
ret = t2[7] - t1[7];
virReportError(VIR_ERR_INTERNAL_ERROR,
_("range %s - %s start larger than end"),
startStr, endStr);
- goto error;
+ return -1;
}
ret++;
} else {
_("unsupported address family "
"for range %s - %s, must be ipv4 or ipv6"),
startStr, endStr);
- goto error;
+ return -1;
}
- cleanup:
- VIR_FREE(startStr);
- VIR_FREE(endStr);
- VIR_FREE(netStr);
return ret;
-
- error:
- ret = -1;
- goto cleanup;
}