/* Get MAC address from tap device */
- if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof(mymac.x), mymac.x, sizeof mymac.x, &len, 0)) {
+ if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof(mymac.x), mymac.x, sizeof(mymac.x), &len, 0)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not get MAC address from Windows tap device %s (%s): %s", device, iface, winerror(GetLastError()));
return false;
}
static bool nametocipher(const char *name, int *algo, int *mode) {
size_t i;
- for(i = 0; i < sizeof(ciphertable) / sizeof * ciphertable; i++) {
+ for(i = 0; i < sizeof(ciphertable) / sizeof(*ciphertable); i++) {
if(ciphertable[i].name && !strcasecmp(name, ciphertable[i].name)) {
*algo = ciphertable[i].algo;
*mode = ciphertable[i].mode;
static bool nidtocipher(int nid, int *algo, int *mode) {
size_t i;
- for(i = 0; i < sizeof(ciphertable) / sizeof * ciphertable; i++) {
+ for(i = 0; i < sizeof(ciphertable) / sizeof(*ciphertable); i++) {
if(nid == ciphertable[i].nid) {
*algo = ciphertable[i].algo;
*mode = ciphertable[i].mode;
static bool ciphertonid(int algo, int mode, int *nid) {
size_t i;
- for(i = 0; i < sizeof(ciphertable) / sizeof * ciphertable; i++) {
+ for(i = 0; i < sizeof(ciphertable) / sizeof(*ciphertable); i++) {
if(algo == ciphertable[i].algo && mode == ciphertable[i].mode) {
*nid = ciphertable[i].nid;
return true;
static bool nametodigest(const char *name, int *algo) {
int i;
- for(i = 0; i < sizeof(digesttable) / sizeof * digesttable; i++) {
+ for(i = 0; i < sizeof(digesttable) / sizeof(*digesttable); i++) {
if(digesttable[i].name && !strcasecmp(name, digesttable[i].name)) {
*algo = digesttable[i].algo;
return true;
static bool nidtodigest(int nid, int *algo) {
int i;
- for(i = 0; i < sizeof(digesttable) / sizeof * digesttable; i++) {
+ for(i = 0; i < sizeof(digesttable) / sizeof(*digesttable); i++) {
if(nid == digesttable[i].nid) {
*algo = digesttable[i].algo;
return true;
static bool digesttonid(int algo, int *nid) {
int i;
- for(i = 0; i < sizeof(digesttable) / sizeof * digesttable; i++) {
+ for(i = 0; i < sizeof(digesttable) / sizeof(*digesttable); i++) {
if(algo == digesttable[i].algo) {
*nid = digesttable[i].nid;
return true;
char hisname[4096] = "";
int code, hismajor, hisminor = 0;
- if(!recvline(sock, line, sizeof(line)) || sscanf(line, "%d %4095s %d.%d", &code, hisname, &hismajor, &hisminor) < 3 || code != 0 || hismajor != PROT_MAJOR || !check_id(hisname) || !recvline(sock, line, sizeof line) || !rstrip(line) || sscanf(line, "%d ", &code) != 1 || code != ACK || strlen(line) < 3) {
+ if(!recvline(sock, line, sizeof(line)) || sscanf(line, "%d %4095s %d.%d", &code, hisname, &hismajor, &hisminor) < 3 || code != 0 || hismajor != PROT_MAJOR || !check_id(hisname) || !recvline(sock, line, sizeof(line)) || !rstrip(line) || sscanf(line, "%d ", &code) != 1 || code != ACK || strlen(line) < 3) {
fprintf(stderr, "Cannot read greeting from peer\n");
closesocket(sock);
goto next;
ULONG info[3] = {0};
DWORD len;
- if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_VERSION, &info, sizeof(info), &info, sizeof info, &len, NULL)) {
+ if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_VERSION, &info, sizeof(info), &info, sizeof(info), &len, NULL)) {
logger(DEBUG_ALWAYS, LOG_WARNING, "Could not get version information from Windows tap device %s (%s): %s", device, iface, winerror(GetLastError()));
} else {
logger(DEBUG_ALWAYS, LOG_INFO, "TAP-Windows driver version: %lu.%lu%s", info[0], info[1], info[2] ? " (DEBUG)" : "");
/* Get MAC address from tap device */
- if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof(mymac.x), mymac.x, sizeof mymac.x, &len, 0)) {
+ if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof(mymac.x), mymac.x, sizeof(mymac.x), &len, 0)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not get MAC address from Windows tap device %s (%s): %s", device, iface, winerror(GetLastError()));
return false;
}
ULONG status = 1;
DWORD len;
- DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof status, &len, NULL);
+ DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof(status), &len, NULL);
/* We don't use the write event directly, but GetOverlappedResult() does, internally. */
ULONG status = 0;
DWORD len;
- DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof status, &len, NULL);
+ DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof(status), &len, NULL);
/* Note that we don't try to cancel ongoing I/O here - we just stop listening.
This is because some TAP-Win32 drivers don't seem to handle cancellation very well,
if(type == SPTPS_HANDSHAKE || tcponly || (!direct && !relay_supported) || (type != PKT_PROBE && (len - SPTPS_DATAGRAM_OVERHEAD) > relay->minmtu)) {
if(type != SPTPS_HANDSHAKE && (to->nexthop->connection->options >> 24) >= 7) {
- char buf[len + sizeof(to->id) + sizeof from->id];
+ char buf[len + sizeof(to->id) + sizeof(from->id)];
char *buf_ptr = buf;
memcpy(buf_ptr, &to->id, sizeof(to->id));
- buf_ptr += sizeof to->id;
+ buf_ptr += sizeof(to->id);
memcpy(buf_ptr, &from->id, sizeof(from->id));
- buf_ptr += sizeof from->id;
+ buf_ptr += sizeof(from->id);
memcpy(buf_ptr, data, len);
logger(DEBUG_TRAFFIC, LOG_INFO, "Sending packet from %s (%s) to %s (%s) via %s (%s) (TCP)", from->name, from->hostname, to->name, to->hostname, to->nexthop->name, to->nexthop->hostname);
return send_sptps_tcppacket(to->nexthop->connection, buf, sizeof(buf));
size_t overhead = 0;
if(relay_supported) {
- overhead += sizeof(to->id) + sizeof from->id;
+ overhead += sizeof(to->id) + sizeof(from->id);
}
char buf[len + overhead];
/* Inform the recipient that this packet was sent directly. */
node_id_t nullid = {};
memcpy(buf_ptr, &nullid, sizeof(nullid));
- buf_ptr += sizeof nullid;
+ buf_ptr += sizeof(nullid);
} else {
memcpy(buf_ptr, &to->id, sizeof(to->id));
- buf_ptr += sizeof to->id;
+ buf_ptr += sizeof(to->id);
}
memcpy(buf_ptr, &from->id, sizeof(from->id));
- buf_ptr += sizeof from->id;
+ buf_ptr += sizeof(from->id);
}
return;
}
- err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof port, NI_NUMERICHOST | NI_NUMERICSERV);
+ err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV);
if(err) {
logger(DEBUG_ALWAYS, LOG_ERR, "Error while translating addresses: %s", err == EAI_SYSTEM ? strerror(errno) : gai_strerror(err));
return str;
}
- err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof port,
+ err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port),
hostnames ? 0 : (NI_NUMERICHOST | NI_NUMERICSERV));
if(err) {
}
case 1: {
- if((inlen = read(request_fd, &request, sizeof(request))) != sizeof request) {
+ if((inlen = read(request_fd, &request, sizeof(request))) != sizeof(request)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Error while reading request from %s %s: %s", device_info,
device, strerror(errno));
event_exit();
return 0;
}
- memcpy(&icmp, buf + 14 + sizeof(ip), sizeof icmp);
+ memcpy(&icmp, buf + 14 + sizeof(ip), sizeof(icmp));
if(icmp.icmp_type != ICMP_ECHO) {
return 0;
icmp.icmp_type = ICMP_ECHOREPLY;
memcpy(buf + 14, &ip, sizeof(ip));
- memcpy(buf + 14 + sizeof(ip), &icmp, sizeof icmp);
+ memcpy(buf + 14 + sizeof(ip), &icmp, sizeof(icmp));
return len;
}