diff --git a/test-server/test-server-extpoll.c b/test-server/test-server-extpoll.c index e0eced72..725fb956 100644 --- a/test-server/test-server-extpoll.c +++ b/test-server/test-server-extpoll.c @@ -98,6 +98,25 @@ static int callback_http(struct libwebsocket *wsi, fprintf(stderr, "Failed to send HTTP file\n"); break; + /* + * callback for confirming to continue with client IP appear in + * protocol 0 callback since no websocket protocol has been agreed + * yet. You can just ignore this if you won't filter on client IP + * since the default uhandled callback return is 0 meaning let the + * connection continue. + */ + + case LWS_CALLBACK_FILTER_NETWORK_CONNECTION: + + libwebsockets_get_peer_addresses((int)(long)user, client_name, + sizeof(client_name), client_ip, sizeof(client_ip)); + + fprintf(stderr, "Received network connect from %s (%s)\n", + client_name, client_ip); + + /* if we returned non-zero from here, we kill the connection */ + break; + /* * callbacks for managing the external poll() array appear in * protocol 0 callback diff --git a/test-server/test-server.c b/test-server/test-server.c index 4422d829..f4995c7c 100644 --- a/test-server/test-server.c +++ b/test-server/test-server.c @@ -64,6 +64,9 @@ static int callback_http(struct libwebsocket *wsi, enum libwebsocket_callback_reasons reason, void *user, void *in, size_t len) { + char client_name[128]; + char client_ip[128]; + switch (reason) { case LWS_CALLBACK_HTTP: fprintf(stderr, "serving HTTP URI %s\n", (char *)in); @@ -82,6 +85,25 @@ static int callback_http(struct libwebsocket *wsi, fprintf(stderr, "Failed to send HTTP file\n"); break; + /* + * callback for confirming to continue with client IP appear in + * protocol 0 callback since no websocket protocol has been agreed + * yet. You can just ignore this if you won't filter on client IP + * since the default uhandled callback return is 0 meaning let the + * connection continue. + */ + + case LWS_CALLBACK_FILTER_NETWORK_CONNECTION: + + libwebsockets_get_peer_addresses((int)(long)user, client_name, + sizeof(client_name), client_ip, sizeof(client_ip)); + + fprintf(stderr, "Received network connect from %s (%s)\n", + client_name, client_ip); + + /* if we returned non-zero from here, we kill the connection */ + break; + default: break; }