utils: fix ipv4 checksum issue
[project/unetd.git] / utils.c
diff --git a/utils.c b/utils.c
index 0c7067173f733681493e4f2c95aeb70c829b8e0d..90cdfe562f7a17a3ccfb9aae18378202a1a248c6 100644 (file)
--- a/utils.c
+++ b/utils.c
 
 #include "unetd.h"
 
-int network_get_endpoint(union network_endpoint *dest, const char *str,
+int network_get_endpoint(union network_endpoint *dest, int af, const char *str,
                         int default_port, int idx)
 {
        struct addrinfo hints = {
                .ai_flags = AI_ADDRCONFIG,
-               .ai_family = AF_UNSPEC,
+               .ai_family = af,
        };
        char *buf = strdup(str);
        char *host = buf, *port;
@@ -33,6 +33,9 @@ int network_get_endpoint(union network_endpoint *dest, const char *str,
        memset(dest, 0, sizeof(*dest));
 
        if (*host == '[') {
+               if (af == AF_INET)
+                       goto out;
+
                host++;
                port = strchr(host, ']');
                if (!port)
@@ -197,7 +200,7 @@ uint64_t unet_gettime(void)
 }
 
 static inline uint32_t
-csum_tcpudp_nofold(uint32_t saddr, uint32_t daddr, uint32_t len, uint8_t proto)
+csum_tcpudp_nofold(uint32_t saddr, uint32_t daddr, uint8_t proto, uint32_t len)
 {
        uint64_t sum = 0;