Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/libsam3/libsam3.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@

#ifdef __MINGW32__
//#include <winsock.h>
#include <windows.h>
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
#ifndef SHUT_RDWR
#define SHUT_RDWR 2
#endif
#define close closesocket
#endif

#if defined(__unix__) || defined(__APPLE__)
Expand Down Expand Up @@ -96,8 +97,14 @@ int sam3tcpSetTimeoutSend(int fd, int timeoutms) {
struct timeval tv;
//
ms2timeval(&tv, timeoutms);
return (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) < 0 ? -1
#ifdef _WIN32
DWORD timeout = timeoutms;
return (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)) < 0 ? -1
: 0);
#else
return (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&tv, sizeof(tv)) < 0 ? -1
: 0);
#endif
}
return -1;
}
Expand All @@ -107,8 +114,14 @@ int sam3tcpSetTimeoutReceive(int fd, int timeoutms) {
struct timeval tv;
//
ms2timeval(&tv, timeoutms);
return (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0 ? -1
#ifdef _WIN32
DWORD timeout = timeoutms;
return (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)) < 0 ? -1
: 0);
#else
return (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof(tv)) < 0 ? -1
: 0);
#endif
}
return -1;
}
Expand Down Expand Up @@ -148,7 +161,7 @@ int sam3tcpConnectIP(uint32_t ip, int port) {
}
}
//
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val));
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (const char*)&val, sizeof(val));
//
if (connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) {
if (libsam3_debug)
Expand Down Expand Up @@ -931,15 +944,15 @@ int sam3CreateSession(Sam3Session *ses, const char *hostname, int port,
strlen(v) < SAM3_PRIVKEY_MIN_SIZE) {
if (libsam3_debug)
fprintf(stderr, "sam3CreateSession: invalid reply (%ld)...\n",
(v != NULL ? strlen(v) : -1));
(long)(v != NULL ? strlen(v) : -1));
if (libsam3_debug)
sam3DumpFieldList(rep);
sam3FreeFieldList(rep);
goto error;
}
// save our keys
if (strlen(v) > SAM3_PRIVKEY_MAX_SIZE) {
fprintf(stderr, "ERROR, Unexpected key size (%li)!\n", strlen(v));
fprintf(stderr, "ERROR, Unexpected key size (%li)!\n", (long)strlen(v));
goto error;
}
strcpy(ses->privkey, v);
Expand All @@ -955,7 +968,7 @@ int sam3CreateSession(Sam3Session *ses, const char *hostname, int port,
!sam3CheckValidKeyLength(v)) {
if (libsam3_debug)
fprintf(stderr, "sam3CreateSession: invalid NAMING reply (%ld)...\n",
(v != NULL ? strlen(v) : -1));
(long)(v != NULL ? strlen(v) : -1));
if (libsam3_debug)
sam3DumpFieldList(rep);
sam3FreeFieldList(rep);
Expand Down
16 changes: 11 additions & 5 deletions src/libsam3a/libsam3a.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@

#ifdef __MINGW32__
//#include <winsock.h>
#include <windows.h>
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
#ifndef SHUT_RDWR
#define SHUT_RDWR 2
#endif
#define close closesocket
#define ioctl ioctlsocket
#endif

#if defined(__unix__) && !defined(__APPLE__)
Expand Down Expand Up @@ -150,11 +152,15 @@ static int sam3aSocketSetTimeoutReceive (int fd, int timeoutms) {
*/

static int sam3aBytesAvail(int fd) {
#ifdef _WIN32
u_long av = 0;
#else
int av = 0;
#endif
//
if (ioctl(fd, FIONREAD, &av) < 0)
return -1;
return av;
return (int)av;
}

static uint32_t sam3aResolveHost(const char *hostname) {
Expand Down Expand Up @@ -183,7 +189,7 @@ static int sam3aConnect(uint32_t ip, int port, int *complete) {
if ((fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0)) < 0)
return -1;
//
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val));
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (const char*)&val, sizeof(val));
//
for (;;) {
struct sockaddr_in addr;
Expand Down Expand Up @@ -1044,7 +1050,7 @@ static void aioSesConnected(Sam3ASession *ses) {
int res;
socklen_t len = sizeof(res);
//
if (getsockopt(ses->fd, SOL_SOCKET, SO_ERROR, &res, &len) == 0 && res == 0) {
if (getsockopt(ses->fd, SOL_SOCKET, SO_ERROR, (char*)&res, &len) == 0 && res == 0) {
// ok, connected
if (sam3aSesStartHandshake(ses, NULL) < 0)
sesError(ses, NULL);
Expand Down Expand Up @@ -1500,7 +1506,7 @@ static void aioConnConnected(Sam3AConnection *conn) {
int res;
socklen_t len = sizeof(res);
//
if (getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, &res, &len) == 0 && res == 0) {
if (getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, (char*)&res, &len) == 0 && res == 0) {
// ok, connected
if (sam3aConnStartHandshake(conn, NULL) < 0)
connError(conn, NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/libsam3a/libsam3a.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

#ifdef __MINGW32__
//#include <winsock.h>
#include <windows.h>
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
//#define SOCK_CLOEXEC O_CLOEXEC
//#define SOCK_NONBLOCK O_NONBLOCK
Expand Down