along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net.c,v 1.35.4.150 2001/11/16 17:38:39 zarq Exp $
+ $Id: net.c,v 1.35.4.151 2001/11/16 22:41:38 zarq Exp $
*/
#include "config.h"
char *hostlookup(struct sockaddr *addr, int numericonly)
{
- char *name;
- struct hostent *host = NULL;
- struct in_addr in;
- config_t const *cfg;
+ char *hostname;
int flags = 0;
+ int r;
cp
if(numericonly
- || ((cfg = get_config_val(config, resolve_dns)) == NULL
- || cfg->data.val != stupid_true))
+ || (get_config_bool(lookup_config(config_tree, "ResolveDNS"), &r)
+ || !r ))
flags |= NI_NUMERICHOST;
hostname = xmalloc(NI_MAXHOST);
- if((r = getnameinfo(addr, sizeof(*addr), &hostname, NI_MAXHOST, NULL, 0, flags)) != 0)
+ if((r = getnameinfo(addr, sizeof(*addr), hostname, NI_MAXHOST, NULL, 0, flags)) != 0)
{
free(hostname);
if(flags & NI_NUMERICHOST)
vpn_packet_t outpkt;
int outlen, outpad;
EVP_CIPHER_CTX ctx;
- struct sockaddr_in to;
- socklen_t tolen = sizeof(to);
vpn_packet_t *copy;
cp
if(!n->status.validkey)
if(bind(nfd, ai->ai_addr, ai->ai_addrlen))
{
close(nfd);
- syslog(LOG_ERR, _("Can't bind to %s port %d/tcp: %m"),
+ syslog(LOG_ERR, _("Can't bind to %s port %s/tcp: %m"),
ai->ai_canonname, n->port);
continue;
}
if(bind(nfd, ai->ai_addr, ai->ai_addrlen))
{
close(nfd);
- syslog(LOG_ERR, _("Can't bind to %s port %d/tcp: %m"),
+ syslog(LOG_ERR, _("Can't bind to %s port %s/tcp: %m"),
ai->ai_canonname, n->port);
continue;
}
int setup_outgoing_socket(connection_t *c)
{
int flags;
- struct sockaddr_in a;
cp
if(debug_lvl >= DEBUG_CONNECTIONS)
syslog(LOG_INFO, _("Trying to connect to %s (%s)"), c->name, c->hostname);
if(c->socket == -1)
{
- syslog(LOG_ERR, _("Creating socket for %s port %d failed: %m"),
+ syslog(LOG_ERR, _("Creating socket for %s port %s failed: %m"),
c->hostname, c->port);
return -1;
}
myself->status.active = 1;
node_add(myself);
- syslog(LOG_NOTICE, _("Ready: listening on port %hd"), myself->port);
+ syslog(LOG_NOTICE, _("Ready: listening on port %s"), myself->port);
cp
return 0;
}
return NULL;
}
- asprintf(&(c->address), " = ntohl(ci.sin_addr.s_addr);
- c->hostname = hostlookup(ci.sin_addr.s_addr);
+ c->address = sockaddr_to_addrinfo(ci);
+
+ c->hostname = xmalloc(INET6_ADDRSTRLEN);
+ if((inet_ntop(ci.sin_family, &(ci.sin_addr), c->hostname, INET6_ADDRSTRLEN)) == NULL)
+ {
+ syslog(LOG_ERR, _("Couldn't convert address to string: %m"));
+ free(c->hostname);
+ return NULL;
+ }
asprintf(&(c->port), "%d", htons(ci.sin_port));
c->socket = sfd;
c->last_ping_time = time(NULL);
if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Connection from %s port %d"),
+ syslog(LOG_NOTICE, _("Connection from %s port %s"),
c->hostname, c->port);
c->allow_request = ID;
return;
}
- n = lookup_node_udp(ntohl(from.sin_addr.s_addr), ntohs(from.sin_port));
+ n = lookup_node_udp(sockaddr_to_addrinfo(&from));
if(!n)
{
- syslog(LOG_WARNING, _("Received UDP packet on port %hd from unknown source %x:%hd"), myself->port, ntohl(from.sin_addr.s_addr), ntohs(from.sin_port));
+ syslog(LOG_WARNING, _("Received UDP packet on port %s from unknown source %x:%hd"), myself->port, ntohl(from.sin_addr.s_addr), ntohs(from.sin_port));
return;
}
/*
if(setup_outgoing_connection(name)) /* function returns 0 when there are no problems */
retry = 1;
- cfg = lookup_config_next(config._tree, cfg); /* Next time skip to next ConnectTo line */
+ cfg = lookup_config_next(config_tree, cfg); /* Next time skip to next ConnectTo line */
}
get_config_int(lookup_config(config_tree, "MaxTimeout"), &maxtimeout);