mirror of
https://github.com/cesanta/mongoose.git
synced 2025-06-07 17:42:30 +08:00
Make mg_conn_addr_to_str return len
Also amend api_net.js to use returned length. PUBLISHED_FROM=38e15f9587edf28049c5b9e5f126b4db159910e8
This commit is contained in:
parent
fb3a5a7d90
commit
8d76733fad
@ -3,7 +3,7 @@ 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 mg_conn_addr_to_str(struct mg_connection *c, char *buf, size_t len,
|
||||
int flags);
|
||||
---
|
||||
|
||||
@ -18,4 +18,5 @@ see `MG_SOCK_STRINGIFY_*` definitions.
|
||||
|
||||
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.
|
||||
|
||||
|
@ -3,7 +3,7 @@ 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 mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
|
||||
int flags);
|
||||
---
|
||||
|
||||
|
11
mongoose.c
11
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 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 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
|
||||
|
@ -4001,8 +4001,9 @@ 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 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. */
|
||||
@ -4014,7 +4015,7 @@ 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 mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
|
||||
int flags);
|
||||
|
||||
#if MG_ENABLE_HEXDUMP
|
||||
|
Loading…
Reference in New Issue
Block a user