Tweaks to cover WIN32 build. Added print of error if tcp connect() fails.
git-svn-id: file:///home/mbr/svn/fwknop/trunk@113 510a4753-2344-4c79-9c09-4d669213fbeb
This commit is contained in:
+1
-1
@@ -178,7 +178,7 @@ validate_cmd_msg(const char *msg)
|
||||
int
|
||||
validate_access_msg(const char *msg)
|
||||
{
|
||||
const char *ndx, *ndx2;
|
||||
const char *ndx;
|
||||
int res = FKO_SUCCESS;
|
||||
int startlen = strlen(msg);
|
||||
|
||||
|
||||
+20
-9
@@ -56,13 +56,16 @@ chksum(unsigned short *buf, int nbytes)
|
||||
|
||||
static int is_ip(char *str)
|
||||
{
|
||||
int rv = 1, i;
|
||||
int rv = 1;
|
||||
unsigned int i;
|
||||
|
||||
for (i=0; i < strlen(str); i++) {
|
||||
if (str[i] != '.' && ! isdigit(str[i])) {
|
||||
rv = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -75,6 +78,7 @@ send_spa_packet_tcp_or_udp(char *spa_data, int sd_len, fko_cli_options_t *option
|
||||
struct addrinfo *result, *rp, hints;
|
||||
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
|
||||
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
|
||||
|
||||
if (options->spa_proto == FKO_PROTO_UDP)
|
||||
@@ -108,21 +112,24 @@ send_spa_packet_tcp_or_udp(char *spa_data, int sd_len, fko_cli_options_t *option
|
||||
if (sock < 0)
|
||||
continue;
|
||||
|
||||
if (connect(sock, rp->ai_addr, rp->ai_addrlen) != -1)
|
||||
if (error = connect(sock, rp->ai_addr, rp->ai_addrlen) != -1)
|
||||
break; /* made it */
|
||||
|
||||
#ifdef WIN32
|
||||
closesocket(sock);
|
||||
#else
|
||||
close(sock);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (rp == NULL) {
|
||||
fprintf(stderr,
|
||||
"[*] send_spa_packet_tcp_or_udp: Could not create socket.\n");
|
||||
perror("[*] send_spa_packet_tcp_or_udp: Could not create socket: ");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
freeaddrinfo(result);
|
||||
|
||||
res = write(sock, spa_data, sd_len);
|
||||
res = send(sock, spa_data, sd_len, 0);
|
||||
|
||||
if(res < 0)
|
||||
{
|
||||
@@ -130,8 +137,10 @@ send_spa_packet_tcp_or_udp(char *spa_data, int sd_len, fko_cli_options_t *option
|
||||
}
|
||||
else if(res != sd_len)
|
||||
{
|
||||
fprintf(stderr, "[#] Warning: bytes sent (%i) not spa data length (%i).\n",
|
||||
res, sd_len);
|
||||
fprintf(stderr,
|
||||
"[#] Warning: bytes sent (%i) not spa data length (%i).\n",
|
||||
res, sd_len
|
||||
);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -235,8 +244,10 @@ send_spa_packet_tcp_raw(char *spa_data, int sd_len, struct sockaddr_in *saddr,
|
||||
}
|
||||
else if(res != sd_len)
|
||||
{
|
||||
fprintf(stderr, "[#] Warning: bytes sent (%i) not spa data length (%i).\n",
|
||||
res, sd_len);
|
||||
fprintf(stderr,
|
||||
"[#] Warning: bytes sent (%i) not spa data length (%i).\n",
|
||||
res, sd_len
|
||||
);
|
||||
}
|
||||
|
||||
close(sock);
|
||||
|
||||
+1
-1
@@ -28,7 +28,6 @@
|
||||
|
||||
#include "fwknop_common.h"
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <winsock2.h>
|
||||
@@ -37,6 +36,7 @@
|
||||
#if HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
/* We will roll our own packet header structs. */
|
||||
|
||||
Reference in New Issue
Block a user