Skip to content

Commit acdcaf7

Browse files
committed
fixup! Added DNS server with TCP support
1 parent 887635f commit acdcaf7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/dns_server_tcp.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ static void read_cb(struct ev_loop __attribute__((unused)) *loop,
118118

119119
// Receive data
120120
char buf[UINT16_MAX]; // stack buffer for largest DNS request
121-
ssize_t len = recv(w->fd, &buf, UINT16_MAX, 0);
121+
ssize_t len = recv(w->fd, buf, UINT16_MAX, 0);
122122
if (len <= 0) {
123123
if (len == 0 || errno == ECONNRESET) {
124124
DLOG_CLIENT("Connection closed");
125-
} else if (errno == EAGAIN && errno == EWOULDBLOCK) {
125+
} else if (errno == EAGAIN || errno == EWOULDBLOCK) {
126126
return;
127127
} else {
128128
WLOG_CLIENT("Read error: %s", strerror(errno));
@@ -239,17 +239,18 @@ static int get_tcp_listen_sock(struct addrinfo *listen_addrinfo) {
239239
ELOG("Reuse address failed: %s (%d)", strerror(errno), errno);
240240
}
241241

242+
uint16_t port;
242243
char ipstr[INET6_ADDRSTRLEN];
243244
if (listen_addrinfo->ai_family == AF_INET) {
244-
inet_ntop(AF_INET, &((struct sockaddr_in *)listen_addrinfo->ai_addr)->sin_addr, ipstr, sizeof(ipstr));
245+
port = ntohs(((struct sockaddr_in*) listen_addrinfo->ai_addr)->sin_port);
246+
inet_ntop(AF_INET, &((struct sockaddr_in *)listen_addrinfo->ai_addr)->sin_addr, ipstr, sizeof(ipstr));
245247
} else if (listen_addrinfo->ai_family == AF_INET6) {
246-
inet_ntop(AF_INET6, &((struct sockaddr_in6 *)listen_addrinfo->ai_addr)->sin6_addr, ipstr, sizeof(ipstr));
248+
port = ntohs(((struct sockaddr_in6*) listen_addrinfo->ai_addr)->sin6_port);
249+
inet_ntop(AF_INET6, &((struct sockaddr_in6 *)listen_addrinfo->ai_addr)->sin6_addr, ipstr, sizeof(ipstr));
247250
} else {
248251
FLOG("Unknown address family: %d", listen_addrinfo->ai_family);
249252
}
250253

251-
uint16_t port = ntohs(((struct sockaddr_in*) listen_addrinfo->ai_addr)->sin_port);
252-
253254
int res = bind(sock, listen_addrinfo->ai_addr, listen_addrinfo->ai_addrlen);
254255
if (res < 0) {
255256
FLOG("Error binding on %s:%d TCP: %s (%d)", ipstr, port,

0 commit comments

Comments
 (0)