V71+: #268 obey host name setting with env vars
authorjoan2937 <joan@abyz.me.uk>
Wed, 27 Nov 2019 21:25:35 +0000 (21:25 +0000)
committerjoan2937 <joan@abyz.me.uk>
Wed, 27 Nov 2019 21:25:35 +0000 (21:25 +0000)
pigpio.h
pigpiod_if2.c

index 7d8df6a45e7e66da51ea54084b1d83c8c908a2e0..0010fd8d2e87cb5bbe3f770ef3a3dfbb21915b03 100644 (file)
--- a/pigpio.h
+++ b/pigpio.h
@@ -30,7 +30,7 @@ For more information, please refer to <http://unlicense.org/>
 #include <stdint.h>
 #include <pthread.h>
 
-#define PIGPIO_VERSION 7103
+#define PIGPIO_VERSION 7104
 
 /*TEXT
 
@@ -6491,7 +6491,7 @@ after this command is issued.
 #define PI_DEFAULT_DMA_NOT_SET             15
 #define PI_DEFAULT_SOCKET_PORT             8888
 #define PI_DEFAULT_SOCKET_PORT_STR         "8888"
-#define PI_DEFAULT_SOCKET_ADDR_STR         "127.0.0.1"
+#define PI_DEFAULT_SOCKET_ADDR_STR         "localhost"
 #define PI_DEFAULT_UPDATE_MASK_UNKNOWN     0x0000000FFFFFFCLL
 #define PI_DEFAULT_UPDATE_MASK_B1          0x03E7CF93
 #define PI_DEFAULT_UPDATE_MASK_A_B2        0xFBC7CF9C
index 6854d65e9bc89e6772c17562d15f9272196b697e..36f01aa3660bc01e615b31cb304889f060922680 100644 (file)
@@ -234,33 +234,10 @@ static int pigpio_command_ext
    return cmd.res;
 }
 
-static int pigpioOpenSocket(char *addr, char *port)
+static int pigpioOpenSocket(char *addrStr, char *portStr)
 {
    int sock, err, opt;
    struct addrinfo hints, *res, *rp;
-   const char *addrStr, *portStr;
-
-   if (!addr)
-   {
-      addrStr = getenv(PI_ENVADDR);
-
-      if ((!addrStr) || (!strlen(addrStr)))
-      {
-         addrStr = PI_DEFAULT_SOCKET_ADDR_STR;
-      }
-   }
-   else addrStr = addr;
-
-   if (!port)
-   {
-      portStr = getenv(PI_ENVPORT);
-
-      if ((!portStr) || (!strlen(portStr)))
-      {
-         portStr = PI_DEFAULT_SOCKET_PORT_STR;
-      }
-   }
-   else portStr = port;
 
    memset (&hints, 0, sizeof (hints));
 
@@ -713,11 +690,6 @@ int pigpio_start(char *addrStr, char *portStr)
    int pi;
    int *userdata;
 
-   if ((!addrStr) || (strlen(addrStr) == 0))
-   {
-      addrStr = "localhost";
-   }
-
    for (pi=0; pi<MAX_PI; pi++)
    {
       if (!gPiInUse[pi]) break;
@@ -727,6 +699,26 @@ int pigpio_start(char *addrStr, char *portStr)
 
    gPiInUse[pi] = 1;
 
+   if ((!addrStr)  || (!strlen(addrStr)))
+   {
+      addrStr = getenv(PI_ENVADDR);
+
+      if ((!addrStr) || (!strlen(addrStr)))
+      {
+         addrStr = PI_DEFAULT_SOCKET_ADDR_STR;
+      }
+   }
+
+   if ((!portStr) || (!strlen(portStr)))
+   {
+      portStr = getenv(PI_ENVPORT);
+
+      if ((!portStr) || (!strlen(portStr)))
+      {
+         portStr = PI_DEFAULT_SOCKET_PORT_STR;
+      }
+   }
+
    pthread_mutex_init(&gCmdMutex[pi], NULL);
 
    gPigCommand[pi] = pigpioOpenSocket(addrStr, portStr);