diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 38fc098a..1b406e6d 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -391,6 +391,8 @@ libwebsockets_hangup_on_client(struct libwebsocket_context *context, int fd) /** * libwebsockets_get_peer_addresses() - Get client address information + * @context: Libwebsockets context + * @wsi: Local struct libwebsocket associated with * @fd: Connection socket descriptor * @name: Buffer to take client address name * @name_len: Length of client address name buffer @@ -404,7 +406,8 @@ libwebsockets_hangup_on_client(struct libwebsocket_context *context, int fd) */ void -libwebsockets_get_peer_addresses(int fd, char *name, int name_len, +libwebsockets_get_peer_addresses(struct libwebsocket_context *context, + struct libwebsocket *wsi, int fd, char *name, int name_len, char *rip, int rip_len) { unsigned int len; @@ -414,6 +417,7 @@ libwebsockets_get_peer_addresses(int fd, char *name, int name_len, char ip[128]; unsigned char *p; int n; + int ret = -1; #ifdef AF_LOCAL struct sockaddr_un *un; #endif @@ -421,17 +425,19 @@ libwebsockets_get_peer_addresses(int fd, char *name, int name_len, rip[0] = '\0'; name[0] = '\0'; + lws_latency_pre(context, wsi); + len = sizeof sin; if (getpeername(fd, (struct sockaddr *) &sin, &len) < 0) { perror("getpeername"); - return; + goto bail; } host = gethostbyaddr((char *) &sin.sin_addr, sizeof sin.sin_addr, AF_INET); if (host == NULL) { perror("gethostbyaddr"); - return; + goto bail; } strncpy(name, host->h_name, name_len); @@ -439,7 +445,7 @@ libwebsockets_get_peer_addresses(int fd, char *name, int name_len, host1 = gethostbyname(host->h_name); if (host1 == NULL) - return; + goto bail; p = (unsigned char *)host1; n = 0; while (p != NULL) { @@ -466,6 +472,10 @@ libwebsockets_get_peer_addresses(int fd, char *name, int name_len, strncpy(rip, ip, rip_len); rip[rip_len - 1] = '\0'; } + + ret = 0; +bail: + lws_latency(context, wsi, "libwebsockets_get_peer_addresses", ret, 1); } int libwebsockets_get_random(struct libwebsocket_context *context, diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 113e9d54..cef5c803 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -856,7 +856,8 @@ libwebsocket_canonical_hostname(struct libwebsocket_context *context); LWS_EXTERN void -libwebsockets_get_peer_addresses(int fd, char *name, int name_len, +libwebsockets_get_peer_addresses(struct libwebsocket_context *context, + struct libwebsocket *wsi, int fd, char *name, int name_len, char *rip, int rip_len); LWS_EXTERN void diff --git a/libwebsockets-api-doc.html b/libwebsockets-api-doc.html index 402c36db..c67692a6 100644 --- a/libwebsockets-api-doc.html +++ b/libwebsockets-api-doc.html @@ -101,13 +101,19 @@ This function creates a connection to a remote server

libwebsockets_get_peer_addresses - Get client address information

void libwebsockets_get_peer_addresses -(int fd, +(struct libwebsocket_context * context, +struct libwebsocket * wsi, +int fd, char * name, int name_len, char * rip, int rip_len)

Arguments

+
context +
Libwebsockets context +
wsi +
Local struct libwebsocket associated with
fd
Connection socket descriptor
name diff --git a/test-server/test-ping.c b/test-server/test-ping.c index 773b7926..ec2df1f5 100644 --- a/test-server/test-ping.c +++ b/test-server/test-ping.c @@ -434,7 +434,7 @@ int main(int argc, char **argv) } } - libwebsockets_get_peer_addresses( + libwebsockets_get_peer_addresses(context, ping_wsi[0], libwebsocket_get_socket_fd(ping_wsi[0]), peer_name, sizeof peer_name, ip, sizeof ip); diff --git a/test-server/test-server.c b/test-server/test-server.c index d54c3712..5d06fa05 100644 --- a/test-server/test-server.c +++ b/test-server/test-server.c @@ -138,7 +138,7 @@ static int callback_http(struct libwebsocket_context *context, case LWS_CALLBACK_FILTER_NETWORK_CONNECTION: #if 0 - libwebsockets_get_peer_addresses((int)(long)user, client_name, + libwebsockets_get_peer_addresses(context, wsi, (int)(long)user, client_name, sizeof(client_name), client_ip, sizeof(client_ip)); fprintf(stderr, "Received network connect from %s (%s)\n",