Correct char signdness in hex conversion
[tunudptotcp] / main.cpp
index 332229836627b80df7cd26d6151ce1cac179ebb9..2afcf4c96e5b28efd6368695fd16b1a658586cec 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,6 +1,5 @@
 #include <fcntl.h>
 #include <string.h>
-#include <stropts.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/socket.h>
@@ -9,6 +8,7 @@
 #include <errno.h>
 #include <arpa/inet.h>
 #include <stdint.h>
+#include <stdlib.h>
 #include <linux/if.h>
 #include <linux/if_tun.h>
 #include <assert.h>
@@ -16,6 +16,7 @@
 #include <atomic>
 #include <chrono>
 #include <thread>
+#include <string>
 
 #if __has_include(<sys/random.h>)
 #include <sys/random.h>
@@ -235,8 +236,8 @@ const signed char p_util_hexdigit[256] =
   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, };
 
-uint32_t hex_to_num(const char* buf) {
-       const char* pbegin = buf;
+uint32_t hex_to_num(const unsigned char* buf) {
+       const unsigned char* pbegin = buf;
        while (p_util_hexdigit[*buf] != -1)
                buf++;
        buf--;
@@ -581,7 +582,7 @@ int main(int argc, char* argv[]) {
        // Create tun and bind to sockets...
        //
 
-       if (tun_alloc(tun_name, TUN_IF_COUNT, fd) < 0) {
+       if (tun_alloc(tun_name, TUN_IF_COUNT, fd) != 0) {
                fprintf(stderr, "Failed to alloc tun if\n");
                return -1;
        }