- Use gai_strerror() where appropriate
- Clear hints before using them with getaddrinfo() - Use sa_len on platforms that support them
This commit is contained in:
parent
28cc9a6488
commit
dbc5b5bb5e
4 changed files with 20 additions and 14 deletions
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: net.h,v 1.9.4.39 2002/02/18 16:25:16 guus Exp $
|
$Id: net.h,v 1.9.4.40 2002/02/20 22:15:32 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TINC_NET_H__
|
#ifndef __TINC_NET_H__
|
||||||
|
@ -67,6 +67,12 @@ typedef union {
|
||||||
|
|
||||||
#define SA_PORT(s) ((s.sa.sa_family==AF_INET)?s.in.sin_port:(s.sa.sa_family==AF_INET6)?s.in6.sin6_port:0)
|
#define SA_PORT(s) ((s.sa.sa_family==AF_INET)?s.in.sin_port:(s.sa.sa_family==AF_INET6)?s.in6.sin6_port:0)
|
||||||
|
|
||||||
|
#ifdef HAVE_LINUX
|
||||||
|
#define SA_LEN(s) sizeof(sockaddr_t)
|
||||||
|
#else
|
||||||
|
#define SA_LEN(s) (s.sa_len)
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct vpn_packet_t {
|
typedef struct vpn_packet_t {
|
||||||
length_t len; /* the actual number of bytes in the `data' field */
|
length_t len; /* the actual number of bytes in the `data' field */
|
||||||
unsigned int seqno; /* 32 bits sequence number (network byte order of course) */
|
unsigned int seqno; /* 32 bits sequence number (network byte order of course) */
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: net_packet.c,v 1.1.2.2 2002/02/20 19:31:15 guus Exp $
|
$Id: net_packet.c,v 1.1.2.3 2002/02/20 22:15:32 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -258,7 +258,7 @@ cp
|
||||||
|
|
||||||
/* Send the packet */
|
/* Send the packet */
|
||||||
|
|
||||||
if((sendto(udp_socket, (char *)&inpkt->seqno, inpkt->len, 0, &(n->address.sa), sizeof(sockaddr_t))) < 0)
|
if((sendto(udp_socket, (char *)&inpkt->seqno, inpkt->len, 0, &(n->address.sa), SA_LEN(n->address.sa))) < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Error sending packet to %s (%s): %s"),
|
syslog(LOG_ERR, _("Error sending packet to %s (%s): %s"),
|
||||||
n->name, n->hostname, strerror(errno));
|
n->name, n->hostname, strerror(errno));
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: net_setup.c,v 1.1.2.3 2002/02/20 19:25:09 guus Exp $
|
$Id: net_setup.c,v 1.1.2.4 2002/02/20 22:15:32 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -221,7 +221,7 @@ int setup_myself(void)
|
||||||
subnet_t *subnet;
|
subnet_t *subnet;
|
||||||
char *name, *mode, *afname, *cipher, *digest;
|
char *name, *mode, *afname, *cipher, *digest;
|
||||||
struct addrinfo hint, *ai;
|
struct addrinfo hint, *ai;
|
||||||
int choice;
|
int choice, err;
|
||||||
cp
|
cp
|
||||||
myself = new_node();
|
myself = new_node();
|
||||||
myself->connection = new_connection();
|
myself->connection = new_connection();
|
||||||
|
@ -462,14 +462,16 @@ cp
|
||||||
cp
|
cp
|
||||||
/* Open sockets */
|
/* Open sockets */
|
||||||
|
|
||||||
|
memset(&hint, 0, sizeof(hint));
|
||||||
|
|
||||||
hint.ai_family = addressfamily;
|
hint.ai_family = addressfamily;
|
||||||
hint.ai_socktype = SOCK_STREAM;
|
hint.ai_socktype = SOCK_STREAM;
|
||||||
hint.ai_protocol = IPPROTO_TCP;
|
hint.ai_protocol = IPPROTO_TCP;
|
||||||
hint.ai_flags = AI_PASSIVE;
|
hint.ai_flags = AI_PASSIVE;
|
||||||
|
|
||||||
if(getaddrinfo(NULL, myport, &hint, &ai) || !ai)
|
if((err = getaddrinfo(NULL, myport, &hint, &ai)) || !ai)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("System call `%s' failed: %s"), "getaddrinfo", strerror(errno));
|
syslog(LOG_ERR, _("System call `%s' failed: %s"), "getaddrinfo", gai_strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,14 +483,12 @@ cp
|
||||||
|
|
||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai);
|
||||||
|
|
||||||
hint.ai_family = addressfamily;
|
|
||||||
hint.ai_socktype = SOCK_DGRAM;
|
hint.ai_socktype = SOCK_DGRAM;
|
||||||
hint.ai_protocol = IPPROTO_UDP;
|
hint.ai_protocol = IPPROTO_UDP;
|
||||||
hint.ai_flags = AI_PASSIVE;
|
|
||||||
|
|
||||||
if(getaddrinfo(NULL, myport, &hint, &ai) || !ai)
|
if((err = getaddrinfo(NULL, myport, &hint, &ai)) || !ai)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("System call `%s' failed: %s"), "getaddrinfo", strerror(errno));
|
syslog(LOG_ERR, _("System call `%s' failed: %s"), "getaddrinfo", gai_strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: netutl.c,v 1.12.4.25 2002/02/20 17:15:33 guus Exp $
|
$Id: netutl.c,v 1.12.4.26 2002/02/20 22:15:32 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -103,7 +103,7 @@ void sockaddr2str(sockaddr_t *sa, char **addrstr, char **portstr)
|
||||||
char port[NI_MAXSERV];
|
char port[NI_MAXSERV];
|
||||||
int err;
|
int err;
|
||||||
cp
|
cp
|
||||||
if((err = getnameinfo((struct sockaddr *)sa, sizeof(sockaddr_t), address, sizeof(address), port, sizeof(port), NI_NUMERICHOST|NI_NUMERICSERV)))
|
if((err = getnameinfo(&sa->sa, SA_LEN(sa->sa), address, sizeof(address), port, sizeof(port), NI_NUMERICHOST|NI_NUMERICSERV)))
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Error while translating addresses: %s"), gai_strerror(err));
|
syslog(LOG_ERR, _("Error while translating addresses: %s"), gai_strerror(err));
|
||||||
cp_trace();
|
cp_trace();
|
||||||
|
@ -123,7 +123,7 @@ char *sockaddr2hostname(sockaddr_t *sa)
|
||||||
char port[NI_MAXSERV] = "unknown";
|
char port[NI_MAXSERV] = "unknown";
|
||||||
int err;
|
int err;
|
||||||
cp
|
cp
|
||||||
if((err = getnameinfo((struct sockaddr *)sa, sizeof(sockaddr_t), address, sizeof(address), port, sizeof(port), hostnames?0:(NI_NUMERICHOST|NI_NUMERICSERV))))
|
if((err = getnameinfo(&sa->sa, SA_LEN(sa->sa), address, sizeof(address), port, sizeof(port), hostnames?0:(NI_NUMERICHOST|NI_NUMERICSERV))))
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Error while looking up hostname: %s"), gai_strerror(err));
|
syslog(LOG_ERR, _("Error while looking up hostname: %s"), gai_strerror(err));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue