summaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorSimon Rettberg2017-10-28 14:56:58 +0200
committerSimon Rettberg2017-10-28 14:56:58 +0200
commitc8c62246f84b5d9d4a496097f043696e2d9ba0bb (patch)
tree27a896f6677791ef8087fa44b1aab7cb2071d774 /src/server
parent[SERVER] Add function to parse x-www-form-urlencoded strings (diff)
downloaddnbd3-c8c62246f84b5d9d4a496097f043696e2d9ba0bb.tar.gz
dnbd3-c8c62246f84b5d9d4a496097f043696e2d9ba0bb.tar.xz
dnbd3-c8c62246f84b5d9d4a496097f043696e2d9ba0bb.zip
[*] Introduce constants for IPv4/6 in dnbd3_host_t
AF_INET luckily was "2" on all platforms checked, so no problems there with interoperation, but AF_INET6 is different between Linux, BSD, Windows and possibly others, so map back and forth between AF_INET/AF_INET6 and HOST_IP4/HOST_IP6 to fix this.
Diffstat (limited to 'src/server')
-rw-r--r--src/server/altservers.c2
-rw-r--r--src/server/helper.c14
-rw-r--r--src/server/helper.h4
-rw-r--r--src/server/rpc.c4
4 files changed, 12 insertions, 12 deletions
diff --git a/src/server/altservers.c b/src/server/altservers.c
index 18e2548..b9394cf 100644
--- a/src/server/altservers.c
+++ b/src/server/altservers.c
@@ -296,7 +296,7 @@ int altservers_netCloseness(dnbd3_host_t *host1, dnbd3_host_t *host2)
{
if ( host1 == NULL || host2 == NULL || host1->type != host2->type ) return -1;
int retval = 0;
- const int max = host1->type == AF_INET ? 4 : 16;
+ const int max = host1->type == HOST_IP4 ? 4 : 16;
for (int i = 0; i < max; ++i) {
if ( (host1->addr[i] & 0xf0) != (host2->addr[i] & 0xf0) ) return retval;
++retval;
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 {
diff --git a/src/server/helper.h b/src/server/helper.h
index 2fa67a5..78a1c41 100644
--- a/src/server/helper.h
+++ b/src/server/helper.h
@@ -19,12 +19,12 @@ void blockNoncriticalSignals();
static inline bool isSameAddress(const dnbd3_host_t * const a, const dnbd3_host_t * const b)
{
- return (a->type == b->type) && (0 == memcmp( a->addr, b->addr, (a->type == AF_INET ? 4 : 16) ));
+ return (a->type == b->type) && (0 == memcmp( a->addr, b->addr, (a->type == HOST_IP4 ? 4 : 16) ));
}
static inline bool isSameAddressPort(const dnbd3_host_t * const a, const dnbd3_host_t * const b)
{
- return (a->type == b->type) && (a->port == b->port) && (0 == memcmp( a->addr, b->addr, (a->type == AF_INET ? 4 : 16) ));
+ return (a->type == b->type) && (a->port == b->port) && (0 == memcmp( a->addr, b->addr, (a->type == HOST_IP4 ? 4 : 16) ));
}
/**
diff --git a/src/server/rpc.c b/src/server/rpc.c
index 6b958be..255d893 100644
--- a/src/server/rpc.c
+++ b/src/server/rpc.c
@@ -267,11 +267,11 @@ static void addacl(int argc, char **argv, void *data UNUSED)
char *last;
bits = strtol( slash, &last, 10 );
if ( last == slash ) slash = NULL;
- if ( host.type == AF_INET && bits > 32 ) bits = 32;
+ if ( host.type == HOST_IP4 && bits > 32 ) bits = 32;
if ( bits > 128 ) bits = 128;
}
if ( slash == NULL ) {
- if ( host.type == AF_INET ) {
+ if ( host.type == HOST_IP4 ) {
bits = 32;
} else {
bits = 128;