Change DNS resolver to ignore hostnames longer than 39 symbols and

prefer IP/IPv6 addresses instead;  substitute "localhost" with
"unknown".
This commit is contained in:
Mike Belopuhov 2014-03-07 16:42:03 +01:00
parent 88719535c4
commit 72898238c8
2 changed files with 11 additions and 6 deletions

14
dns.c
View File

@ -42,7 +42,7 @@ struct icbd_dnsquery {
uint64_t sid;
union {
struct sockaddr_storage req;
char rep[MAXHOSTNAMELEN];
char rep[NI_MAXHOST];
} u;
};
@ -167,11 +167,15 @@ dns_done(int fd, short event, void *arg __attribute__((unused)))
return;
}
memcpy(is->host, q.u.rep, MAXHOSTNAMELEN);
is->host[sizeof is->host - 1] = '\0';
if (verbose)
syslog(LOG_DEBUG, "icbd_dns: resolved %s", is->host);
syslog(LOG_DEBUG, "icbd_dns: resolved %s to %s",
is->host, q.u.rep);
/* XXX */
if (strcmp(q.u.rep, "localhost") == 0)
strlcpy(is->host, "unknown", ICB_MAXHOSTLEN);
else if (strlen(q.u.rep) < ICB_MAXHOSTLEN)
strlcpy(is->host, q.u.rep, ICB_MAXHOSTLEN);
}
void

3
icb.h
View File

@ -29,6 +29,7 @@
#define ICB_MAXNICKLEN 32
#define ICB_MAXPASSLEN 32
#define ICB_MAXTOPICLEN 160
#define ICB_MAXHOSTLEN 40
#define ICB_MTABLEN 50 /* XXX */
#define ICB_M_LOGIN 'a'
@ -75,7 +76,7 @@ struct icb_session {
uint64_t id;
char nick[ICB_MAXNICKLEN];
char client[ICB_MAXNICKLEN];
char host[MAXHOSTNAMELEN];
char host[ICB_MAXHOSTLEN];
char buffer[ICB_MSGSIZE];
struct event ev;
struct bufferevent *bev;