Record hostname for each connected client
Signed-off-by: Jim Ramsay <jramsay@redhat.com>pull/83/head
parent
73e1089f06
commit
86bd2ced85
|
@ -69,6 +69,7 @@ struct nvnc_client {
|
||||||
struct nvnc_common common;
|
struct nvnc_common common;
|
||||||
int ref;
|
int ref;
|
||||||
struct stream* net_stream;
|
struct stream* net_stream;
|
||||||
|
char hostname[256];
|
||||||
struct nvnc* server;
|
struct nvnc* server;
|
||||||
enum nvnc_client_state state;
|
enum nvnc_client_state state;
|
||||||
bool has_pixfmt;
|
bool has_pixfmt;
|
||||||
|
|
|
@ -131,6 +131,7 @@ void* nvnc_get_userdata(const void* self);
|
||||||
|
|
||||||
struct nvnc* nvnc_client_get_server(const struct nvnc_client* client);
|
struct nvnc* nvnc_client_get_server(const struct nvnc_client* client);
|
||||||
bool nvnc_client_supports_cursor(const struct nvnc_client* client);
|
bool nvnc_client_supports_cursor(const struct nvnc_client* client);
|
||||||
|
const char* nvnc_client_get_hostname(const struct nvnc_client* client);
|
||||||
|
|
||||||
void nvnc_set_name(struct nvnc* self, const char* name);
|
void nvnc_set_name(struct nvnc* self, const char* name);
|
||||||
|
|
||||||
|
|
29
src/server.c
29
src/server.c
|
@ -1102,6 +1102,24 @@ static void on_client_event(struct stream* stream, enum stream_event event)
|
||||||
client->buffer_index = 0;
|
client->buffer_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void record_peer_hostname(int fd, struct nvnc_client* client)
|
||||||
|
{
|
||||||
|
struct sockaddr_storage storage;
|
||||||
|
struct sockaddr* peer = (struct sockaddr*)&storage;
|
||||||
|
socklen_t peerlen = sizeof(storage);
|
||||||
|
if (getpeername(fd, peer, &peerlen) == 0) {
|
||||||
|
if (peer->sa_family == AF_UNIX) {
|
||||||
|
snprintf(client->hostname, sizeof(client->hostname),
|
||||||
|
"unix domain socket");
|
||||||
|
} else {
|
||||||
|
getnameinfo(peer, peerlen,
|
||||||
|
client->hostname, sizeof(client->hostname),
|
||||||
|
NULL, 0, // no need for port
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void on_connection(void* obj)
|
static void on_connection(void* obj)
|
||||||
{
|
{
|
||||||
struct nvnc* server = aml_get_userdata(obj);
|
struct nvnc* server = aml_get_userdata(obj);
|
||||||
|
@ -1123,6 +1141,8 @@ static void on_connection(void* obj)
|
||||||
int one = 1;
|
int one = 1;
|
||||||
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
|
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
|
||||||
|
|
||||||
|
record_peer_hostname(fd, client);
|
||||||
|
|
||||||
client->net_stream = stream_new(fd, on_client_event, client);
|
client->net_stream = stream_new(fd, on_client_event, client);
|
||||||
if (!client->net_stream) {
|
if (!client->net_stream) {
|
||||||
nvnc_log(NVNC_LOG_WARNING, "OOM");
|
nvnc_log(NVNC_LOG_WARNING, "OOM");
|
||||||
|
@ -1148,7 +1168,7 @@ static void on_connection(void* obj)
|
||||||
|
|
||||||
client->state = VNC_CLIENT_STATE_WAITING_FOR_VERSION;
|
client->state = VNC_CLIENT_STATE_WAITING_FOR_VERSION;
|
||||||
|
|
||||||
nvnc_log(NVNC_LOG_INFO, "New client connection: %p (ref %d)", client, client->ref);
|
nvnc_log(NVNC_LOG_INFO, "New client connection from %s: %p (ref %d)", client->hostname, client, client->ref);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1604,6 +1624,13 @@ struct nvnc* nvnc_client_get_server(const struct nvnc_client* client)
|
||||||
return client->server;
|
return client->server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EXPORT
|
||||||
|
const char* nvnc_client_get_hostname(const struct nvnc_client* client) {
|
||||||
|
if (client->hostname[0] == '\0')
|
||||||
|
return NULL;
|
||||||
|
return client->hostname;
|
||||||
|
}
|
||||||
|
|
||||||
EXPORT
|
EXPORT
|
||||||
bool nvnc_client_supports_cursor(const struct nvnc_client* client)
|
bool nvnc_client_supports_cursor(const struct nvnc_client* client)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue