ntohs(cs->serv_addr.sin_port),strerror(errno));
if (setsockopt(cs->fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) {
- tlog(TL_CRIT|TL_EXIT, "socketsockopt failed: %s (d%)", strerror(errno), errno);
+ tlog(TL_CRIT|TL_EXIT, "socketsockopt failed: %s (%d)", strerror(errno), errno);
return CS_ERROR;
}
memset(sc, 0, sizeof(TC_Connection));
sc->serv_addr.sin_family = AF_INET;
sc->serv_addr.sin_addr.s_addr = (name) ? inet_addr(name) : htonl(INADDR_ANY);
+ if ( sc->serv_addr.sin_addr.s_addr == INADDR_NONE ) {
+ struct hostent *host;
+
+ /*
+ * Can't parse address: it's a DNS Name
+ */
+ host = gethostbyname(name);
+ if ( host && host->h_addrtype == AF_INET ) {
+ memcpy(&sc->serv_addr.sin_addr.s_addr, host->h_addr_list[0],
+ sizeof(&sc->serv_addr.sin_addr.s_addr));
+ } else {
+#ifdef HAVE_HSTRERROR
+ tlog(TL_CRIT,"gethostbyname: %s - %s", name, hstrerror(h_errno));
+#else
+ tlog(TL_CRIT,"gethostbyname: %s - %s", name, strerror(errno));
+#endif
+ sc->state = CS_ERROR;
+ return sc;
+ }
+ }
+
sc->serv_addr.sin_port = htons(port);
sc->state = CS_NOTINITED;
return sc;
#include <unistd.h>
#include <fcntl.h>
+#ifdef HAVE_HSTRERROR
+#include <netdb.h>
+#endif
+
#include "connection.h"
#include "tlog.h"
#include "tmalloc.h"
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(host);
+ if ( serv_addr.sin_addr.s_addr == INADDR_NONE ) {
+ struct hostent *ip_host;
+
+ /*
+ * Can't parse address: it's a DNS Name
+ */
+ ip_host = gethostbyname(host);
+ if ( ip_host && ip_host->h_addrtype == AF_INET ) {
+ memcpy(&serv_addr.sin_addr.s_addr, ip_host->h_addr_list[0],
+ sizeof(&serv_addr.sin_addr.s_addr));
+ } else {
+#ifdef HAVE_HSTRERROR
+ tlog(TL_CRIT,"gethostbyname: %s - %s", host, hstrerror(h_errno));
+#else
+ tlog(TL_CRIT,"gethostbyname: %s - %s", host, strerror(errno));
+#endif
+ close(sockfd);
+ return -1;
+ }
+ }
serv_addr.sin_port = htons(port);
if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
if ( msg->sockfd <=0 ) {
struct sockaddr_in cli_addr;
+
if ( (msg->sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
tlog(TL_CRIT,"udp socket %s %d: %s", msg->host, msg->port, strerror(errno));
return CS_ERROR;
memset(&(msg->host_addr), 0, sizeof(msg->host_addr));
msg->host_addr.sin_family = AF_INET;
msg->host_addr.sin_addr.s_addr = inet_addr(msg->host);
+ if ( msg->host_addr.sin_addr.s_addr == INADDR_NONE ) {
+ struct hostent *ip_host;
+
+ /*
+ * Can't parse address: it's a DNS Name
+ */
+ ip_host = gethostbyname(msg->host);
+ if ( ip_host && ip_host->h_addrtype == AF_INET ) {
+ memcpy(&msg->host_addr.sin_addr.s_addr, ip_host->h_addr_list[0],
+ sizeof(&msg->host_addr.sin_addr.s_addr));
+ } else {
+#ifdef HAVE_HSTRERROR
+ tlog(TL_CRIT,"gethostbyname: %s - %s", msg->host, hstrerror(h_errno));
+#else
+ tlog(TL_CRIT,"gethostbyname: %s - %s", msg->host, strerror(errno));
+#endif
+ close(msg->sockfd);
+ msg->sockfd=-1;
+ return CS_ERROR;
+ }
+ }
msg->host_addr.sin_port = htons(msg->port);
}