* fix testnet codepath

* add packet info for osx
pull/686/head
Jeff Becker 5 years ago
parent c4aaa80e75
commit 81cab62bb9
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -306,7 +306,7 @@ namespace llarp
continue;
std::array< byte_t, 128 > tmp = {0};
llarp_buffer_t buf(tmp);
if(SendToServiceOrQueue(introset.A.Addr().data(), buf,
if(SendToServiceOrQueue(introset.A.Addr(), buf,
eProtocolControl))
LogInfo(Name(), " send message to ", introset.A.Addr(), " for tag ",
tag.ToString());

@ -274,8 +274,18 @@ tuntap_read(struct device *dev, void *buf, size_t size)
tuntap_log(TUNTAP_LOG_NOTICE, "Device is not started");
return 0;
}
#if defined(Darwin)
unsigned int pktinfo = 0;
struct iovec vecs[2];
vecs[0].iov_base = &pktinfo;
vecs[0].iov_len = sizeof(unsigned int);
vecs[1].iov_base = buf;
vecs[1].iov_len = size;
n = readv(dev->tun_fd, &vecs, 2);
if(n >= sizeof(unsigned int)) n -= sizeof(unsigned int);
#else
n = read(dev->tun_fd, buf, size);
#endif
if(n == -1)
{
tuntap_log(TUNTAP_LOG_WARN, "Can't to read from device");
@ -295,8 +305,20 @@ tuntap_write(struct device *dev, void *buf, size_t size)
tuntap_log(TUNTAP_LOG_NOTICE, "Device is not started");
return 0;
}
#if defined(Darwin)
/** darwin has packet info so let's use writev */
struct iovec vecs[2];
static unsigned int af4 = AF_INET;
static unsigned int af6 = AF_INET6;
vecs[0].iov_base = (((byte_t*)buf)[0] & 0x60) == 0x60) ? &af6 : &af4;
vecs[0].iov_len = sizeof(unsigned int);
vecs[1].iov_base = buf;
vecs[1].iov_len = size;
n = writev(dev->tun_fd, &vecs, 2);
if (n >= sizeof(unsigned int)) n -= sizeof(unsigned int);
#else
n = write(dev->tun_fd, buf, size);
#endif
if(n == -1)
{
tuntap_log(TUNTAP_LOG_WARN, "Can't write to device");

Loading…
Cancel
Save