diff --git a/docs/c-api/util.h/mg_conn_addr_to_str.md b/docs/c-api/util.h/mg_conn_addr_to_str.md index e623734fbf0b5286de40fbe6c20dbb1d548c7c04..b7603fb29aa76fcfb32d8700f2a79c880464768a 100644 --- a/docs/c-api/util.h/mg_conn_addr_to_str.md +++ b/docs/c-api/util.h/mg_conn_addr_to_str.md @@ -3,8 +3,8 @@ title: "mg_conn_addr_to_str()" decl_name: "mg_conn_addr_to_str" symbol_kind: "func" signature: | - void mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len, - int flags); + int mg_conn_addr_to_str(struct mg_connection *c, char *buf, size_t len, + int flags); --- Converts a connection's local or remote address into string. @@ -17,5 +17,6 @@ see `MG_SOCK_STRINGIFY_*` definitions. - MG_SOCK_STRINGIFY_REMOTE - print remote peer's IP/port, not local address If both port number and IP address are printed, they are separated by `:`. -If compiled with `-DMG_ENABLE_IPV6`, IPv6 addresses are supported. +If compiled with `-DMG_ENABLE_IPV6`, IPv6 addresses are supported. +Return length of the stringified address. diff --git a/docs/c-api/util.h/mg_sock_addr_to_str.md b/docs/c-api/util.h/mg_sock_addr_to_str.md index 3502e135e44da7e64a51d0b2d6b9fbab944fe234..b5cb6fddd17267e36c470bf08b3f57fca583dcee 100644 --- a/docs/c-api/util.h/mg_sock_addr_to_str.md +++ b/docs/c-api/util.h/mg_sock_addr_to_str.md @@ -3,8 +3,8 @@ title: "mg_sock_addr_to_str()" decl_name: "mg_sock_addr_to_str" symbol_kind: "func" signature: | - void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len, - int flags); + int mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len, + int flags); --- Convert the socket's address into string. diff --git a/mongoose.c b/mongoose.c index ca80bd4bd8a51e6361cf06f87d0640a5a6959ec2..677ce124fa901ac730d3b899d1cfc503c8b522af 100644 --- a/mongoose.c +++ b/mongoose.c @@ -9541,10 +9541,10 @@ void mg_set_close_on_exec(sock_t sock) { #endif } -void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len, - int flags) { +int mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len, + int flags) { int is_v6; - if (buf == NULL || len <= 0) return; + if (buf == NULL || len <= 0) return 0; memset(buf, 0, len); #if MG_ENABLE_IPV6 is_v6 = sa->sa.sa_family == AF_INET6; @@ -9594,18 +9594,19 @@ void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len, } } - return; + return strlen(buf); cleanup: *buf = '\0'; + return 0; } -void mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len, - int flags) { +int mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len, + int flags) { union socket_address sa; memset(&sa, 0, sizeof(sa)); mg_if_get_conn_addr(nc, flags & MG_SOCK_STRINGIFY_REMOTE, &sa); - mg_sock_addr_to_str(&sa, buf, len, flags); + return mg_sock_addr_to_str(&sa, buf, len, flags); } #if MG_ENABLE_HEXDUMP diff --git a/mongoose.h b/mongoose.h index bed63633972305b9d680198636e1152bd004d8aa..64a9250b849efd87ceaa2ba20f427bc314116bd3 100644 --- a/mongoose.h +++ b/mongoose.h @@ -4001,9 +4001,10 @@ void mg_set_close_on_exec(sock_t); * * If both port number and IP address are printed, they are separated by `:`. * If compiled with `-DMG_ENABLE_IPV6`, IPv6 addresses are supported. + * Return length of the stringified address. */ -void mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len, - int flags); +int mg_conn_addr_to_str(struct mg_connection *c, char *buf, size_t len, + int flags); #if MG_NET_IF == MG_NET_IF_SOCKET /* Legacy interface. */ void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags); @@ -4014,8 +4015,8 @@ void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags); * * `flags` is MG_SOCK_STRINGIFY_IP and/or MG_SOCK_STRINGIFY_PORT. */ -void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len, - int flags); +int mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len, + int flags); #if MG_ENABLE_HEXDUMP /*