diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2019-08-10 12:03:13 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2019-08-10 12:03:13 +0200 |
commit | 05425539f8f939ea2edc03c1e011e41952612836 (patch) | |
tree | 96f72afa6e9f48aaa63c13c6ef6f1a3944952bdc /lib/lanplus/lanplus.c | |
parent | 5f532f12bf9a32e4fe135280c22a12de32c8ebd3 (diff) | |
parent | 27df2893a39a9da083841e37c12fc24b2bdad80f (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'lib/lanplus/lanplus.c')
-rw-r--r-- | lib/lanplus/lanplus.c | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/lib/lanplus/lanplus.c b/lib/lanplus/lanplus.c index e423ede..c910b85 100644 --- a/lib/lanplus/lanplus.c +++ b/lib/lanplus/lanplus.c @@ -32,19 +32,18 @@ /* ARCress, TODO: improve error handling and remove all assert() calls here. */ #ifdef WIN32 -#include <windows.h> -#include <stdio.h> -#include <stdlib.h> -#include <inttypes-win.h> -#include <io.h> -#include <signal.h> -//#define HAVE_IPV6 1 #ifdef HAVE_IPV6 #include <winsock2.h> //#include <ws2tcpip.h> #else #include <winsock.h> #endif +#include <windows.h> +#include <stdio.h> +#include <stdlib.h> +#include <inttypes-win.h> +#include <io.h> +#include <signal.h> #include <time.h> #else #include <stdlib.h> @@ -103,7 +102,11 @@ static int my_ai_flags = AI_NUMERICSERV; /*0x0400 Dont use name resolution NEW*/ #undef HAVE_IPV6 #endif #ifdef HAVE_IPV6 +#ifdef WIN32 +#define SOCKADDR_T SOCKADDR_STORAGE +#else #define SOCKADDR_T struct sockaddr_storage +#endif #else #define SOCKADDR_T struct sockaddr_in #endif @@ -3703,7 +3706,7 @@ ipmi_lanplus_open(struct ipmi_intf * intf) #endif #ifdef HAVE_IPV6 - session->addrlen = 0; + session->addrlen = 0; memset(&session->addr, 0, sizeof(session->addr)); memset(&addr, 0, sizeof(addr)); sprintf(service, "%d", session->port); @@ -3714,10 +3717,10 @@ ipmi_lanplus_open(struct ipmi_intf * intf) hints.ai_flags = my_ai_flags; hints.ai_protocol = IPPROTO_UDP; /* */ - rc = getaddrinfo((char *)session->hostname, service, &hints, &result); + rc = getaddrinfo((char *)session->hostname, service, &hints, &result); if (rc != 0) { - lprintf(LOG_ERR, "Address lookup for %s failed with %d", - session->hostname,rc); + lprintf(LOG_ERR, "Address lookup for %s failed with %d, %s", + session->hostname,rc,gai_strerror(rc)); return -1; } @@ -3725,24 +3728,24 @@ ipmi_lanplus_open(struct ipmi_intf * intf) * Try each address until we successfully connect(2). */ for (rp = result; rp != NULL; rp = rp->ai_next) { - intf->fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if (intf->fd == -1) continue; + intf->fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if (intf->fd == -1) continue; /* valid protocols are IPPROTO_UDP, IPPROTO_IPV6 */ if (rp->ai_protocol == IPPROTO_TCP) continue; /*IPMI != TCP*/ lprintf(LOG_DEBUG, "lanplus socket(%d,%d,%d), connect(%d)", rp->ai_family, rp->ai_socktype, rp->ai_protocol, intf->fd ); - if (connect(intf->fd, rp->ai_addr, rp->ai_addrlen) != -1) { + if (connect(intf->fd, rp->ai_addr, rp->ai_addrlen) != -1) { lprintf(LOG_DEBUG, "lanplus connect ok, addrlen=%d size=%d", rp->ai_addrlen,sizeof(addr)); - addrlen = rp->ai_addrlen; - memcpy(&addr, rp->ai_addr, addrlen); - // memcpy(&session->addr, rp->ai_addr, rp->ai_addrlen); - session->addrlen = rp->ai_addrlen; - break; /* Success */ - } - close(intf->fd); - intf->fd = -1; + addrlen = rp->ai_addrlen; + memcpy(&addr, rp->ai_addr, addrlen); + // memcpy(&session->addr, rp->ai_addr, rp->ai_addrlen); + session->addrlen = rp->ai_addrlen; + break; /* Success */ + } + close(intf->fd); + intf->fd = -1; } freeaddrinfo(result); /* Done with addrinfo */ if (intf->fd < 0) { |