#endif
#ifdef WIN32
+#include <winbase.h>
#define close(x) closesocket(x)
int __stdcall SignalHandler(unsigned long signo) __attribute__ ((noreturn));
void ListInterfaces(void);
* locking file.
*/
static void olsr_create_lock_file(void) {
+#ifdef WIN32
+ HANDLE lck = CreateEvent(NULL, TRUE, FALSE, lock_file_name);
+ if (NULL == lck || ERROR_ALREADY_EXISTS == GetLastError()) {
+ if (NULL == lck) {
+ fprintf(stderr,
+ "Error, cannot create OLSR lock '%s'.\n",
+ lock_file_name);
+ } else {
+ CloseHandle(lck);
+ fprintf(stderr,
+ "Error, cannot aquire OLSR lock '%s'.\n"
+ "Another OLSR instance might be running.\n",
+ lock_file_name);
+ }
+ olsr_exit("", EXIT_FAILURE);
+ }
+#else
struct flock lck;
/* create file for lock */
lock_file_name);
olsr_exit("", EXIT_FAILURE);
}
+#endif
return;
}
{
struct ohs_connection *oc;
int i;
+ uint32_t addr[4];
if (logbits & LOG_CONNECT) {
printf("ohs_init_new_connection\n");
/* Get "fake IP" */
for (i = 0; i < 20; i++) {
/* Win32 needs that cast. */
- if (recv(oc->socket, (void *)&oc->ip_addr, olsr_cnf->ipsize, 0) == (int)olsr_cnf->ipsize) {
+ if (recv(oc->socket, (void *)addr, olsr_cnf->ipsize, 0) == (int)olsr_cnf->ipsize) {
break;
}
#if defined WIN32
return -1;
}
+ addr[0] = ntohl(addr[0]);
+ addr[1] = ntohl(addr[1]);
+ addr[2] = ntohl(addr[2]);
+ addr[3] = ntohl(addr[3]);
+ memcpy(oc->ip_addr.v6.s6_addr, addr, olsr_cnf->ipsize);
+
if (logbits & LOG_CONNECT) {
struct ipaddr_str addrstr;
printf("IP: %s\n", olsr_ip_to_string(&addrstr, &oc->ip_addr));
/* user defined cookies */
typedef uint16_t olsr_cookie_t;
+#ifdef WIN32
+#include <winsock2.h>
+#else
/* manpage says: fd_set is in sys/select.h with posix (at least with the Android-NDK) */
#include <sys/select.h>
+#endif
/* OpenBSD wants this here */
#include <sys/types.h>
#define EWOULDBLOCK WSAEWOULDBLOCK
#undef errno
#define errno WSAGetLastError()
+char *StrError(unsigned int ErrNo);
#undef strerror
#define strerror(x) StrError(x)
#endif
#include "olsr_cookie.h"
#ifdef WIN32
+char *StrError(unsigned int ErrNo);
#undef strerror
#define strerror(x) StrError(x)
#endif
#include "olsr_spf.h"
#include "link_set.h"
#include "olsr_cookie.h"
+#ifdef WIN32
+/* Need stdlib for rand() */
+#include <stdlib.h>
+#define random() rand()
+#define srandom(x) srand(x)
+#endif
/* Timer data, global. Externed in defs.h */
uint32_t now_times; /* relative time compared to startup (in milliseconds */
return 0;
}
-void
+int
gettimeofday(struct timeval *TVal, void *TZone __attribute__ ((unused)))
{
SYSTEMTIME SysTime;
TVal->tv_sec = (unsigned int)(Ticks / 10000000);
TVal->tv_usec = (unsigned int)(Ticks % 10000000) / 10;
+ return 0;
}
long
*
*/
+#include <stdlib.h>
+#define random() rand()
+#define srandom(x) srand(x)
#include <winsock2.h>
#include "interfaces.h"
#include "olsr.h"
New->valtimes.mid = reltime_to_me(IntConf->cnf->mid_params.validity_time * MSEC_PER_SEC);
New->valtimes.hna = reltime_to_me(IntConf->cnf->hna_params.validity_time * MSEC_PER_SEC);
- New->mode = iface->cnf->mode;
+ New->mode = IntConf->cnf->mode;
run_ifchg_cbs(New, IFCHG_IF_ADD);
#if defined WINCE
#define WIDE_STRING(s) L##s
#else
-#define WIDE_STRING(s) s
+#define WIDE_STRING(s) TEXT(s)
#endif
void WinSockPError(const char *Str);
memset(&Addr6, 0, sizeof(Addr6));
Addr6.sin6_family = AF_INET6;
- Addr6.sin6_port = htons(OLSRPORT);
+ Addr6.sin6_port = htons(olsr_cnf->olsrport);
//Addr6.sin6_addr.s_addr = IN6ADDR_ANY_INIT;
if (bind(Sock, (struct sockaddr *)&Addr6, sizeof(Addr6)) < 0) {
WinSockPError("getsocket6/bind()");
enable_ip_forwarding(int Ver)
{
HMODULE Lib;
- unsigned int __stdcall(*EnableRouter) (HANDLE * Hand, OVERLAPPED * Over);
+ unsigned int __stdcall(*enable_router)(HANDLE *, OVERLAPPED *);
HANDLE Hand;
Ver = Ver;
if (Lib == NULL)
return 0;
- EnableRouter = (unsigned int __stdcall(*)(HANDLE *, OVERLAPPED *))GetProcAddress(Lib, WIDE_STRING("EnableRouter"));
+ enable_router = (unsigned int __stdcall(*)(HANDLE *, OVERLAPPED *))GetProcAddress(Lib, WIDE_STRING("EnableRouter"));
- if (EnableRouter == NULL)
+ if (enable_router == NULL)
return 0;
memset(&RouterOver, 0, sizeof(OVERLAPPED));
return -1;
}
- if (EnableRouter(&Hand, &RouterOver) != ERROR_IO_PENDING) {
+ if (enable_router(&Hand, &RouterOver) != ERROR_IO_PENDING) {
PError("EnableRouter()");
return -1;
}
disable_ip_forwarding(int Ver)
{
HMODULE Lib;
- unsigned int __stdcall(*UnenableRouter) (OVERLAPPED * Over, unsigned int *Count);
+ unsigned int __stdcall(*unenable_router)(OVERLAPPED *, unsigned int *);
unsigned int Count;
Ver = Ver;
if (Lib == NULL)
return 0;
- UnenableRouter = (unsigned int __stdcall(*)(OVERLAPPED *, unsigned int *))GetProcAddress(Lib, WIDE_STRING("UnenableRouter"));
+ unenable_router = (unsigned int __stdcall(*)(OVERLAPPED *, unsigned int *))GetProcAddress(Lib, WIDE_STRING("UnenableRouter"));
- if (UnenableRouter == NULL)
+ if (unenable_router == NULL)
return 0;
- if (UnenableRouter(&RouterOver, &Count) != NO_ERROR) {
+ if (unenable_router(&RouterOver, &Count) != NO_ERROR) {
PError("UnenableRouter()");
return -1;
}
int nanosleep(struct timespec *Req, struct timespec *Rem);
-void gettimeofday(struct timeval *TVal, void *TZone);
+int gettimeofday(struct timeval *TVal, void *TZone);
#endif