diff options
Diffstat (limited to 'src/server/helper.c')
-rw-r--r-- | src/server/helper.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/server/helper.c b/src/server/helper.c index 1a67a95..2dbc3ea 100644 --- a/src/server/helper.c +++ b/src/server/helper.c @@ -16,7 +16,7 @@ * * @param string eg. "1.2.3.4" or "2a01::10:5", optially with port appended, eg "1.2.3.4:6666" or "[2a01::10:5]:6666" * @param host pointer to dnbd3_host_t that will be filled with the following data: - * .type will contain either AF_INET or AF_INET6 + * .type will contain either HOST_IP4 or HOST_IP6 * .addr will contain the address in network representation * .port will contain the port in network representation, defaulting to #define PORT if none was given * @return true on success, false in failure. contents of af, addr and port are undefined in the latter case @@ -29,14 +29,14 @@ bool parse_address(char *string, dnbd3_host_t *host) memset( host, 0, sizeof(*host) ); // Try IPv4 without port if ( 1 == inet_pton( AF_INET, string, &v4 ) ) { - host->type = AF_INET; + host->type = HOST_IP4; memcpy( host->addr, &v4, 4 ); host->port = htons( PORT ); return true; } // Try IPv6 without port if ( 1 == inet_pton( AF_INET6, string, &v6 ) ) { - host->type = AF_INET6; + host->type = HOST_IP6; memcpy( host->addr, &v6, 16 ); host->port = htons( PORT ); return true; @@ -61,13 +61,13 @@ bool parse_address(char *string, dnbd3_host_t *host) // Try IPv4 with port if ( 1 == inet_pton( AF_INET, string, &v4 ) ) { - host->type = AF_INET; + host->type = HOST_IP4; memcpy( host->addr, &v4, 4 ); return true; } // Try IPv6 with port if ( 1 == inet_pton( AF_INET6, string, &v6 ) ) { - host->type = AF_INET6; + host->type = HOST_IP6; memcpy( host->addr, &v6, 16 ); return true; } @@ -85,12 +85,12 @@ bool host_to_string(const dnbd3_host_t *host, char *target, size_t targetlen) { // Worst case: Port 5 chars, ':' to separate ip and port 1 char, terminating null 1 char = 7, [] for IPv6 if ( targetlen < 10 ) return false; - if ( host->type == AF_INET6 ) { + if ( host->type == HOST_IP6 ) { *target++ = '['; inet_ntop( AF_INET6, host->addr, target, (socklen_t)targetlen - 10 ); target += strlen( target ); *target++ = ']'; - } else if ( host->type == AF_INET ) { + } else if ( host->type == HOST_IP4 ) { inet_ntop( AF_INET, host->addr, target, (socklen_t)targetlen - 8 ); target += strlen( target ); } else { |