/**
* 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
*/
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;
char ip[128];
unsigned char *p;
int n;
+ int ret = -1;
#ifdef AF_LOCAL
struct sockaddr_un *un;
#endif
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);
host1 = gethostbyname(host->h_name);
if (host1 == NULL)
- return;
+ goto bail;
p = (unsigned char *)host1;
n = 0;
while (p != NULL) {
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,
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
<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>
}
}
- 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);
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",