server: Remove DNS lookup
DNS lookup is slow and can even fail. Under some circumstances, it will even block for a significant amount of time until it completes. The user of this library can do the lookup instead if they wish.pull/32/merge
parent
0e262c8f33
commit
c76129b2d2
31
src/server.c
31
src/server.c
|
@ -82,6 +82,8 @@ static void on_encode_frame_done(struct encoder*, struct rcbuf*, uint64_t pts);
|
||||||
static bool client_has_encoding(const struct nvnc_client* client,
|
static bool client_has_encoding(const struct nvnc_client* client,
|
||||||
enum rfb_encodings encoding);
|
enum rfb_encodings encoding);
|
||||||
static void process_fb_update_requests(struct nvnc_client* client);
|
static void process_fb_update_requests(struct nvnc_client* client);
|
||||||
|
static void sockaddr_to_string(char* dst, size_t sz,
|
||||||
|
const struct sockaddr* addr);
|
||||||
|
|
||||||
#if defined(PROJECT_VERSION)
|
#if defined(PROJECT_VERSION)
|
||||||
EXPORT const char nvnc_version[] = PROJECT_VERSION;
|
EXPORT const char nvnc_version[] = PROJECT_VERSION;
|
||||||
|
@ -1670,21 +1672,23 @@ static void on_client_event(struct stream* stream, enum stream_event event)
|
||||||
client->buffer_index = 0;
|
client->buffer_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this when nvnc_client_get_hostname gets renamed.
|
||||||
static void record_peer_hostname(int fd, struct nvnc_client* client)
|
static void record_peer_hostname(int fd, struct nvnc_client* client)
|
||||||
{
|
{
|
||||||
struct sockaddr_storage storage;
|
struct sockaddr_storage storage;
|
||||||
struct sockaddr* peer = (struct sockaddr*)&storage;
|
struct sockaddr* peer = (struct sockaddr*)&storage;
|
||||||
socklen_t peerlen = sizeof(storage);
|
socklen_t peerlen = sizeof(storage);
|
||||||
if (getpeername(fd, peer, &peerlen) == 0) {
|
if (getpeername(fd, peer, &peerlen) < 0) {
|
||||||
if (peer->sa_family == AF_UNIX) {
|
nvnc_log(NVNC_LOG_WARNING, "Failed to get address for client: %m");
|
||||||
snprintf(client->hostname, sizeof(client->hostname),
|
return;
|
||||||
"unix domain socket");
|
}
|
||||||
} else {
|
|
||||||
getnameinfo(peer, peerlen,
|
if (peer->sa_family == AF_UNIX) {
|
||||||
client->hostname, sizeof(client->hostname),
|
snprintf(client->hostname, sizeof(client->hostname),
|
||||||
NULL, 0, // no need for port
|
"unix domain socket");
|
||||||
0);
|
} else {
|
||||||
}
|
sockaddr_to_string(client->hostname, sizeof(client->hostname),
|
||||||
|
peer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1771,6 +1775,11 @@ static void sockaddr_to_string(char* dst, size_t sz, const struct sockaddr* addr
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
inet_ntop(addr->sa_family, &sa_in6->sin6_addr, dst, sz);
|
inet_ntop(addr->sa_family, &sa_in6->sin6_addr, dst, sz);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
nvnc_log(NVNC_LOG_DEBUG,
|
||||||
|
"Don't know how to convert sa_family %d to string",
|
||||||
|
addr->sa_family);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2262,6 +2271,8 @@ struct nvnc* nvnc_client_get_server(const struct nvnc_client* client)
|
||||||
return client->server;
|
return client->server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: This function should be renamed to nvnc_client_get_address and it
|
||||||
|
// should return the sockaddr.
|
||||||
EXPORT
|
EXPORT
|
||||||
const char* nvnc_client_get_hostname(const struct nvnc_client* client) {
|
const char* nvnc_client_get_hostname(const struct nvnc_client* client) {
|
||||||
if (client->hostname[0] == '\0')
|
if (client->hostname[0] == '\0')
|
||||||
|
|
Loading…
Reference in New Issue