make bencode ILP32/LLP64 clean (long is 32 bits outside of unix!)

actually open new RCs in binary mode
clang-format
win32 skeleton code for tun (still working on the guts)
This commit is contained in:
despair86 2018-09-30 21:08:03 -05:00
parent 8ac7d4f6dc
commit 9fdde65798
11 changed files with 19 additions and 18 deletions

View File

@ -122,8 +122,8 @@ main(int argc, char *argv[])
fs::path fpath = basepath / "lokinet.ini";
std::error_code ec;
// These paths are guaranteed to exist - $APPDATA or $HOME
// so only create .lokinet/*
// These paths are guaranteed to exist - $APPDATA or $HOME
// so only create .lokinet/*
if(!fs::create_directory(basepath, ec))
{
if(ec)

View File

@ -18,7 +18,7 @@
#include <winsock2.h>
#include <ws2tcpip.h>
#include <wspiapi.h>
#define inet_aton(x,y) inet_pton(AF_INET,x,y)
#define inet_aton(x, y) inet_pton(AF_INET, x, y)
#endif
bool

View File

@ -4,7 +4,7 @@
bool
bencode_write_bytestring(llarp_buffer_t* buff, const void* data, size_t sz)
{
if(!llarp_buffer_writef(buff, "%ld:", sz))
if(!llarp_buffer_writef(buff, "%zu:", sz))
return false;
return llarp_buffer_write(buff, data, sz);
}
@ -12,7 +12,7 @@ bencode_write_bytestring(llarp_buffer_t* buff, const void* data, size_t sz)
bool
bencode_write_uint64(llarp_buffer_t* buff, uint64_t i)
{
return llarp_buffer_writef(buff, "i%lu", i)
return llarp_buffer_writef(buff, "i%llu", i)
&& llarp_buffer_write(buff, "e", 1);
}
@ -59,7 +59,7 @@ bencode_read_integer(struct llarp_buffer_t* buffer, uint64_t* result)
buffer->cur++;
numbuf[len] = 0;
*result = strtoul(numbuf, nullptr, 10);
*result = strtoull(numbuf, nullptr, 10);
return true;
}

View File

@ -105,7 +105,7 @@ extern "C"
#ifndef _WIN32
basepath += "/";
#else
basepath += "\\";
basepath += "\\";
#endif
}

View File

@ -462,8 +462,8 @@ raw_resolve_host(struct dnsc_context *dnsc, const char *url,
llarp::LogInfo("Waiting for recv");
// Timeout?
ret = recvfrom(sockfd, (char*)buffer, DNC_BUF_SIZE, 0, (struct sockaddr *)&addr,
&size);
ret = recvfrom(sockfd, (char *)buffer, DNC_BUF_SIZE, 0,
(struct sockaddr *)&addr, &size);
llarp::LogInfo("recv done ", size);
if(ret < 0)
{

View File

@ -121,5 +121,5 @@ bool
llarp_ev_tun_async_write(struct llarp_tun_io *tun, const void *pkt, size_t sz)
{
// TODO: queue write
return static_cast< llarp::ev_io * >(tun->impl)->do_write((void*)pkt, sz);
return static_cast< llarp::ev_io * >(tun->impl)->do_write((void *)pkt, sz);
}

View File

@ -1,8 +1,10 @@
#ifndef LLARP_EV_HPP
#define LLARP_EV_HPP
#include <llarp/ev.h>
// witev
// writev
#ifndef _WIN32
#include <sys/uio.h>
#endif
#ifndef _MSC_VER
#include <unistd.h>

View File

@ -86,7 +86,7 @@ namespace llarp
}
};
struct tun : public ev_io
struct tun : public ev_io
{
llarp_tun_io* t;
device* tunif;
@ -153,7 +153,7 @@ namespace llarp
// set non blocking
int on = 1;
return ioctlsocket(fd, FIONBIO, (u_long*)&on) != -1;
return ioctlsocket(fd, FIONBIO, (u_long*)&on) != -1;
}
~tun()
@ -168,7 +168,6 @@ struct llarp_win32_loop : public llarp_ev_loop
llarp_win32_loop() : iocpfd(INVALID_HANDLE_VALUE)
{
}
~llarp_win32_loop()

View File

@ -443,7 +443,7 @@ namespace llarp
}))
{
llarp::LogInfo("Failed to parse ipv4 packet");
llarp::DumpBuffer(llarp::InitBuffer(buf,sz));
llarp::DumpBuffer(llarp::InitBuffer(buf, sz));
}
}

View File

@ -348,8 +348,8 @@ namespace llarp
static_cast< LinkLayer* >(utp_context_get_userdata(arg->context));
llarp::LogDebug("utp_sendto ", Addr(*arg->address), " ", arg->len,
" bytes");
if(::sendto(l->m_udp.fd, (char*)arg->buf, arg->len, arg->flags, arg->address,
arg->address_len)
if(::sendto(l->m_udp.fd, (char*)arg->buf, arg->len, arg->flags,
arg->address, arg->address_len)
== -1)
{
llarp::LogError("sendto failed: ", strerror(errno));

View File

@ -96,7 +96,7 @@ struct llarp_nodedb
llarp::LogDebug("saving RC.pubkey ", filepath);
std::ofstream ofs(
filepath,
std::ofstream::out & std::ofstream::binary & std::ofstream::trunc);
std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
ofs.write((char *)buf.base, buf.sz);
ofs.close();
if(!ofs)