]> git.meshlink.io Git - meshlink/commitdiff
Always ensure we store a port number when setting the canonical address.
authorGuus Sliepen <guus@meshlink.io>
Mon, 7 Sep 2020 15:58:23 +0000 (17:58 +0200)
committerGuus Sliepen <guus@meshlink.io>
Mon, 7 Sep 2020 15:58:23 +0000 (17:58 +0200)
src/meshlink.c
src/meshlink.h

index f949c2c7da8df9acd9999418c79cf4a736635ada..7492c46bda6a0ce7716fc27278b58db108735500 100644 (file)
@@ -2583,11 +2583,7 @@ bool meshlink_set_canonical_address(meshlink_handle_t *mesh, meshlink_node_t *no
 
        char *canonical_address;
 
 
        char *canonical_address;
 
-       if(port) {
-               xasprintf(&canonical_address, "%s %s", address, port);
-       } else {
-               canonical_address = xstrdup(address);
-       }
+       xasprintf(&canonical_address, "%s %s", address, port ? port : mesh->myport);
 
        if(pthread_mutex_lock(&mesh->mutex) != 0) {
                abort();
 
        if(pthread_mutex_lock(&mesh->mutex) != 0) {
                abort();
index 09a0028d9bd0799e0ecca585db9dea4d1caf2ce9..3a23eb088b6d38a810b7f821565b00cd6afdfddd 100644 (file)
@@ -822,7 +822,7 @@ bool meshlink_set_canonical_address(struct meshlink_handle *mesh, struct meshlin
  *  @param mesh         A handle which represents an instance of MeshLink.
  *  @param address      A nul-terminated C string containing the address, which can be either in numeric format or a hostname.
  *  @param port         A nul-terminated C string containing the port, which can be either in numeric or symbolic format.
  *  @param mesh         A handle which represents an instance of MeshLink.
  *  @param address      A nul-terminated C string containing the address, which can be either in numeric format or a hostname.
  *  @param port         A nul-terminated C string containing the port, which can be either in numeric or symbolic format.
- *                      If it is NULL, the listening port's number will be used.
+ *                      If it is NULL, the current listening port's number will be used.
  *
  *  @return             This function returns true if the address was added, false otherwise.
  */
  *
  *  @return             This function returns true if the address was added, false otherwise.
  */
@@ -953,6 +953,9 @@ int meshlink_get_port(struct meshlink_handle *mesh) __attribute__((__warn_unused
  *  that the other nodes may no longer be able to initiate connections to the local node,
  *  since they will try to connect to the previously configured port.
  *
  *  that the other nodes may no longer be able to initiate connections to the local node,
  *  since they will try to connect to the previously configured port.
  *
+ *  Note that if a canonical address has been set for the local node,
+ *  you might need to call meshlink_set_canonical_address() again to ensure it includes the new port number.
+ *
  *  \memberof meshlink_handle
  *  @param mesh          A handle which represents an instance of MeshLink.
  *  @param port          The port number to listen on. This must be between 0 and 65535.
  *  \memberof meshlink_handle
  *  @param mesh          A handle which represents an instance of MeshLink.
  *  @param port          The port number to listen on. This must be between 0 and 65535.