mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
change get_peer_addresses to use context wsi latency
Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
e000a709b3
commit
aaf0b9f514
5 changed files with 25 additions and 8 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -101,13 +101,19 @@ This function creates a connection to a remote server
|
|||
<h2>libwebsockets_get_peer_addresses - Get client address information</h2>
|
||||
<i>void</i>
|
||||
<b>libwebsockets_get_peer_addresses</b>
|
||||
(<i>int</i> <b>fd</b>,
|
||||
(<i>struct libwebsocket_context *</i> <b>context</b>,
|
||||
<i>struct libwebsocket *</i> <b>wsi</b>,
|
||||
<i>int</i> <b>fd</b>,
|
||||
<i>char *</i> <b>name</b>,
|
||||
<i>int</i> <b>name_len</b>,
|
||||
<i>char *</i> <b>rip</b>,
|
||||
<i>int</i> <b>rip_len</b>)
|
||||
<h3>Arguments</h3>
|
||||
<dl>
|
||||
<dt><b>context</b>
|
||||
<dd>Libwebsockets context
|
||||
<dt><b>wsi</b>
|
||||
<dd>Local struct libwebsocket associated with
|
||||
<dt><b>fd</b>
|
||||
<dd>Connection socket descriptor
|
||||
<dt><b>name</b>
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Reference in a new issue