if(!found) {
logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
- outgoing_t *outgoing = xzalloc(sizeof *outgoing);
+ outgoing_t *outgoing = xzalloc(sizeof(*outgoing));
outgoing->name = xstrdup(n->name);
list_insert_tail(outgoing_list, outgoing);
setup_outgoing_connection(outgoing);
return;
logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
- outgoing_t *outgoing = xzalloc(sizeof *outgoing);
+ outgoing_t *outgoing = xzalloc(sizeof(*outgoing));
outgoing->name = xstrdup(n->name);
list_insert_tail(outgoing_list, outgoing);
setup_outgoing_connection(outgoing);
}
struct ctl_info info = {};
- strlcpy(info.ctl_name, UTUN_CONTROL_NAME, sizeof info.ctl_name);
+ strlcpy(info.ctl_name, UTUN_CONTROL_NAME, sizeof(info.ctl_name));
if(ioctl(device_fd, CTLIOCGINFO, &info) == -1) {
logger(DEBUG_ALWAYS, LOG_ERR, "ioctl(CTLIOCGINFO) failed: %s", strerror(errno));
struct sockaddr_ctl sc = {
.sc_id = info.ctl_id,
- .sc_len = sizeof sc,
+ .sc_len = sizeof(sc),
.sc_family = AF_SYSTEM,
.ss_sysaddr = AF_SYS_CONTROL,
.sc_unit = unit + 1,
}
char name[64] = "";
- socklen_t len = sizeof name;
+ socklen_t len = sizeof(name);
if(getsockopt(device_fd, SYSPROTO_CONTROL, UTUN_OPT_IFNAME, name, &len)) {
iface = xstrdup(device);
} else {
#ifdef TUNSIFHEAD
{
const int zero = 0;
- if(ioctl(device_fd, TUNSIFHEAD, &zero, sizeof zero) == -1) {
+ if(ioctl(device_fd, TUNSIFHEAD, &zero, sizeof(zero)) == -1) {
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "ioctl", strerror(errno));
return false;
}
#if defined(TUNSIFMODE) && defined(IFF_BROADCAST) && defined(IFF_MULTICAST)
{
const int mode = IFF_BROADCAST | IFF_MULTICAST;
- ioctl(device_fd, TUNSIFMODE, &mode, sizeof mode);
+ ioctl(device_fd, TUNSIFMODE, &mode, sizeof(mode));
}
#endif
#ifdef TUNSIFHEAD
{
const int one = 1;
- if(ioctl(device_fd, TUNSIFHEAD, &one, sizeof one) == -1) {
+ if(ioctl(device_fd, TUNSIFHEAD, &one, sizeof(one)) == -1) {
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "ioctl", strerror(errno));
return false;
}
#if defined(TUNSIFMODE) && defined(IFF_BROADCAST) && defined(IFF_MULTICAST)
{
const int mode = IFF_BROADCAST | IFF_MULTICAST;
- ioctl(device_fd, TUNSIFMODE, &mode, sizeof mode);
+ ioctl(device_fd, TUNSIFMODE, &mode, sizeof(mode));
}
#endif
return false;
}
- memcpy(DATA(packet) + 10, &type, sizeof type);
+ memcpy(DATA(packet) + 10, &type, sizeof(type));
if(write(device_fd, DATA(packet) + 10, packet->len - 10) < 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "Can't write to %s %s: %s", device_info, device,
{
va_list vl;
va_start(vl, format);
- vsnprintf(tunemu_error, sizeof tunemu_error, format, vl);
+ vsnprintf(tunemu_error, sizeof(tunemu_error), format, vl);
va_end(vl);
}
chacha_poly1305_ctx_t *chacha_poly1305_init(void)
{
- chacha_poly1305_ctx_t *ctx = xzalloc(sizeof *ctx);
+ chacha_poly1305_ctx_t *ctx = xzalloc(sizeof(*ctx));
return ctx;
}
/* Teach newbies what subnets are... */
if(((subnet.type == SUBNET_IPV4)
- && !maskcheck(&subnet.net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof subnet.net.ipv4.address))
+ && !maskcheck(&subnet.net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof(subnet.net.ipv4.address)))
|| ((subnet.type == SUBNET_IPV6)
- && !maskcheck(&subnet.net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof subnet.net.ipv6.address))) {
+ && !maskcheck(&subnet.net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof(subnet.net.ipv6.address)))) {
logger(DEBUG_ALWAYS, LOG_ERR, "Network address and prefix length do not match for configuration variable %s in %s line %d",
cfg->variable, cfg->file, cfg->line);
return false;
}
for(;;) {
- line = readline(fp, buffer, sizeof buffer);
+ line = readline(fp, buffer, sizeof(buffer));
if(!line) {
if(feof(fp))
read_config_options(config_tree, NULL);
- snprintf(fname, sizeof fname, "%s" SLASH "tinc.conf", confbase);
+ snprintf(fname, sizeof(fname), "%s" SLASH "tinc.conf", confbase);
errno = 0;
x = read_config_file(config_tree, fname);
// We will try to read the conf files in the "conf.d" dir
if (x) {
char dname[PATH_MAX];
- snprintf(dname, sizeof dname, "%s" SLASH "conf.d", confbase);
+ snprintf(dname, sizeof(dname), "%s" SLASH "conf.d", confbase);
DIR *dir = opendir (dname);
// If we can find this dir
if (dir) {
size_t l = strlen(ep->d_name);
// And we try to read the ones that end with ".conf"
if (l > 5 && !strcmp(".conf", & ep->d_name[ l - 5 ])) {
- snprintf(fname, sizeof fname, "%s" SLASH "%s", dname, ep->d_name);
+ snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ep->d_name);
x = read_config_file(config_tree, fname);
}
}
read_config_options(config_tree, name);
- snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, name);
+ snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, name);
x = read_config_file(config_tree, fname);
return x;
bool append_config_file(const char *name, const char *key, const char *value) {
char fname[PATH_MAX];
- snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, name);
+ snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, name);
FILE *fp = fopen(fname, "a");
send_request(cdump, "%d %d %s %s %x %d %x",
CONTROL, REQ_DUMP_CONNECTIONS,
c->name, c->hostname, c->options, c->socket,
- bitfield_to_int(&c->status, sizeof c->status));
+ bitfield_to_int(&c->status, sizeof(c->status)));
}
return send_request(cdump, "%d %d", CONTROL, REQ_DUMP_CONNECTIONS);
}
bool init_control(void) {
- randomize(controlcookie, sizeof controlcookie / 2);
- bin2hex(controlcookie, controlcookie, sizeof controlcookie / 2);
+ randomize(controlcookie, sizeof(controlcookie) / 2);
+ bin2hex(controlcookie, controlcookie, sizeof(controlcookie) / 2);
mode_t mask = umask(0);
umask(mask | 077);
char *localhost = NULL;
sockaddr_t sa;
- socklen_t len = sizeof sa;
+ socklen_t len = sizeof(sa);
// Make sure we have a valid address, and map 0.0.0.0 and :: to 127.0.0.1 and ::1.
sa.in.sin_addr.s_addr = htonl(0x7f000001);
} else if(sa.sa.sa_family == AF_INET6) {
static const uint8_t zero[16] = {0};
- if(!memcmp(sa.in6.sin6_addr.s6_addr, zero, sizeof zero))
+ if(!memcmp(sa.in6.sin6_addr.s6_addr, zero, sizeof(zero)))
sa.in6.sin6_addr.s6_addr[15] = 1;
}
struct sockaddr_un sa_un;
sa_un.sun_family = AF_UNIX;
- strncpy(sa_un.sun_path, unixsocketname, sizeof sa_un.sun_path);
+ strncpy(sa_un.sun_path, unixsocketname, sizeof(sa_un.sun_path));
- if(connect(unix_fd, (struct sockaddr *)&sa_un, sizeof sa_un) >= 0) {
+ if(connect(unix_fd, (struct sockaddr *)&sa_un, sizeof(sa_un)) >= 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "UNIX socket %s is still in use!", unixsocketname);
return false;
}
unlink(unixsocketname);
umask(mask | 077);
- int result = bind(unix_fd, (struct sockaddr *)&sa_un, sizeof sa_un);
+ int result = bind(unix_fd, (struct sockaddr *)&sa_un, sizeof(sa_un));
umask(mask);
if(result < 0) {
}
for (i = 0; ; i++) {
- len = sizeof adapterid;
+ len = sizeof(adapterid);
if(RegEnumKeyEx(key, i, adapterid, &len, 0, 0, 0, NULL))
break;
/* Find out more about this adapter */
- snprintf(regpath, sizeof regpath, "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, adapterid);
+ snprintf(regpath, sizeof(regpath), "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, adapterid);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &key2))
continue;
- len = sizeof adaptername;
+ len = sizeof(adaptername);
err = RegQueryValueEx(key2, "Name", 0, 0, adaptername, &len);
RegCloseKey(key2);
continue;
}
- snprintf(tapname, sizeof tapname, USERMODEDEVICEDIR "%s" TAPSUFFIX, adapterid);
+ snprintf(tapname, sizeof(tapname), USERMODEDEVICEDIR "%s" TAPSUFFIX, adapterid);
device_handle = CreateFile(tapname, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, 0);
if(device_handle != INVALID_HANDLE_VALUE) {
CloseHandle(device_handle);
if(!iface)
iface = xstrdup(adaptername);
- snprintf(tapname, sizeof tapname, USERMODEDEVICEDIR "%s" TAPSUFFIX, device);
+ snprintf(tapname, sizeof(tapname), USERMODEDEVICEDIR "%s" TAPSUFFIX, device);
/* Now we are going to open this device twice: once for reading and once for writing.
We do this because apparently it isn't possible to check for activity in the select() loop.
/* 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;
}
#include "../xalloc.h"
ecdh_t *ecdh_generate_public(void *pubkey) {
- ecdh_t *ecdh = xzalloc(sizeof *ecdh);
+ ecdh_t *ecdh = xzalloc(sizeof(*ecdh));
uint8_t seed[32];
- randomize(seed, sizeof seed);
+ randomize(seed, sizeof(seed));
ed25519_create_keypair(pubkey, ecdh->private, seed);
return ecdh;
return 0;
}
- ecdsa_t *ecdsa = xzalloc(sizeof *ecdsa);
+ ecdsa_t *ecdsa = xzalloc(sizeof(*ecdsa));
len = b64decode(p, ecdsa->public, len);
if(len != 32) {
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid format of public key! len = %d", len);
char *ecdsa_get_base64_public_key(ecdsa_t *ecdsa) {
char *base64 = xmalloc(44);
- b64encode(ecdsa->public, base64, sizeof ecdsa->public);
+ b64encode(ecdsa->public, base64, sizeof(ecdsa->public));
return base64;
}
bool data = false;
size_t typelen = strlen(type);
- while(fgets(line, sizeof line, fp)) {
+ while(fgets(line, sizeof(line), fp)) {
if(!data) {
if(strncmp(line, "-----BEGIN ", 11))
continue;
}
ecdsa_t *ecdsa_read_pem_public_key(FILE *fp) {
- ecdsa_t *ecdsa = xzalloc(sizeof *ecdsa);
- if(read_pem(fp, "ED25519 PUBLIC KEY", ecdsa->public, sizeof ecdsa->public))
+ ecdsa_t *ecdsa = xzalloc(sizeof(*ecdsa));
+ if(read_pem(fp, "ED25519 PUBLIC KEY", ecdsa->public, sizeof(ecdsa->public)))
return ecdsa;
free(ecdsa);
return 0;
}
ecdsa_t *ecdsa_read_pem_private_key(FILE *fp) {
- ecdsa_t *ecdsa = xmalloc(sizeof *ecdsa);
- if(read_pem(fp, "ED25519 PRIVATE KEY", ecdsa->private, sizeof *ecdsa))
+ ecdsa_t *ecdsa = xmalloc(sizeof(*ecdsa));
+ if(read_pem(fp, "ED25519 PRIVATE KEY", ecdsa->private, sizeof(*ecdsa)))
return ecdsa;
free(ecdsa);
return 0;
// Generate ECDSA key
ecdsa_t *ecdsa_generate(void) {
- ecdsa_t *ecdsa = xzalloc(sizeof *ecdsa);
+ ecdsa_t *ecdsa = xzalloc(sizeof(*ecdsa));
uint8_t seed[32];
- randomize(seed, sizeof seed);
+ randomize(seed, sizeof(seed));
ed25519_create_keypair(ecdsa->public, ecdsa->private, seed);
return ecdsa;
}
bool ecdsa_write_pem_public_key(ecdsa_t *ecdsa, FILE *fp) {
- return write_pem(fp, "ED25519 PUBLIC KEY", ecdsa->public, sizeof ecdsa->public);
+ return write_pem(fp, "ED25519 PUBLIC KEY", ecdsa->public, sizeof(ecdsa->public));
}
bool ecdsa_write_pem_private_key(ecdsa_t *ecdsa, FILE *fp) {
- return write_pem(fp, "ED25519 PRIVATE KEY", ecdsa->private, sizeof *ecdsa);
+ return write_pem(fp, "ED25519 PRIVATE KEY", ecdsa->private, sizeof(*ecdsa));
}
while(running) {
struct timeval diff;
struct timeval *tv = get_time_remaining(&diff);
- memcpy(&readable, &readfds, sizeof readable);
- memcpy(&writable, &writefds, sizeof writable);
+ memcpy(&readable, &readfds, sizeof(readable));
+ memcpy(&writable, &writefds, sizeof(writable));
int fds = 0;
again:
fprintf(stderr, "Fix y/n? ");
char buf[1024];
- if(!fgets(buf, sizeof buf, stdin)) {
+ if(!fgets(buf, sizeof(buf), stdin)) {
tty = false;
return false;
}
bool skip = false;
const int maxvariables = 50;
int count[maxvariables];
- memset(count, 0, sizeof count);
+ memset(count, 0, sizeof(count));
- while(fgets(line, sizeof line, f)) {
+ while(fgets(line, sizeof(line), f)) {
if(skip) {
if(!strncmp(line, "-----END", 8))
skip = false;
#ifndef DISABLE_LEGACY
rsa_t *rsa_priv = NULL;
- snprintf(fname, sizeof fname, "%s/rsa_key.priv", confbase);
+ snprintf(fname, sizeof(fname), "%s/rsa_key.priv", confbase);
if(stat(fname, &st)) {
if(errno != ENOENT) {
#endif
ecdsa_t *ecdsa_priv = NULL;
- snprintf(fname, sizeof fname, "%s/ed25519_key.priv", confbase);
+ snprintf(fname, sizeof(fname), "%s/ed25519_key.priv", confbase);
if(stat(fname, &st)) {
if(errno != ENOENT) {
// Check for public keys.
// TODO: use RSAPublicKeyFile variable if present.
- snprintf(fname, sizeof fname, "%s/hosts/%s", confbase, name);
+ snprintf(fname, sizeof(fname), "%s/hosts/%s", confbase, name);
if(access(fname, R_OK))
fprintf(stderr, "WARNING: cannot read %s\n", fname);
return 1;
}
char buf1[len], buf2[len], buf3[len];
- randomize(buf1, sizeof buf1);
+ randomize(buf1, sizeof(buf1));
buf1[0] &= 0x7f;
- memset(buf2, 0, sizeof buf2);
- memset(buf3, 0, sizeof buf2);
- if(!rsa_public_encrypt(rsa_pub, buf1, sizeof buf1, buf2)) {
+ memset(buf2, 0, sizeof(buf2));
+ memset(buf3, 0, sizeof(buf2));
+ if(!rsa_public_encrypt(rsa_pub, buf1, sizeof(buf1), buf2)) {
fprintf(stderr, "ERROR: public RSA key does not work.\n");
return 1;
}
- if(!rsa_private_decrypt(rsa_priv, buf2, sizeof buf2, buf3)) {
+ if(!rsa_private_decrypt(rsa_priv, buf2, sizeof(buf2), buf3)) {
fprintf(stderr, "ERROR: private RSA key does not work.\n");
return 1;
}
- if(memcmp(buf1, buf3, sizeof buf1)) {
+ if(memcmp(buf1, buf3, sizeof(buf1))) {
fprintf(stderr, "ERROR: public and private RSA keys do not match.\n");
return 1;
}
if(strtailcmp(ent->d_name, "-up") && strtailcmp(ent->d_name, "-down"))
continue;
- strncpy(fname, ent->d_name, sizeof fname);
+ strncpy(fname, ent->d_name, sizeof(fname));
char *dash = strrchr(fname, '-');
if(!dash)
continue;
continue;
}
- snprintf(fname, sizeof fname, "%s" SLASH "%s", confbase, ent->d_name);
+ snprintf(fname, sizeof(fname), "%s" SLASH "%s", confbase, ent->d_name);
if(access(fname, R_OK | X_OK)) {
if(errno != EACCES) {
fprintf(stderr, "ERROR: cannot access %s: %s\n", fname, strerror(errno));
}
closedir(dir);
- snprintf(dname, sizeof dname, "%s" SLASH "hosts", confbase);
+ snprintf(dname, sizeof(dname), "%s" SLASH "hosts", confbase);
dir = opendir(dname);
if(!dir) {
fprintf(stderr, "ERROR: cannot read directory %s: %s\n", dname, strerror(errno));
if(strtailcmp(ent->d_name, "-up") && strtailcmp(ent->d_name, "-down"))
continue;
- strncpy(fname, ent->d_name, sizeof fname);
+ strncpy(fname, ent->d_name, sizeof(fname));
char *dash = strrchr(fname, '-');
if(!dash)
continue;
*dash = 0;
- snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, ent->d_name);
+ snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, ent->d_name);
if(access(fname, R_OK | X_OK)) {
if(errno != EACCES) {
fprintf(stderr, "ERROR: cannot access %s: %s\n", fname, strerror(errno));
if(!check_id(ent->d_name))
continue;
- snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, ent->d_name);
+ snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, ent->d_name);
check_conffile(fname, false);
}
closedir(dir);
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;
// opad
memxor(tmp, 0x36 ^ 0x5c, blklen);
- if(sha512(tmp, sizeof tmp, out) != 0)
+ if(sha512(tmp, sizeof(tmp), out) != 0)
return false;
return true;
while(outlen > 0) {
/* Inner HMAC */
- if(!hmac_sha512(secret, secretlen, data, sizeof data, data))
+ if(!hmac_sha512(secret, secretlen, data, sizeof(data), data))
return false;
/* Outer HMAC */
if(outlen >= mdlen) {
- if(!hmac_sha512(secret, secretlen, data, sizeof data, out))
+ if(!hmac_sha512(secret, secretlen, data, sizeof(data), out))
return false;
out += mdlen;
outlen -= mdlen;
} else {
- if(!hmac_sha512(secret, secretlen, data, sizeof data, hash))
+ if(!hmac_sha512(secret, secretlen, data, sizeof(data), hash))
return false;
memcpy(out, hash, outlen);
out += outlen;
size_t i, j = 0;
while(!feof(fp)) {
- if(!fgets(line, sizeof line, fp))
+ if(!fgets(line, sizeof(line), fp))
return false;
if(!decode && !strncmp(line, "-----BEGIN ", 11)) {
uint8_t derbuf[8096], *derp = derbuf;
size_t derlen;
- if(!pem_decode(fp, "RSA PUBLIC KEY", derbuf, sizeof derbuf, &derlen)) {
+ if(!pem_decode(fp, "RSA PUBLIC KEY", derbuf, sizeof(derbuf), &derlen)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read RSA public key: %s", strerror(errno));
return NULL;
}
uint8_t derbuf[8096], *derp = derbuf;
size_t derlen;
- if(!pem_decode(fp, "RSA PRIVATE KEY", derbuf, sizeof derbuf, &derlen)) {
+ if(!pem_decode(fp, "RSA PRIVATE KEY", derbuf, sizeof(derbuf), &derlen)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read RSA private key: %s", strerror(errno));
return NULL;
}
static bool ber_write_mpi(uint8_t **p, size_t *buflen, gcry_mpi_t mpi) {
uint8_t tmpbuf[1024];
- size_t tmplen = sizeof tmpbuf;
+ size_t tmplen = sizeof(tmpbuf);
gcry_error_t err;
err = gcry_mpi_aprint(GCRYMPI_FMT_USG, &tmpbuf, &tmplen, mpi);
uint8_t derbuf2[8096];
uint8_t *derp1 = derbuf1;
uint8_t *derp2 = derbuf2;
- size_t derlen1 = sizeof derbuf1;
- size_t derlen2 = sizeof derbuf2;
+ size_t derlen1 = sizeof(derbuf1);
+ size_t derlen2 = sizeof(derbuf2);
if(!ber_write_mpi(&derp1, &derlen1, &rsa->n)
|| !ber_write_mpi(&derp1, &derlen1, &rsa->e)
uint8_t derbuf2[8096];
uint8_t *derp1 = derbuf1;
uint8_t *derp2 = derbuf2;
- size_t derlen1 = sizeof derbuf1;
- size_t derlen2 = sizeof derbuf2;
+ size_t derlen1 = sizeof(derbuf1);
+ size_t derlen2 = sizeof(derbuf2);
if(!ber_write_mpi(&derp1, &derlen1, &bits)
|| ber_write_mpi(&derp1, &derlen1, &rsa->n) // modulus
if(!n->status.reachable) {
update_node_udp(n, NULL);
- memset(&n->status, 0, sizeof n->status);
+ memset(&n->status, 0, sizeof(n->status));
n->options = 0;
} else if(n->connection) {
// Speed up UDP probing by sending our key.
/* (De)allocation */
hash_t *hash_alloc(size_t n, size_t size) {
- hash_t *hash = xzalloc(sizeof *hash);
+ hash_t *hash = xzalloc(sizeof(*hash));
hash->n = n;
hash->size = size;
hash->keys = xzalloc(hash->n * hash->size);
- hash->values = xzalloc(hash->n * sizeof *hash->values);
+ hash->values = xzalloc(hash->n * sizeof(*hash->values));
return hash;
}
/* Utility functions */
void hash_clear(hash_t *hash) {
- memset(hash->values, 0, hash->n * sizeof *hash->values);
+ memset(hash->values, 0, hash->n * sizeof(*hash->values));
}
void hash_resize(hash_t *hash, size_t n) {
hash->keys = xrealloc(hash->keys, n * hash->size);
- hash->values = xrealloc(hash->values, n * sizeof *hash->values);
+ hash->values = xrealloc(hash->values, n * sizeof(*hash->values));
if(n > hash->n) {
memset(hash->keys + hash->n * hash->size, 0, (n - hash->n) * hash->size);
- memset(hash->values + hash->n, 0, (n - hash->n) * sizeof *hash->values);
+ memset(hash->values + hash->n, 0, (n - hash->n) * sizeof(*hash->values));
}
}
void ifconfig_address(FILE *out, const char *value) {
subnet_t address = {};
char address_str[MAXNETSTR];
- if(!str2net(&address, value) || !net2str(address_str, sizeof address_str, &address)) {
+ if(!str2net(&address, value) || !net2str(address_str, sizeof(address_str), &address)) {
fprintf(stderr, "Could not parse address in Ifconfig statement\n");
return;
}
char *sep = strchr(value, ' ');
if(sep)
*sep++ = 0;
- if(!str2net(&subnet, value) || !net2str(subnet_str, sizeof subnet_str, &subnet) || subnet.type == SUBNET_MAC) {
+ if(!str2net(&subnet, value) || !net2str(subnet_str, sizeof(subnet_str), &subnet) || subnet.type == SUBNET_MAC) {
fprintf(stderr, "Could not parse subnet in Route statement\n");
return;
}
if(sep) {
- if(!str2net(&gateway, sep) || !net2str(gateway_str, sizeof gateway_str, &gateway) || gateway.type != subnet.type) {
+ if(!str2net(&gateway, sep) || !net2str(gateway_str, sizeof(gateway_str), &gateway) || gateway.type != subnet.type) {
fprintf(stderr, "Could not parse gateway in Route statement\n");
return;
}
fprintf(stderr, "Route requested but no Ifconfig\n");
return;
}
- net2str(gateway_str, sizeof gateway_str, &ipv4);
+ net2str(gateway_str, sizeof(gateway_str), &ipv4);
break;
case SUBNET_IPV6:
if(!ipv6.type) {
fprintf(stderr, "Route requested but no Ifconfig\n");
return;
}
- net2str(gateway_str, sizeof gateway_str, &ipv6);
+ net2str(gateway_str, sizeof(gateway_str), &ipv6);
break;
default: return;
}
node_status_t status;
long int last_state_change;
- while(recvline(fd, line, sizeof line)) {
+ while(recvline(fd, line, sizeof(line))) {
int n = sscanf(line, "%d %d %4095s %4095s %4095s port %4095s %d %d %d %d %x %"PRIx32" %4095s %4095s %d %hd %hd %hd %ld", &code, &req, node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_union.raw, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change);
if(n == 2)
return 1;
}
- while(recvline(fd, line, sizeof line)) {
+ while(recvline(fd, line, sizeof(line))) {
if(sscanf(line, "%d %d %4095s", &code, &req, node) == 2)
break;
}
time_t lsc_time = last_state_change;
if(last_state_change)
- strftime(timestr, sizeof timestr, "%Y-%m-%d %H:%M:%S", localtime(&lsc_time));
+ strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", localtime(&lsc_time));
status = status_union.bits;
// List edges
printf("Edges: ");
sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_EDGES, item);
- while(recvline(fd, line, sizeof line)) {
+ while(recvline(fd, line, sizeof(line))) {
int n = sscanf(line, "%d %d %4095s %4095s", &code, &req, from, to);
if(n == 2)
break;
// List subnets
printf("Subnets: ");
sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_SUBNETS, item);
- while(recvline(fd, line, sizeof line)) {
+ while(recvline(fd, line, sizeof(line))) {
int n = sscanf(line, "%d %d %4095s %4095s", &code, &req, subnet, from);
if(n == 2)
break;
int code, req;
sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_SUBNETS, item);
- while(recvline(fd, line, sizeof line)) {
+ while(recvline(fd, line, sizeof(line))) {
int n = sscanf(line, "%d %d %4095s %4095s", &code, &req, netstr, owner);
if(n == 2)
break;
} else {
if(find.net.ipv4.prefixlength != subnet.net.ipv4.prefixlength)
continue;
- if(memcmp(&find.net.ipv4.address, &subnet.net.ipv4.address, sizeof subnet.net.ipv4))
+ if(memcmp(&find.net.ipv4.address, &subnet.net.ipv4.address, sizeof(subnet.net.ipv4)))
continue;
}
} else if(find.type == SUBNET_IPV6) {
} else {
if(find.net.ipv6.prefixlength != subnet.net.ipv6.prefixlength)
continue;
- if(memcmp(&find.net.ipv6.address, &subnet.net.ipv6.address, sizeof subnet.net.ipv6))
+ if(memcmp(&find.net.ipv6.address, &subnet.net.ipv6.address, sizeof(subnet.net.ipv6)))
continue;
}
} if(find.type == SUBNET_MAC) {
- if(memcmp(&find.net.mac.address, &subnet.net.mac.address, sizeof subnet.net.mac))
+ if(memcmp(&find.net.mac.address, &subnet.net.mac.address, sizeof(subnet.net.mac)))
continue;
}
if(!f)
return;
- while(fgets(line, sizeof line, f)) {
+ while(fgets(line, sizeof(line), f)) {
if(!rstrip(line))
continue;
char *p = line, *q;
// Use first Address statement in own host config file
if(check_id(name)) {
- snprintf(filename, sizeof filename, "%s" SLASH "hosts" SLASH "%s", confbase, name);
+ snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", confbase, name);
scan_for_hostname(filename, &hostname, &port);
scan_for_hostname(tinc_conf, &hostname, &port);
}
}
}
if(s >= 0) {
- send(s, request, sizeof request - 1, 0);
- int len = recv(s, line, sizeof line - 1, MSG_WAITALL);
+ send(s, request, sizeof(request) - 1, 0);
+ int len = recv(s, line, sizeof(line) - 1, MSG_WAITALL);
if(len > 0) {
line[len] = 0;
if(line[len - 1] == '\n')
fprintf(stderr, " [%s]", hostname);
fprintf(stderr, ": ");
- if(!fgets(line, sizeof line, stdin)) {
+ if(!fgets(line, sizeof(line), stdin)) {
fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
free(hostname);
return NULL;
char buf[1024];
size_t len;
- while((len = fread(buf, 1, sizeof buf, in)))
+ while((len = fread(buf, 1, sizeof(buf), in)))
fwrite(buf, len, 1, out);
fclose(in);
return true;
// Ensure no host configuration file with that name exists
char filename[PATH_MAX];
- snprintf(filename, sizeof filename, "%s" SLASH "hosts" SLASH "%s", confbase, argv[1]);
+ snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", confbase, argv[1]);
if(!access(filename, F_OK)) {
fprintf(stderr, "A host config file for %s already exists!\n", argv[1]);
return 1;
bool found = false;
sendline(fd, "%d %d", CONTROL, REQ_DUMP_NODES);
- while(recvline(fd, line, sizeof line)) {
+ while(recvline(fd, line, sizeof(line))) {
char node[4096];
int code, req;
if(sscanf(line, "%d %d %4095s", &code, &req, node) != 3)
}
}
- snprintf(filename, sizeof filename, "%s" SLASH "invitations", confbase);
+ snprintf(filename, sizeof(filename), "%s" SLASH "invitations", confbase);
if(mkdir(filename, 0700) && errno != EEXIST) {
fprintf(stderr, "Could not create directory %s: %s\n", filename, strerror(errno));
return 1;
continue;
char invname[PATH_MAX];
struct stat st;
- snprintf(invname, sizeof invname, "%s" SLASH "%s", filename, ent->d_name);
+ snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name);
if(!stat(invname, &st)) {
if(deadline < st.st_mtime)
count++;
}
ecdsa_t *key;
- snprintf(filename, sizeof filename, "%s" SLASH "invitations" SLASH "ed25519_key.priv", confbase);
+ snprintf(filename, sizeof(filename), "%s" SLASH "invitations" SLASH "ed25519_key.priv", confbase);
// Remove the key if there are no outstanding invitations.
if(!count)
char buf[18 + strlen(fingerprint)];
char cookiehash[64];
memcpy(buf, cookie, 18);
- memcpy(buf + 18, fingerprint, sizeof buf - 18);
- sha512(buf, sizeof buf, cookiehash);
+ memcpy(buf + 18, fingerprint, sizeof(buf) - 18);
+ sha512(buf, sizeof(buf), cookiehash);
b64encode_urlsafe(cookiehash, cookiehash, 18);
b64encode_urlsafe(cookie, cookie, 18);
// Create a file containing the details of the invitation.
- snprintf(filename, sizeof filename, "%s" SLASH "invitations" SLASH "%s", confbase, cookiehash);
+ snprintf(filename, sizeof(filename), "%s" SLASH "invitations" SLASH "%s", confbase, cookiehash);
int ifd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
if(!ifd) {
fprintf(stderr, "Could not create invitation file %s: %s\n", filename, strerror(errno));
FILE *tc = fopen(tinc_conf, "r");
if(tc) {
char buf[1024];
- while(fgets(buf, sizeof buf, tc)) {
+ while(fgets(buf, sizeof(buf), tc)) {
if((!strncasecmp(buf, "Mode", 4) && strchr(" \t=", buf[4]))
|| (!strncasecmp(buf, "Broadcast", 9) && strchr(" \t=", buf[9]))) {
fputs(buf, f);
fprintf(f, "Name = %s\n", myname);
char filename2[PATH_MAX];
- snprintf(filename2, sizeof filename2, "%s" SLASH "hosts" SLASH "%s", confbase, myname);
+ snprintf(filename2, sizeof(filename2), "%s" SLASH "hosts" SLASH "%s", confbase, myname);
fcopy(f, filename2);
fclose(f);
static char line[1024];
const char *end = strchr(*data, '\n');
size_t len = end ? end - *data : strlen(*data);
- if(len >= sizeof line) {
+ if(len >= sizeof(line)) {
fprintf(stderr, "Maximum line length exceeded!\n");
return NULL;
}
if(!e)
return xstrdup(p);
- if(e - p >= sizeof value) {
+ if(e - p >= sizeof(value)) {
fprintf(stderr, "Maximum line length exceeded!\n");
return NULL;
}
// Generate a random netname, ask for a better one later.
ask_netname = true;
- snprintf(temp_netname, sizeof temp_netname, "join_%x", rand());
+ snprintf(temp_netname, sizeof(temp_netname), "join_%x", rand());
netname = temp_netname;
goto make_names;
}
fprintf(f, "Name = %s\n", name);
char filename[PATH_MAX];
- snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, name);
+ snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name);
FILE *fh = fopen(filename, "w");
if(!fh) {
fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
return false;
}
- snprintf(filename, sizeof filename, "%s" SLASH "invitation-data", confbase);
+ snprintf(filename, sizeof(filename), "%s" SLASH "invitation-data", confbase);
FILE *finv = fopen(filename, "w");
if(!finv || fwrite(data, datalen, 1, finv) != 1) {
fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
}
fclose(finv);
- snprintf(filename, sizeof filename, "%s" SLASH "tinc-up.invitation", confbase);
+ snprintf(filename, sizeof(filename), "%s" SLASH "tinc-up.invitation", confbase);
FILE *fup = fopen(filename, "w");
if(!fup) {
fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
return false;
}
- snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, value);
+ snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, value);
f = fopen(filename, "w");
if(!f) {
if(!b64key)
return false;
- snprintf(filename, sizeof filename, "%s" SLASH "ed25519_key.priv", confbase);
+ snprintf(filename, sizeof(filename), "%s" SLASH "ed25519_key.priv", confbase);
f = fopenmask(filename, "w", 0600);
if(!f)
return false;
#ifndef DISABLE_LEGACY
rsa_t *rsa = rsa_generate(2048, 0x1001);
- snprintf(filename, sizeof filename, "%s" SLASH "rsa_key.priv", confbase);
+ snprintf(filename, sizeof(filename), "%s" SLASH "rsa_key.priv", confbase);
f = fopenmask(filename, "w", 0600);
if(!f || !rsa_write_pem_private_key(rsa, f)) {
ask_netname:
if(ask_netname && tty) {
fprintf(stderr, "Enter a new netname: ");
- if(!fgets(line, sizeof line, stdin)) {
+ if(!fgets(line, sizeof(line), stdin)) {
fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
return false;
}
line[strlen(line) - 1] = 0;
char newbase[PATH_MAX];
- snprintf(newbase, sizeof newbase, CONFDIR SLASH "tinc" SLASH "%s", line);
+ snprintf(newbase, sizeof(newbase), CONFDIR SLASH "tinc" SLASH "%s", line);
if(rename(confbase, newbase)) {
fprintf(stderr, "Error trying to rename %s to %s: %s\n", confbase, newbase, strerror(errno));
goto ask_netname;
}
char filename2[PATH_MAX];
- snprintf(filename, sizeof filename, "%s" SLASH "tinc-up.invitation", confbase);
- snprintf(filename2, sizeof filename2, "%s" SLASH "tinc-up", confbase);
+ snprintf(filename, sizeof(filename), "%s" SLASH "tinc-up.invitation", confbase);
+ snprintf(filename2, sizeof(filename2), "%s" SLASH "tinc-up", confbase);
if(valid_tinc_up) {
if(tty) {
fprintf(stderr, "\nPlease review the following tinc-up script:\n\n");
char buf[MAXSIZE];
- while(fgets(buf, sizeof buf, fup))
+ while(fgets(buf, sizeof(buf), fup))
fputs(buf, stderr);
fclose(fup);
static bool invitation_receive(void *handle, uint8_t type, const void *msg, uint16_t len) {
switch(type) {
case SPTPS_HANDSHAKE:
- return sptps_send_record(&sptps, 0, cookie, sizeof cookie);
+ return sptps_send_record(&sptps, 0, cookie, sizeof(cookie));
case 0:
data = xrealloc(data, datalen + len + 1);
if(tty)
fprintf(stderr, "Enter invitation URL: ");
errno = EPIPE;
- if(!fgets(line, sizeof line, stdin)) {
+ if(!fgets(line, sizeof(line), stdin)) {
fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
return false;
}
fprintf(stderr, "Connected to %s port %s...\n", address, port);
// Tell him we have an invitation, and give him our throw-away key.
- int len = snprintf(line, sizeof line, "0 ?%s %d.%d\n", b64key, PROT_MAJOR, PROT_MINOR);
- if(len <= 0 || len >= sizeof line)
+ int len = snprintf(line, sizeof(line), "0 ?%s %d.%d\n", b64key, PROT_MAJOR, PROT_MINOR);
+ if(len <= 0 || len >= sizeof(line))
abort();
if(!sendline(sock, "0 ?%s %d.%d", b64key, PROT_MAJOR, 1)) {
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;
if(!sptps_receive_data(&sptps, buffer, blen))
return 1;
- while((len = recv(sock, line, sizeof line, 0))) {
+ while((len = recv(sock, line, sizeof(line), 0))) {
if(len < 0) {
if(errno == EINTR)
continue;
if(!now.tv_sec)
gettimeofday(&now, NULL);
time_t now_sec = now.tv_sec;
- strftime(timestr, sizeof timestr, "%Y-%m-%d %H:%M:%S", localtime(&now_sec));
+ strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", localtime(&now_sec));
fprintf(logfile, "%s %s[%ld]: %s\n", timestr, logident, (long)logpid, message);
fflush(logfile);
break;
char message[1024] = "";
va_start(ap, format);
- int len = vsnprintf(message, sizeof message, format, ap);
- message[sizeof message - 1] = 0;
+ int len = vsnprintf(message, sizeof(message), format, ap);
+ message[sizeof(message) - 1] = 0;
va_end(ap);
- if(len > 0 && len < sizeof message - 1 && message[len - 1] == '\n')
+ if(len > 0 && len < sizeof(message) - 1 && message[len - 1] == '\n')
message[len - 1] = 0;
real_logger(level, priority, message);
static void sptps_logger(sptps_t *s, int s_errno, const char *format, va_list ap) {
char message[1024];
- size_t msglen = sizeof message;
+ size_t msglen = sizeof(message);
int len = vsnprintf(message, msglen, format, ap);
- message[sizeof message - 1] = 0;
- if(len > 0 && len < sizeof message - 1) {
+ message[sizeof(message) - 1] = 0;
+ if(len > 0 && len < sizeof(message) - 1) {
if(message[len - 1] == '\n')
message[--len] = 0;
// but both types have the name and hostname fields at the same offsets.
connection_t *c = s->handle;
if(c)
- snprintf(message + len, sizeof message - len, " from %s (%s)", c->name, c->hostname);
+ snprintf(message + len, sizeof(message) - len, " from %s (%s)", c->name, c->hostname);
}
real_logger(DEBUG_ALWAYS, LOG_ERR, message);
buffer_compact(&c->inbuf, MAXBUFSIZE);
- if(sizeof inbuf <= c->inbuf.len) {
+ if(sizeof(inbuf) <= c->inbuf.len) {
logger(DEBUG_ALWAYS, LOG_ERR, "Input buffer full for %s (%s)", c->name, c->hostname);
return false;
}
- inlen = recv(c->socket, inbuf, sizeof inbuf - c->inbuf.len, 0);
+ inlen = recv(c->socket, inbuf, sizeof(inbuf) - c->inbuf.len, 0);
if(inlen <= 0) {
if(!inlen || !sockerrno) {
}
for (i = 0; ; i++) {
- len = sizeof adapterid;
+ len = sizeof(adapterid);
if(RegEnumKeyEx(key, i, adapterid, &len, 0, 0, 0, NULL))
break;
/* Find out more about this adapter */
- snprintf(regpath, sizeof regpath, "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, adapterid);
+ snprintf(regpath, sizeof(regpath), "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, adapterid);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &key2))
continue;
- len = sizeof adaptername;
+ len = sizeof(adaptername);
err = RegQueryValueEx(key2, "Name", 0, 0, (LPBYTE)adaptername, &len);
RegCloseKey(key2);
continue;
}
- snprintf(tapname, sizeof tapname, USERMODEDEVICEDIR "%s" TAPSUFFIX, adapterid);
+ snprintf(tapname, sizeof(tapname), USERMODEDEVICEDIR "%s" TAPSUFFIX, adapterid);
device_handle = CreateFile(tapname, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0);
if(device_handle != INVALID_HANDLE_VALUE) {
found = true;
/* Try to open the corresponding tap device */
if(device_handle == INVALID_HANDLE_VALUE) {
- snprintf(tapname, sizeof tapname, USERMODEDEVICEDIR "%s" TAPSUFFIX, device);
+ snprintf(tapname, sizeof(tapname), USERMODEDEVICEDIR "%s" TAPSUFFIX, device);
device_handle = CreateFile(tapname, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0);
}
{
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,
/* Copy the packet, since the write operation might still be ongoing after we return. */
- memcpy(&device_write_packet, packet, sizeof *packet);
+ memcpy(&device_write_packet, packet, sizeof(*packet));
if(WriteFile(device_handle, DATA(&device_write_packet), device_write_packet.len, &outlen, &device_write_overlapped))
device_write_packet.len = 0;
#endif
static const int one = 1;
- setsockopt(device_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof one);
+ setsockopt(device_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one));
if(bind(device_fd, ai->ai_addr, ai->ai_addrlen)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Can't bind to %s %s: %s", host, port, sockstrerror(sockerrno));
case AF_INET: {
struct ip_mreq mreq;
struct sockaddr_in in;
- memcpy(&in, ai->ai_addr, sizeof in);
+ memcpy(&in, ai->ai_addr, sizeof(in));
mreq.imr_multiaddr.s_addr = in.sin_addr.s_addr;
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
- if(setsockopt(device_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof mreq)) {
+ if(setsockopt(device_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq))) {
logger(DEBUG_ALWAYS, LOG_ERR, "Cannot join multicast group %s %s: %s", host, port, sockstrerror(sockerrno));
goto error;
}
#ifdef IP_MULTICAST_LOOP
- setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof one);
+ setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof(one));
#endif
#ifdef IP_MULTICAST_TTL
- setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_TTL, (void *)&ttl, sizeof ttl);
+ setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_TTL, (void *)&ttl, sizeof(ttl));
#endif
} break;
#endif
case AF_INET6: {
struct ipv6_mreq mreq;
struct sockaddr_in6 in6;
- memcpy(&in6, ai->ai_addr, sizeof in6);
- memcpy(&mreq.ipv6mr_multiaddr, &in6.sin6_addr, sizeof mreq.ipv6mr_multiaddr);
+ memcpy(&in6, ai->ai_addr, sizeof(in6));
+ memcpy(&mreq.ipv6mr_multiaddr, &in6.sin6_addr, sizeof(mreq.ipv6mr_multiaddr));
mreq.ipv6mr_interface = in6.sin6_scope_id;
- if(setsockopt(device_fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof mreq)) {
+ if(setsockopt(device_fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof(mreq))) {
logger(DEBUG_ALWAYS, LOG_ERR, "Cannot join multicast group %s %s: %s", host, port, sockstrerror(sockerrno));
goto error;
}
#ifdef IPV6_MULTICAST_LOOP
- setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof one);
+ setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof(one));
#endif
#ifdef IPV6_MULTICAST_HOPS
- setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (void *)&ttl, sizeof ttl);
+ setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (void *)&ttl, sizeof(ttl));
#endif
} break;
#endif
return false;
}
- if(!memcmp(&ignore_src, DATA(packet) + 6, sizeof ignore_src)) {
+ if(!memcmp(&ignore_src, DATA(packet) + 6, sizeof(ignore_src))) {
logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Ignoring loopback packet of %d bytes from %s", lenin, device_info);
return false;
}
return false;
}
- memcpy(&ignore_src, DATA(packet) + 6, sizeof ignore_src);
+ memcpy(&ignore_src, DATA(packet) + 6, sizeof(ignore_src));
return true;
}
#ifdef HAVE_MINGW
HKEY key;
char installdir[1024] = "";
- DWORD len = sizeof installdir;
+ DWORD len = sizeof(installdir);
#endif
confbase_given = confbase;
fallback = true;
} else {
char fname[PATH_MAX];
- snprintf(fname, sizeof fname, LOCALSTATEDIR SLASH "run" SLASH "%s.pid", identname);
+ snprintf(fname, sizeof(fname), LOCALSTATEDIR SLASH "run" SLASH "%s.pid", identname);
if(access(fname, R_OK)) {
- snprintf(fname, sizeof fname, "%s" SLASH "pid", confbase);
+ snprintf(fname, sizeof(fname), "%s" SLASH "pid", confbase);
if(!access(fname, R_OK))
fallback = true;
}
read_config_options(config_tree, NULL);
- snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, myself->name);
+ snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, myself->name);
read_config_file(config_tree, fname);
/* Parse some options that are allowed to be changed while tinc is running */
if(c->status.control)
continue;
- snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
+ snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
struct stat s;
if(stat(fname, &s) || s.st_mtime > last_config_check) {
logger(DEBUG_CONNECTIONS, LOG_INFO, "Host config file of %s has been changed", c->name);
/* Check the sequence number */
seqno_t seqno;
- memcpy(&seqno, SEQNO(inpkt), sizeof seqno);
+ memcpy(&seqno, SEQNO(inpkt), sizeof(seqno));
seqno = ntohl(seqno);
- inpkt->len -= sizeof seqno;
+ inpkt->len -= sizeof(seqno);
if(replaywin) {
if(seqno != n->received_seqno + 1) {
vpn_packet_t outpkt;
outpkt.offset = DEFAULT_PACKET_OFFSET;
- if(len > sizeof outpkt.data - outpkt.offset)
+ if(len > sizeof(outpkt.data) - outpkt.offset)
return;
outpkt.len = len;
/* Add sequence number */
seqno_t seqno = htonl(++(n->sent_seqno));
- memcpy(SEQNO(inpkt), &seqno, sizeof seqno);
- inpkt->len += sizeof seqno;
+ memcpy(SEQNO(inpkt), &seqno, sizeof(seqno));
+ inpkt->len += sizeof(seqno);
/* Encrypt the packet */
#if defined(IPPROTO_IP) && defined(IP_TOS)
case AF_INET:
logger(DEBUG_TRAFFIC, LOG_DEBUG, "Setting IPv4 outgoing packet priority to %d", origpriority);
- if(setsockopt(listen_socket[sock].udp.fd, IPPROTO_IP, IP_TOS, (void *)&origpriority, sizeof origpriority)) /* SO_PRIORITY doesn't seem to work */
+ if(setsockopt(listen_socket[sock].udp.fd, IPPROTO_IP, IP_TOS, (void *)&origpriority, sizeof(origpriority))) /* SO_PRIORITY doesn't seem to work */
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setsockopt", sockstrerror(sockerrno));
break;
#endif
#if defined(IPPROTO_IPV6) & defined(IPV6_TCLASS)
case AF_INET6:
logger(DEBUG_TRAFFIC, LOG_DEBUG, "Setting IPv6 outgoing packet priority to %d", origpriority);
- if(setsockopt(listen_socket[sock].udp.fd, IPPROTO_IPV6, IPV6_TCLASS, (void *)&origpriority, sizeof origpriority)) /* SO_PRIORITY doesn't seem to work */
+ if(setsockopt(listen_socket[sock].udp.fd, IPPROTO_IPV6, IPV6_TCLASS, (void *)&origpriority, sizeof(origpriority))) /* SO_PRIORITY doesn't seem to work */
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setsockopt", sockstrerror(sockerrno));
break;
#endif
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_ptr = buf;
- memcpy(buf_ptr, &to->id, sizeof to->id); buf_ptr += sizeof to->id;
- memcpy(buf_ptr, &from->id, sizeof from->id); buf_ptr += 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;
+ memcpy(buf_ptr, &from->id, 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);
+ return send_sptps_tcppacket(to->nexthop->connection, buf, sizeof(buf));
}
char buf[len * 4 / 3 + 5];
}
size_t overhead = 0;
- if(relay_supported) overhead += sizeof to->id + sizeof from->id;
+ if(relay_supported) overhead += sizeof(to->id) + sizeof from->id;
char buf[len + overhead]; char* buf_ptr = buf;
if(relay_supported) {
if(direct) {
/* Inform the recipient that this packet was sent directly. */
node_id_t nullid = {};
- memcpy(buf_ptr, &nullid, sizeof nullid); buf_ptr += sizeof nullid;
+ memcpy(buf_ptr, &nullid, sizeof(nullid)); buf_ptr += sizeof nullid;
} else {
- memcpy(buf_ptr, &to->id, sizeof to->id); buf_ptr += sizeof to->id;
+ memcpy(buf_ptr, &to->id, sizeof(to->id)); buf_ptr += sizeof to->id;
}
- memcpy(buf_ptr, &from->id, sizeof from->id); buf_ptr += sizeof from->id;
+ memcpy(buf_ptr, &from->id, sizeof(from->id)); buf_ptr += sizeof from->id;
}
/* TODO: if this copy turns out to be a performance concern, change sptps_send_record() to add some "pre-padding" to the buffer and use that instead */
}
int ip_mtu;
- socklen_t ip_mtu_len = sizeof ip_mtu;
+ socklen_t ip_mtu_len = sizeof(ip_mtu);
if(getsockopt(sock, IPPROTO_IP, IP_MTU, &ip_mtu, &ip_mtu_len)) {
logger(DEBUG_TRAFFIC, LOG_ERR, "getsockopt(IP_MTU) on %s (%s) failed: %s", n->name, n->hostname, sockstrerror(sockerrno));
close(sock);
// It might be from a 1.1 node, which might have a source ID in the packet.
pkt->offset = 2 * sizeof(node_id_t);
from = lookup_node_id(SRCID(pkt));
- if(from && !memcmp(DSTID(pkt), &nullid, sizeof nullid) && from->status.sptps) {
+ if(from && !memcmp(DSTID(pkt), &nullid, sizeof(nullid)) && from->status.sptps) {
if(sptps_verify_datagram(&from->sptps, DATA(pkt), pkt->len - 2 * sizeof(node_id_t)))
n = from;
else
pkt->len -= pkt->offset;
}
- if(!memcmp(DSTID(pkt), &nullid, sizeof nullid) || !relay_enabled) {
+ if(!memcmp(DSTID(pkt), &nullid, sizeof(nullid)) || !relay_enabled) {
direct = true;
from = n;
to = myself;
msg[i].msg_hdr = (struct msghdr){
.msg_name = &addr[i].sa,
- .msg_namelen = sizeof addr[i],
+ .msg_namelen = sizeof(addr)[i],
.msg_iov = &iov[i],
.msg_iovlen = 1,
};
#else
vpn_packet_t pkt;
sockaddr_t addr = {};
- socklen_t addrlen = sizeof addr;
+ socklen_t addrlen = sizeof(addr);
pkt.offset = 0;
int len = recvfrom(ls->udp.fd, (void *)DATA(&pkt), MAXSIZE, 0, &addr.sa, &addrlen);
invitation_key = NULL;
}
- snprintf(fname, sizeof fname, "%s" SLASH "invitations" SLASH "ed25519_key.priv", confbase);
+ snprintf(fname, sizeof(fname), "%s" SLASH "invitations" SLASH "ed25519_key.priv", confbase);
fp = fopen(fname, "r");
struct dirent *ent;
char dname[PATH_MAX];
- snprintf(dname, sizeof dname, "%s" SLASH "hosts", confbase);
+ snprintf(dname, sizeof(dname), "%s" SLASH "hosts", confbase);
dir = opendir(dname);
if(!dir) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", dname, strerror(errno));
}
for(int i = 0; i < listen_sockets; i++) {
- salen = sizeof sa;
+ salen = sizeof(sa);
if(getsockname(i + 3, &sa.sa, &salen) < 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not get address of listen fd %d: %s", i + 3, sockstrerror(sockerrno));
return false;
if(!port_specified || atoi(myport) == 0) {
sockaddr_t sa;
- socklen_t salen = sizeof sa;
+ socklen_t salen = sizeof(sa);
if(!getsockname(listen_socket[0].udp.fd, &sa.sa, &salen)) {
free(myport);
sockaddr2str(&sa, NULL, &myport);
#if defined(IPPROTO_TCP) && defined(TCP_NODELAY)
option = 1;
- setsockopt(c->socket, IPPROTO_TCP, TCP_NODELAY, (void *)&option, sizeof option);
+ setsockopt(c->socket, IPPROTO_TCP, TCP_NODELAY, (void *)&option, sizeof(option));
#endif
#if defined(IPPROTO_IP) && defined(IP_TOS) && defined(IPTOS_LOWDELAY)
option = IPTOS_LOWDELAY;
- setsockopt(c->socket, IPPROTO_IP, IP_TOS, (void *)&option, sizeof option);
+ setsockopt(c->socket, IPPROTO_IP, IP_TOS, (void *)&option, sizeof(option));
#endif
#if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS) && defined(IPTOS_LOWDELAY)
option = IPTOS_LOWDELAY;
- setsockopt(c->socket, IPPROTO_IPV6, IPV6_TCLASS, (void *)&option, sizeof option);
+ setsockopt(c->socket, IPPROTO_IPV6, IPV6_TCLASS, (void *)&option, sizeof(option));
#endif
}
/* Optimize TCP settings */
option = 1;
- setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof option);
+ setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof(option));
#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
if(sa->sa.sa_family == AF_INET6)
- setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof option);
+ setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option));
#endif
if(get_config_string
#if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE)
struct ifreq ifr;
- memset(&ifr, 0, sizeof ifr);
+ memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ);
- if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof ifr)) {
+ if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr))) {
closesocket(nfd);
logger(DEBUG_ALWAYS, LOG_ERR, "Can't bind to interface %s: %s", iface,
sockstrerror(sockerrno));
#endif
option = 1;
- setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof option);
- setsockopt(nfd, SOL_SOCKET, SO_BROADCAST, (void *)&option, sizeof option);
+ setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof(option));
+ setsockopt(nfd, SOL_SOCKET, SO_BROADCAST, (void *)&option, sizeof(option));
if(udp_rcvbuf && setsockopt(nfd, SOL_SOCKET, SO_RCVBUF, (void *)&udp_rcvbuf, sizeof(udp_rcvbuf)))
logger(DEBUG_ALWAYS, LOG_WARNING, "Can't set UDP SO_RCVBUF to %i: %s", udp_rcvbuf, sockstrerror(sockerrno));
#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
if(sa->sa.sa_family == AF_INET6)
- setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof option);
+ setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option));
#endif
#if defined(IP_DONTFRAG) && !defined(IP_DONTFRAGMENT)
if (!socknotconn(sockerrno))
socket_error = sockerrno;
else {
- socklen_t len = sizeof socket_error;
+ socklen_t len = sizeof(socket_error);
getsockopt(c->socket, SOL_SOCKET, SO_ERROR, (void *)&socket_error, &len);
}
if (socket_error) {
#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
int option = 1;
if(c->address.sa.sa_family == AF_INET6)
- setsockopt(c->socket, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof option);
+ setsockopt(c->socket, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option));
#endif
bind_to_interface(c->socket);
continue;
oai = ai;
- ai = xzalloc(sizeof *ai);
+ ai = xzalloc(sizeof(*ai));
ai->ai_family = e->reverse->address.sa.sa_family;
ai->ai_socktype = SOCK_STREAM;
ai->ai_protocol = IPPROTO_TCP;
connection_t *c;
sockaddr_t sa;
int fd;
- socklen_t len = sizeof sa;
+ socklen_t len = sizeof(sa);
fd = accept(l->tcp.fd, &sa.sa, &len);
}
}
- memcpy(&prev_sa, &sa, sizeof sa);
+ memcpy(&prev_sa, &sa, sizeof(sa));
// Check if we get many connections from different hosts
connection_t *c;
sockaddr_t sa;
int fd;
- socklen_t len = sizeof sa;
+ socklen_t len = sizeof(sa);
fd = accept(io->fd, &sa.sa, &len);
}
if(!found) {
- outgoing_t *outgoing = xzalloc(sizeof *outgoing);
+ outgoing_t *outgoing = xzalloc(sizeof(*outgoing));
outgoing->name = name;
list_insert_tail(outgoing_list, outgoing);
setup_outgoing_connection(outgoing);
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) {
logger(DEBUG_ALWAYS, LOG_ERR, "Error while looking up hostname: %s", err == EAI_SYSTEM ? strerror(errno) : gai_strerror(err));
return strcmp(a->unknown.port, b->unknown.port);
case AF_INET:
- result = memcmp(&a->in.sin_addr, &b->in.sin_addr, sizeof a->in.sin_addr);
+ result = memcmp(&a->in.sin_addr, &b->in.sin_addr, sizeof(a->in.sin_addr));
if(result)
return result;
- return memcmp(&a->in.sin_port, &b->in.sin_port, sizeof a->in.sin_port);
+ return memcmp(&a->in.sin_port, &b->in.sin_port, sizeof(a->in.sin_port));
case AF_INET6:
- result = memcmp(&a->in6.sin6_addr, &b->in6.sin6_addr, sizeof a->in6.sin6_addr);
+ result = memcmp(&a->in6.sin6_addr, &b->in6.sin6_addr, sizeof(a->in6.sin6_addr));
if(result)
return result;
- return memcmp(&a->in6.sin6_port, &b->in6.sin6_port, sizeof a->in6.sin6_port);
+ return memcmp(&a->in6.sin6_port, &b->in6.sin6_port, sizeof(a->in6.sin6_port));
default:
logger(DEBUG_ALWAYS, LOG_ERR, "sockaddrcmp() was called with unknown address family %d, exitting!",
}
node_t *new_node(void) {
- node_t *n = xzalloc(sizeof *n);
+ node_t *n = xzalloc(sizeof(*n));
if(replaywin) n->late = xzalloc(replaywin);
n->subnet_tree = new_subnet_tree();
void node_add(node_t *n) {
unsigned char buf[64];
sha512(n->name, strlen(n->name),buf);
- memcpy(&n->id, buf, sizeof n->id);
+ memcpy(&n->id, buf, sizeof(n->id));
splay_insert(node_tree, n);
splay_insert(node_id_tree, n);
bool dump_nodes(connection_t *c) {
for splay_each(node_t, n, node_tree) {
- char id[2 * sizeof n->id + 1];
- for (size_t c = 0; c < sizeof n->id; ++c)
+ char id[2 * sizeof(n->id) + 1];
+ for (size_t c = 0; c < sizeof(n->id); ++c)
snprintf(id + 2 * c, 3, "%02x", n->id.x[c]);
- id[sizeof id - 1] = 0;
+ id[sizeof(id) - 1] = 0;
send_request(c, "%d %d %s %s %s %d %d %d %d %x %x %s %s %d %d %d %d %ld", CONTROL, REQ_DUMP_NODES,
n->name, id, n->hostname ?: "unknown port unknown",
#ifdef DISABLE_LEGACY
#else
cipher_get_nid(n->outcipher), digest_get_nid(n->outdigest), (int)digest_length(n->outdigest),
#endif
- n->outcompression, n->options, bitfield_to_int(&n->status, sizeof n->status),
+ n->outcompression, n->options, bitfield_to_int(&n->status, sizeof(n->status)),
n->nexthop ? n->nexthop->name : "-", n->via ? n->via->name ?: "-" : "-", n->distance,
n->mtu, n->minmtu, n->maxmtu, (long)n->last_state_change);
}
// opad
memxor(tmp, 0x36 ^ 0x5c, blklen);
- if(sha512(tmp, sizeof tmp, out) != 0)
+ if(sha512(tmp, sizeof(tmp), out) != 0)
return false;
return true;
while(outlen > 0) {
/* Inner HMAC */
- if(!hmac_sha512(secret, secretlen, data, sizeof data, data))
+ if(!hmac_sha512(secret, secretlen, data, sizeof(data), data))
return false;
/* Outer HMAC */
if(outlen >= mdlen) {
- if(!hmac_sha512(secret, secretlen, data, sizeof data, out))
+ if(!hmac_sha512(secret, secretlen, data, sizeof(data), out))
return false;
out += mdlen;
outlen -= mdlen;
} else {
- if(!hmac_sha512(secret, secretlen, data, sizeof data, hash))
+ if(!hmac_sha512(secret, secretlen, data, sizeof(data), hash))
return false;
memcpy(out, hash, outlen);
out += outlen;
};
static cipher_t *cipher_open(const EVP_CIPHER *evp_cipher) {
- cipher_t *cipher = xzalloc(sizeof *cipher);
+ cipher_t *cipher = xzalloc(sizeof(*cipher));
cipher->cipher = evp_cipher;
cipher->ctx = EVP_CIPHER_CTX_new();
if(!cipher->ctx)
#include "../logger.h"
static digest_t *digest_open(const EVP_MD *evp_md, int maclength) {
- digest_t *digest = xzalloc(sizeof *digest);
+ digest_t *digest = xzalloc(sizeof(*digest));
digest->digest = evp_md;
int digestlen = EVP_MD_size(digest->digest);
}
HMODULE module = GetModuleHandle(NULL);
- GetModuleFileName(module, command + 1, sizeof command - 1);
- command[sizeof command - 1] = 0;
+ GetModuleFileName(module, command + 1, sizeof(command) - 1);
+ command[sizeof(command) - 1] = 0;
- strncat(command, "\"", sizeof command - strlen(command));
+ strncat(command, "\"", sizeof(command) - strlen(command));
for(char **argp = g_argv + 1; *argp; argp++) {
char *space = strchr(*argp, ' ');
- strncat(command, " ", sizeof command - strlen(command));
+ strncat(command, " ", sizeof(command) - strlen(command));
if(space)
- strncat(command, "\"", sizeof command - strlen(command));
+ strncat(command, "\"", sizeof(command) - strlen(command));
- strncat(command, *argp, sizeof command - strlen(command));
+ strncat(command, *argp, sizeof(command) - strlen(command));
if(space)
- strncat(command, "\"", sizeof command - strlen(command));
+ strncat(command, "\"", sizeof(command) - strlen(command));
}
service = CreateService(manager, identname, identname,
input buffer anyway */
va_start(args, format);
- len = vsnprintf(request, sizeof request, format, args);
- request[sizeof request - 1] = 0;
+ len = vsnprintf(request, sizeof(request), format, args);
+ request[sizeof(request) - 1] = 0;
va_end(args);
- if(len < 0 || len > sizeof request - 1) {
+ if(len < 0 || len > sizeof(request) - 1) {
logger(DEBUG_ALWAYS, LOG_ERR, "Output buffer overflow while sending request to %s (%s)",
c->name, c->hostname);
return false;
char tmp[len + 1];
memcpy(tmp, request, len);
tmp[len] = '\n';
- broadcast_meta(from, tmp, sizeof tmp);
+ broadcast_meta(from, tmp, sizeof(tmp));
}
bool receive_request(connection_t *c, const char *request) {
logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Already seen request");
return true;
} else {
- new = xmalloc(sizeof *new);
+ new = xmalloc(sizeof(*new));
new->request = xstrdup(request);
new->firstseen = now.tv_sec;
splay_insert(past_request_tree, new);
memcpy(s4req + 4, &c->address.in.sin_addr, 4);
if(proxyuser)
memcpy(s4req + 8, proxyuser, strlen(proxyuser));
- s4req[sizeof s4req - 1] = 0;
+ s4req[sizeof(s4req) - 1] = 0;
c->tcplen = 8;
- return send_meta(c, s4req, sizeof s4req);
+ return send_meta(c, s4req, sizeof(s4req));
}
case PROXY_SOCKS5: {
int len = 3 + 6 + (c->address.sa.sa_family == AF_INET ? 4 : 16);
}
if(i > len)
abort();
- return send_meta(c, s5req, sizeof s5req);
+ return send_meta(c, s5req, sizeof(s5req));
}
case PROXY_SOCKS4A:
logger(DEBUG_ALWAYS, LOG_ERR, "Proxy type not implemented yet");
// Create a new host config file
char filename[PATH_MAX];
- snprintf(filename, sizeof filename, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
+ snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
if(!access(filename, F_OK)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Host config file for %s (%s) already exists!\n", c->name, c->hostname);
return false;
char hashbuf[18 + strlen(fingerprint)];
char cookie[64];
memcpy(hashbuf, data, 18);
- memcpy(hashbuf + 18, fingerprint, sizeof hashbuf - 18);
- sha512(hashbuf, sizeof hashbuf, cookie);
+ memcpy(hashbuf + 18, fingerprint, sizeof(hashbuf) - 18);
+ sha512(hashbuf, sizeof(hashbuf), cookie);
b64encode_urlsafe(cookie, cookie, 18);
free(fingerprint);
char filename[PATH_MAX], usedname[PATH_MAX];
- snprintf(filename, sizeof filename, "%s" SLASH "invitations" SLASH "%s", confbase, cookie);
- snprintf(usedname, sizeof usedname, "%s" SLASH "invitations" SLASH "%s.used", confbase, cookie);
+ snprintf(filename, sizeof(filename), "%s" SLASH "invitations" SLASH "%s", confbase, cookie);
+ snprintf(usedname, sizeof(usedname), "%s" SLASH "invitations" SLASH "%s.used", confbase, cookie);
// Atomically rename the invitation file
if(rename(filename, usedname)) {
// Read the new node's Name from the file
char buf[1024];
- fgets(buf, sizeof buf, f);
+ fgets(buf, sizeof(buf), f);
if(*buf)
buf[strlen(buf) - 1] = 0;
// Send the node the contents of the invitation file
rewind(f);
size_t result;
- while((result = fread(buf, 1, sizeof buf, f)))
+ while((result = fread(buf, 1, sizeof(buf), f)))
sptps_send_record(&c->sptps, 0, buf, result);
sptps_send_record(&c->sptps, 1, buf, 0);
fclose(f);
char label[25 + strlen(myself->name) + strlen(c->name)];
if(c->outgoing)
- snprintf(label, sizeof label, "tinc TCP key expansion %s %s", myself->name, c->name);
+ snprintf(label, sizeof(label), "tinc TCP key expansion %s %s", myself->name, c->name);
else
- snprintf(label, sizeof label, "tinc TCP key expansion %s %s", c->name, myself->name);
+ snprintf(label, sizeof(label), "tinc TCP key expansion %s %s", c->name, myself->name);
- return sptps_start(&c->sptps, c, c->outgoing, false, myself->connection->ecdsa, c->ecdsa, label, sizeof label, send_meta_sptps, receive_meta_sptps);
+ return sptps_start(&c->sptps, c, c->outgoing, false, myself->connection->ecdsa, c->ecdsa, label, sizeof(label), send_meta_sptps, receive_meta_sptps);
} else {
return send_metakey(c);
}
/* Convert the challenge from hexadecimal back to binary */
- int inlen = hex2bin(hexkey, enckey, sizeof enckey);
+ int inlen = hex2bin(hexkey, enckey, sizeof(enckey));
/* Check if the length of the meta key is all right */
/* Convert the challenge from hexadecimal back to binary */
- int inlen = hex2bin(buffer, buffer, sizeof buffer);
+ int inlen = hex2bin(buffer, buffer, sizeof(buffer));
/* Check if the length of the challenge is all right */
/* Convert the hash to binary format */
- int inlen = hex2bin(hishash, hishash, sizeof hishash);
+ int inlen = hex2bin(hishash, hishash, sizeof(hishash));
/* Check if the length of the hash is all right */
char pad[MAXBUFSIZE - MAXSIZE];
} zeropkt;
- memset(&zeropkt, 0, sizeof zeropkt);
+ memset(&zeropkt, 0, sizeof(zeropkt));
zeropkt.pkt.len = MAXBUFSIZE;
send_tcppacket(c, &zeropkt.pkt);
}
sockaddrcpy(&c->edge->address, &c->address);
sockaddr_setport(&c->edge->address, hisport);
sockaddr_t local_sa;
- socklen_t local_salen = sizeof local_sa;
+ socklen_t local_salen = sizeof(local_sa);
if (getsockname(c->socket, &local_sa.sa, &local_salen) < 0)
logger(DEBUG_ALWAYS, LOG_WARNING, "Could not get local socket address for connection with %s", c->name);
else {
}
char label[25 + strlen(myself->name) + strlen(to->name)];
- snprintf(label, sizeof label, "tinc UDP key expansion %s %s", myself->name, to->name);
+ snprintf(label, sizeof(label), "tinc UDP key expansion %s %s", myself->name, to->name);
sptps_stop(&to->sptps);
to->status.validkey = false;
to->status.waitingforkey = true;
to->last_req_key = now.tv_sec;
to->incompression = myself->incompression;
- return sptps_start(&to->sptps, to, true, true, myself->connection->ecdsa, to->ecdsa, label, sizeof label, send_initial_sptps_data, receive_sptps_record);
+ return sptps_start(&to->sptps, to, true, true, myself->connection->ecdsa, to->ecdsa, label, sizeof(label), send_initial_sptps_data, receive_sptps_record);
}
return send_request(to->nexthop->connection, "%d %s %s", REQ_KEY, myself->name, to->name);
}
char label[25 + strlen(from->name) + strlen(myself->name)];
- snprintf(label, sizeof label, "tinc UDP key expansion %s %s", from->name, myself->name);
+ snprintf(label, sizeof(label), "tinc UDP key expansion %s %s", from->name, myself->name);
sptps_stop(&from->sptps);
from->status.validkey = false;
from->status.waitingforkey = true;
from->last_req_key = now.tv_sec;
- sptps_start(&from->sptps, from, false, true, myself->connection->ecdsa, from->ecdsa, label, sizeof label, send_sptps_data_myself, receive_sptps_record);
+ sptps_start(&from->sptps, from, false, true, myself->connection->ecdsa, from->ecdsa, label, sizeof(label), send_sptps_data_myself, receive_sptps_record);
sptps_receive_data(&from->sptps, buf, len);
send_mtu_info(myself, from, MTU);
return true;
/* Process key */
- int keylen = hex2bin(key, key, sizeof key);
+ int keylen = hex2bin(key, key, sizeof(key));
if(keylen != (from->outcipher ? cipher_keylength(from->outcipher) : 1)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses wrong keylength!", from->name, from->hostname);
bool send_add_subnet(connection_t *c, const subnet_t *subnet) {
char netstr[MAXNETSTR];
- if(!net2str(netstr, sizeof netstr, subnet))
+ if(!net2str(netstr, sizeof(netstr), subnet))
return false;
return send_request(c, "%d %x %s %s", ADD_SUBNET, rand(), subnet->owner->name, netstr);
bool send_del_subnet(connection_t *c, const subnet_t *s) {
char netstr[MAXNETSTR];
- if(!net2str(netstr, sizeof netstr, s))
+ if(!net2str(netstr, sizeof(netstr), s))
return false;
return send_request(c, "%d %x %s %s", DEL_SUBNET, rand(), s->owner->name, netstr);
return false;
}
- memset(&ifr, 0, sizeof ifr);
+ memset(&ifr, 0, sizeof(ifr));
#ifdef FD_CLOEXEC
fcntl(device_fd, F_SETFD, FD_CLOEXEC);
return false;
}
- memset(&sa, '0', sizeof sa);
+ memset(&sa, '0', sizeof(sa));
sa.sll_family = AF_PACKET;
sa.sll_protocol = htons(ETH_P_ALL);
sa.sll_ifindex = ifr.ifr_ifindex;
- if(bind(device_fd, (struct sockaddr *) &sa, (socklen_t) sizeof sa)) {
+ if(bind(device_fd, (struct sockaddr *) &sa, (socklen_t) sizeof(sa))) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not bind %s to %s: %s", device, iface, strerror(errno));
return false;
}
static void swap_mac_addresses(vpn_packet_t *packet) {
mac_t tmp;
- memcpy(&tmp, &DATA(packet)[0], sizeof tmp);
- memcpy(&DATA(packet)[0], &DATA(packet)[6], sizeof tmp);
- memcpy(&DATA(packet)[6], &tmp, sizeof tmp);
+ memcpy(&tmp, &DATA(packet)[0], sizeof(tmp));
+ memcpy(&DATA(packet)[0], &DATA(packet)[6], sizeof(tmp));
+ memcpy(&DATA(packet)[6], &tmp, sizeof(tmp));
}
/* RFC 792 */
/* Generate checksum */
- checksum = inet_checksum(&pseudo, sizeof pseudo, ~0);
+ checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
checksum = inet_checksum(&icmp6, icmp6_size, checksum);
checksum = inet_checksum(DATA(packet) + ether_size + ip6_size + icmp6_size, ntohl(pseudo.length) - icmp6_size, checksum);
if(s->expires && s->expires < now.tv_sec) {
if(debug_level >= DEBUG_TRAFFIC) {
char netstr[MAXNETSTR];
- if(net2str(netstr, sizeof netstr, s))
+ if(net2str(netstr, sizeof(netstr), s))
logger(DEBUG_TRAFFIC, LOG_INFO, "Subnet %s expired", netstr);
}
node_t *via;
ipv4_t dest;
- memcpy(&dest, &DATA(packet)[30], sizeof dest);
+ memcpy(&dest, &DATA(packet)[30], sizeof(dest));
subnet = lookup_subnet_ipv4(&dest);
if(!subnet) {
node_t *via;
ipv6_t dest;
- memcpy(&dest, &DATA(packet)[38], sizeof dest);
+ memcpy(&dest, &DATA(packet)[38], sizeof(dest));
subnet = lookup_subnet_ipv6(&dest);
if(!subnet) {
/* Generate checksum */
- checksum = inet_checksum(&pseudo, sizeof pseudo, ~0);
+ checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
checksum = inet_checksum(&ns, ns_size, checksum);
if(has_opt) {
checksum = inet_checksum(&opt, opt_size, checksum);
/* Generate checksum */
- checksum = inet_checksum(&pseudo, sizeof pseudo, ~0);
+ checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
checksum = inet_checksum(&ns, ns_size, checksum);
if(has_opt) {
checksum = inet_checksum(&opt, opt_size, checksum);
/* Check if this is a valid ARP request */
if(ntohs(arp.arp_hrd) != ARPHRD_ETHER || ntohs(arp.arp_pro) != ETH_P_IP ||
- arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof addr || ntohs(arp.arp_op) != ARPOP_REQUEST) {
+ arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof(addr) || ntohs(arp.arp_op) != ARPOP_REQUEST) {
logger(DEBUG_TRAFFIC, LOG_WARNING, "Cannot route packet: received unknown type ARP request");
return;
}
if(!do_decrement_ttl(source, packet))
return;
- memcpy(&addr, arp.arp_tpa, sizeof addr); /* save protocol addr */
- memcpy(arp.arp_tpa, arp.arp_spa, sizeof addr); /* swap destination and source protocol address */
- memcpy(arp.arp_spa, &addr, sizeof addr); /* ... */
+ memcpy(&addr, arp.arp_tpa, sizeof(addr)); /* save protocol addr */
+ memcpy(arp.arp_tpa, arp.arp_spa, sizeof(addr)); /* swap destination and source protocol address */
+ memcpy(arp.arp_spa, &addr, sizeof(addr)); /* ... */
memcpy(arp.arp_tha, arp.arp_sha, ETH_ALEN); /* set target hard/proto addr */
memcpy(arp.arp_sha, DATA(packet) + ETH_ALEN, ETH_ALEN); /* set source hard/proto addr */
if(source == myself) {
mac_t src;
- memcpy(&src, &DATA(packet)[6], sizeof src);
+ memcpy(&src, &DATA(packet)[6], sizeof(src));
learn_mac(&src);
}
/* Lookup destination address */
- memcpy(&dest, &DATA(packet)[0], sizeof dest);
+ memcpy(&dest, &DATA(packet)[0], sizeof(dest));
subnet = lookup_subnet_mac(NULL, &dest);
if(!subnet || !subnet->owner) {
int environment_add(environment_t *env, const char *format, ...) {
if(env->n >= env->size) {
env->size = env->n ? env->n * 2 : min_env_size;
- env->entries = xrealloc(env->entries, env->size * sizeof *env->entries);
+ env->entries = xrealloc(env->entries, env->size * sizeof(*env->entries));
}
if(format) {
void environment_init(environment_t *env) {
env->n = 0;
env->size = min_env_size;
- env->entries = xzalloc(env->size * sizeof *env->entries);
+ env->entries = xzalloc(env->size * sizeof(*env->entries));
if(netname)
environment_add(env, "NETNAME=%s", netname);
char scriptname[PATH_MAX];
char *command;
- snprintf(scriptname, sizeof scriptname, "%s" SLASH "%s%s", confbase, name, scriptextension);
+ snprintf(scriptname, sizeof(scriptname), "%s" SLASH "%s%s", confbase, name, scriptextension);
/* First check if there is a script */
size_t scriptlen = strlen(scriptname);
char fullname[scriptlen + pathlen + 1];
char *ext = fullname + scriptlen;
- strncpy(fullname, scriptname, sizeof fullname);
+ strncpy(fullname, scriptname, sizeof(fullname));
const char *p = pathext;
bool found = false;
struct strioctl strioc_ppa = {
.ic_cmd = TUNNEWPPA,
- .ic_len = sizeof ppa,
+ .ic_len = sizeof(ppa),
.ic_dp = (char *)&ppa,
};
{
/* Remove muxes just in case they are left over from a crashed tincd */
struct lifreq ifr = {};
- strncpy(ifr.lifr_name, iface, sizeof ifr.lifr_name);
+ strncpy(ifr.lifr_name, iface, sizeof(ifr.lifr_name));
if(ioctl(ip_fd, SIOCGLIFMUXID, &ifr) >= 0) {
int muxid = ifr.lifr_arp_muxid;
ioctl(ip_fd, I_PUNLINK, muxid);
/* Set ifname to arp */
struct strioctl strioc_if = {
.ic_cmd = SIOCSLIFNAME,
- .ic_len = sizeof ifr,
+ .ic_len = sizeof(ifr),
.ic_dp = (char *)&ifr,
};
static void close_device(void) {
if(iface) {
struct lifreq ifr = {};
- strncpy(ifr.lifr_name, iface, sizeof ifr.lifr_name);
+ strncpy(ifr.lifr_name, iface, sizeof(ifr.lifr_name));
if(ioctl(ip_fd, SIOCGLIFMUXID, &ifr) >= 0) {
int muxid = ifr.lifr_arp_muxid;
ioctl(ip_fd, I_PUNLINK, muxid);
memcpy(msg + 1 + 2 * (33 + keylen), s->label, s->labellen);
// Sign the result.
- if(!ecdsa_sign(s->mykey, msg, sizeof msg, sig))
+ if(!ecdsa_sign(s->mykey, msg, sizeof(msg), sig))
return error(s, EINVAL, "Failed to sign SIG record");
// Send the SIG exchange record.
- return send_record_priv(s, SPTPS_HANDSHAKE, sig, sizeof sig);
+ return send_record_priv(s, SPTPS_HANDSHAKE, sig, sizeof(sig));
}
// Generate key material from the shared secret created from the ECDHE key exchange.
memcpy(msg + 1 + 2 * (33 + keylen), s->label, s->labellen);
// Verify signature.
- if(!ecdsa_verify(s->hiskey, msg, sizeof msg, data))
+ if(!ecdsa_verify(s->hiskey, msg, sizeof(msg), data))
return error(s, EIO, "Failed to verify SIG record");
// Compute shared secret.
s->ecdh = NULL;
// Generate key material from shared secret.
- if(!generate_key_material(s, shared, sizeof shared))
+ if(!generate_key_material(s, shared, sizeof(shared)))
return false;
free(s->mykex);
// Start a SPTPS session.
bool sptps_start(sptps_t *s, void *handle, bool initiator, bool datagram, ecdsa_t *mykey, ecdsa_t *hiskey, const void *label, size_t labellen, send_data_t send_data, receive_record_t receive_record) {
// Initialise struct sptps
- memset(s, 0, sizeof *s);
+ memset(s, 0, sizeof(*s));
s->handle = handle;
s->initiator = initiator;
free(s->key);
free(s->label);
free(s->late);
- memset(s, 0, sizeof *s);
+ memset(s, 0, sizeof(*s));
return true;
}
static void receive_data(sptps_t *sptps) {
char buf[4096], *bufp = buf;
int fd = *(int *)sptps->handle;
- size_t len = recv(fd, buf, sizeof buf, 0);
+ size_t len = recv(fd, buf, sizeof(buf), 0);
while(len) {
size_t done = sptps_receive_data(sptps, bufp, len);
if(!done)
crypto_init();
- randomize(buf1, sizeof buf1);
- randomize(buf2, sizeof buf2);
- randomize(buf3, sizeof buf3);
+ randomize(buf1, sizeof(buf1));
+ randomize(buf2, sizeof(buf2));
+ randomize(buf3, sizeof(buf3));
// Key generation
#endif
struct addrinfo *ai, hint;
- memset(&hint, 0, sizeof hint);
+ memset(&hint, 0, sizeof(hint));
hint.ai_family = addressfamily;
hint.ai_socktype = datagram ? SOCK_DGRAM : SOCK_STREAM;
}
int one = 1;
- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof one);
+ setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one));
if(initiator) {
if(connect(sock, ai->ai_addr, ai->ai_addrlen)) {
char buf[65536];
struct sockaddr addr;
- socklen_t addrlen = sizeof addr;
+ socklen_t addrlen = sizeof(addr);
- if(recvfrom(sock, buf, sizeof buf, MSG_PEEK, &addr, &addrlen) <= 0) {
+ if(recvfrom(sock, buf, sizeof(buf), MSG_PEEK, &addr, &addrlen) <= 0) {
fprintf(stderr, "Could not read from socket: %s\n", sockstrerror(sockerrno));
return 1;
}
return 1;
if(FD_ISSET(in, &fds)) {
- ssize_t len = read(in, buf, sizeof buf);
+ ssize_t len = read(in, buf, sizeof(buf));
if(len < 0) {
fprintf(stderr, "Could not read from stdin: %s\n", strerror(errno));
return 1;
if(len > 1)
sptps_send_record(&s, 0, buf, len);
} else
- if(!sptps_send_record(&s, buf[0] == '!' ? 1 : 0, buf, (len == 1 && buf[0] == '\n') ? 0 : buf[0] == '*' ? sizeof buf : len))
+ if(!sptps_send_record(&s, buf[0] == '!' ? 1 : 0, buf, (len == 1 && buf[0] == '\n') ? 0 : buf[0] == '*' ? sizeof(buf) : len))
return 1;
}
if(FD_ISSET(sock, &fds)) {
- ssize_t len = recv(sock, buf, sizeof buf, 0);
+ ssize_t len = recv(sock, buf, sizeof(buf), 0);
if(len < 0) {
fprintf(stderr, "Could not read from socket: %s\n", sockstrerror(sockerrno));
return 1;
if(!p || p->type != SUBNET_MAC)
continue;
- if(!memcmp(address, &p->net.mac.address, sizeof *address)) {
+ if(!memcmp(address, &p->net.mac.address, sizeof(*address))) {
r = p;
if(!p->owner || p->owner->status.reachable)
break;
if(!subnet) {
for splay_each(subnet_t, subnet, owner->subnet_tree) {
- if(!net2str(netstr, sizeof netstr, subnet))
+ if(!net2str(netstr, sizeof(netstr), subnet))
continue;
// Strip the weight from the subnet, and put it in its own environment variable
execute_script(name, &env);
}
} else {
- if(net2str(netstr, sizeof netstr, subnet)) {
+ if(net2str(netstr, sizeof(netstr), subnet)) {
// Strip the weight from the subnet, and put it in its own environment variable
char *weight = strchr(netstr, '#');
if(weight)
for splay_each(subnet_t, subnet, subnet_tree) {
char netstr[MAXNETSTR];
- if(!net2str(netstr, sizeof netstr, subnet))
+ if(!net2str(netstr, sizeof(netstr), subnet))
continue;
send_request(c, "%d %d %s %s",
static int subnet_compare_mac(const subnet_t *a, const subnet_t *b) {
int result;
- result = memcmp(&a->net.mac.address, &b->net.mac.address, sizeof a->net.mac.address);
+ result = memcmp(&a->net.mac.address, &b->net.mac.address, sizeof(a->net.mac.address));
if(result)
return result;
bool str2net(subnet_t *subnet, const char *subnetstr) {
char str[1024];
strncpy(str, subnetstr, sizeof(str));
- str[sizeof str - 1] = 0;
+ str[sizeof(str) - 1] = 0;
int consumed;
int weight = DEFAULT_WEIGHT;
for (int i = 0; i < 4; i++)
if (x[i] > 255)
return false;
- snprintf(last_colon, sizeof str - (last_colon - str), ":%02x%02x:%02x%02x", x[0], x[1], x[2], x[3]);
+ snprintf(last_colon, sizeof(str) - (last_colon - str), ":%02x%02x:%02x%02x", x[0], x[1], x[2], x[3]);
}
char* double_colon = strstr(str, "::");
if(!r)
return;
- snprintf(tmpfile, sizeof tmpfile, "%s.tmp", filename);
+ snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", filename);
struct stat st = {.st_mode = 0600};
fstat(fileno(r), &st);
w = fopenmask(tmpfile, "w", st.st_mode);
- while(fgets(buf, sizeof buf, r)) {
+ while(fgets(buf, sizeof(buf), r)) {
if(!block && !strncmp(buf, "-----BEGIN ", 11)) {
if((strstr(buf, " ED25519 ") && strstr(what, "Ed25519")) || (strstr(buf, " RSA ") && strstr(what, "RSA"))) {
disabled = true;
#ifdef HAVE_MINGW
// We cannot atomically replace files on Windows.
char bakfile[PATH_MAX] = "";
- snprintf(bakfile, sizeof bakfile, "%s.bak", filename);
+ snprintf(bakfile, sizeof(bakfile), "%s.bak", filename);
if(rename(filename, bakfile) || rename(tmpfile, filename)) {
rename(bakfile, filename);
#else
/* Ask for a file and/or directory name. */
fprintf(stderr, "Please enter a file to save %s to [%s]: ", what, filename);
- if(fgets(buf, sizeof buf, stdin) == NULL) {
+ if(fgets(buf, sizeof(buf), stdin) == NULL) {
fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
return NULL;
}
if(filename[0] != '/') {
#endif
/* The directory is a relative path or a filename. */
- getcwd(directory, sizeof directory);
- snprintf(buf2, sizeof buf2, "%s" SLASH "%s", directory, filename);
+ getcwd(directory, sizeof(directory));
+ snprintf(buf2, sizeof(buf2), "%s" SLASH "%s", directory, filename);
filename = buf2;
}
} else
fprintf(stderr, "Done.\n");
- snprintf(fname, sizeof fname, "%s" SLASH "ed25519_key.priv", confbase);
+ snprintf(fname, sizeof(fname), "%s" SLASH "ed25519_key.priv", confbase);
f = ask_and_open(fname, "private Ed25519 key", "a", ask, 0600);
if(!f)
fclose(f);
if(name)
- snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, name);
+ snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, name);
else
- snprintf(fname, sizeof fname, "%s" SLASH "ed25519_key.pub", confbase);
+ snprintf(fname, sizeof(fname), "%s" SLASH "ed25519_key.pub", confbase);
f = ask_and_open(fname, "public Ed25519 key", "a", ask, 0666);
} else
fprintf(stderr, "Done.\n");
- snprintf(fname, sizeof fname, "%s" SLASH "rsa_key.priv", confbase);
+ snprintf(fname, sizeof(fname), "%s" SLASH "rsa_key.priv", confbase);
f = ask_and_open(fname, "private RSA key", "a", ask, 0600);
if(!f)
fclose(f);
if(name)
- snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, name);
+ snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, name);
else
- snprintf(fname, sizeof fname, "%s" SLASH "rsa_key.pub", confbase);
+ snprintf(fname, sizeof(fname), "%s" SLASH "rsa_key.pub", confbase);
f = ask_and_open(fname, "public RSA key", "a", ask, 0666);
return false;
while(!(newline = memchr(buffer, '\n', blen))) {
- int result = recv(fd, buffer + blen, sizeof buffer - blen, 0);
+ int result = recv(fd, buffer + blen, sizeof(buffer) - blen, 0);
if(result == -1 && sockerrno == EINTR)
continue;
else if(result <= 0)
len = blen;
while(blen < len) {
- int result = recv(fd, buffer + blen, sizeof buffer - blen, 0);
+ int result = recv(fd, buffer + blen, sizeof(buffer) - blen, 0);
if(result == -1 && sockerrno == EINTR)
continue;
else if(result <= 0)
va_list ap;
va_start(ap, format);
- blen = vsnprintf(buffer, sizeof buffer, format, ap);
- buffer[sizeof buffer - 1] = 0;
+ blen = vsnprintf(buffer, sizeof(buffer), format, ap);
+ buffer[sizeof(buffer) - 1] = 0;
va_end(ap);
- if(blen < 1 || blen >= sizeof buffer)
+ if(blen < 1 || blen >= sizeof(buffer))
return false;
buffer[blen] = '\n';
0xa1b2c3d4,
2, 4,
0, 0,
- snaplen ?: sizeof data,
+ snaplen ?: sizeof(data),
1,
};
struct timeval tv;
- fwrite(&header, sizeof header, 1, out);
+ fwrite(&header, sizeof(header), 1, out);
fflush(out);
char line[32];
- while(recvline(fd, line, sizeof line)) {
+ while(recvline(fd, line, sizeof(line))) {
int code, req, len;
int n = sscanf(line, "%d %d %d", &code, &req, &len);
gettimeofday(&tv, NULL);
- if(n != 3 || code != CONTROL || req != REQ_PCAP || len < 0 || len > sizeof data)
+ if(n != 3 || code != CONTROL || req != REQ_PCAP || len < 0 || len > sizeof(data))
break;
if(!recvdata(fd, data, len))
break;
packet.tv_usec = tv.tv_usec;
packet.len = len;
packet.origlen = len;
- fwrite(&packet, sizeof packet, 1, out);
+ fwrite(&packet, sizeof(packet), 1, out);
fwrite(data, len, 1, out);
fflush(out);
}
char data[1024];
char line[32];
- while(recvline(fd, line, sizeof line)) {
+ while(recvline(fd, line, sizeof(line))) {
int code, req, len;
int n = sscanf(line, "%d %d %d", &code, &req, &len);
- if(n != 3 || code != CONTROL || req != REQ_LOG || len < 0 || len > sizeof data)
+ if(n != 3 || code != CONTROL || req != REQ_LOG || len < 0 || len > sizeof(data))
break;
if(!recvdata(fd, data, len))
break;
struct sockaddr_un sa;
sa.sun_family = AF_UNIX;
- strncpy(sa.sun_path, unixsocketname, sizeof sa.sun_path);
+ strncpy(sa.sun_path, unixsocketname, sizeof(sa.sun_path));
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if(fd < 0) {
return false;
}
- if(connect(fd, (struct sockaddr *)&sa, sizeof sa) < 0) {
+ if(connect(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
if(verbose)
fprintf(stderr, "Cannot connect to UNIX socket %s: %s\n", unixsocketname, sockstrerror(sockerrno));
close(fd);
#ifdef SO_NOSIGPIPE
static const int one = 1;
- setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&one, sizeof one);
+ setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&one, sizeof(one));
#endif
char data[4096];
int version;
- if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %4095s %d", &code, data, &version) != 3 || code != 0) {
+ if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %4095s %d", &code, data, &version) != 3 || code != 0) {
if(verbose)
fprintf(stderr, "Cannot read greeting from control socket: %s\n", sockstrerror(sockerrno));
close(fd);
sendline(fd, "%d ^%s %d", ID, controlcookie, TINC_CTL_VERSION_CURRENT);
- if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &version, &pid) != 3 || code != 4 || version != TINC_CTL_VERSION_CURRENT) {
+ if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &version, &pid) != 3 || code != 4 || version != TINC_CTL_VERSION_CURRENT) {
if(verbose)
fprintf(stderr, "Could not fully establish control socket connection\n");
close(fd);
c = "tincd";
int nargc = 0;
- char **nargv = xzalloc((optind + argc) * sizeof *nargv);
+ char **nargv = xzalloc((optind + argc) * sizeof(*nargv));
char *arg0 = c;
#ifdef HAVE_MINGW
if(!pid) {
close(pfd[0]);
char buf[100];
- snprintf(buf, sizeof buf, "%d", pfd[1]);
+ snprintf(buf, sizeof(buf), "%d", pfd[1]);
setenv("TINC_UMBILICAL", buf, true);
exit(execvp(c, nargv));
} else {
char buf[1024];
ssize_t len;
- while((len = read(pfd[0], buf, sizeof buf)) > 0) {
+ while((len = read(pfd[0], buf, sizeof(buf))) > 0) {
failure = buf[len - 1];
if(!failure)
len--;
sendline(fd, "%d %d", CONTROL, REQ_STOP);
- while(recvline(fd, line, sizeof line)) {
+ while(recvline(fd, line, sizeof(line))) {
// Wait for tincd to close the connection...
}
#else
return 1;
sendline(fd, "%d %d", CONTROL, REQ_RELOAD);
- if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_RELOAD || result) {
+ if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_RELOAD || result) {
fprintf(stderr, "Could not reload configuration.\n");
return 1;
}
static int dump_invitations(void) {
char dname[PATH_MAX];
- snprintf(dname, sizeof dname, "%s" SLASH "invitations", confbase);
+ snprintf(dname, sizeof(dname), "%s" SLASH "invitations", confbase);
DIR *dir = opendir(dname);
if(!dir) {
if(errno == ENOENT) {
continue;
char fname[PATH_MAX];
- snprintf(fname, sizeof fname, "%s" SLASH "%s", dname, ent->d_name);
+ snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ent->d_name);
FILE *f = fopen(fname, "r");
if(!f) {
fprintf(stderr, "Cannot open %s: %s\n", fname, strerror(errno));
}
buf[0] = 0;
- if(!fgets(buf, sizeof buf, f)) {
+ if(!fgets(buf, sizeof(buf), f)) {
fprintf(stderr, "Invalid invitation file %s", fname);
fclose(f);
continue;
else if(do_graph == 2)
printf("digraph {\n");
- while(recvline(fd, line, sizeof line)) {
+ while(recvline(fd, line, sizeof(line))) {
char node1[4096], node2[4096];
int n = sscanf(line, "%d %d %4095s %4095s", &code, &req, node1, node2);
if(n == 2) {
return 1;
}
- memcpy(&status, &status_int, sizeof status);
+ memcpy(&status, &status_int, sizeof(status));
if(do_graph) {
const char *color = "black";
return 1;
sendline(fd, "%d %d", CONTROL, REQ_PURGE);
- if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_PURGE || result) {
+ if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_PURGE || result) {
fprintf(stderr, "Could not purge old information.\n");
return 1;
}
int origlevel;
sendline(fd, "%d %d %d", CONTROL, REQ_SET_DEBUG, debuglevel);
- if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &origlevel) != 3 || code != CONTROL || req != REQ_SET_DEBUG) {
+ if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &req, &origlevel) != 3 || code != CONTROL || req != REQ_SET_DEBUG) {
fprintf(stderr, "Could not set debug level.\n");
return 1;
}
return 1;
sendline(fd, "%d %d", CONTROL, REQ_RETRY);
- if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_RETRY || result) {
+ if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_RETRY || result) {
fprintf(stderr, "Could not retry outgoing connections.\n");
return 1;
}
return 1;
sendline(fd, "%d %d %s", CONTROL, REQ_CONNECT, argv[1]);
- if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_CONNECT || result) {
+ if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_CONNECT || result) {
fprintf(stderr, "Could not connect to %s.\n", argv[1]);
return 1;
}
return 1;
sendline(fd, "%d %d %s", CONTROL, REQ_DISCONNECT, argv[1]);
- if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_DISCONNECT || result) {
+ if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_DISCONNECT || result) {
fprintf(stderr, "Could not disconnect %s.\n", argv[1]);
return 1;
}
char buf[4096];
char *value;
- while(fgets(buf, sizeof buf, f)) {
+ while(fgets(buf, sizeof(buf), f)) {
int len = strcspn(buf, "\t =");
value = buf + len;
value += strspn(value, "\t ");
ecdsa_t *get_pubkey(FILE *f) {
char buf[4096];
char *value;
- while(fgets(buf, sizeof buf, f)) {
+ while(fgets(buf, sizeof(buf), f)) {
int len = strcspn(buf, "\t =");
value = buf + len;
value += strspn(value, "\t ");
}
// Concatenate the rest of the command line
- strncpy(line, argv[1], sizeof line - 1);
+ strncpy(line, argv[1], sizeof(line) - 1);
for(int i = 2; i < argc; i++) {
- strncat(line, " ", sizeof line - 1 - strlen(line));
- strncat(line, argv[i], sizeof line - 1 - strlen(line));
+ strncat(line, " ", sizeof(line) - 1 - strlen(line));
+ strncat(line, argv[i], sizeof(line) - 1 - strlen(line));
}
// Liberal parsing into node name, variable name and value.
// Open the right configuration file.
char filename[PATH_MAX];
if(node)
- snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, node);
+ snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, node);
else
- snprintf(filename, sizeof filename, "%s", tinc_conf);
+ snprintf(filename, sizeof(filename), "%s", tinc_conf);
FILE *f = fopen(filename, "r");
if(!f) {
FILE *tf = NULL;
if(action >= -1) {
- snprintf(tmpfile, sizeof tmpfile, "%s.config.tmp", filename);
+ snprintf(tmpfile, sizeof(tmpfile), "%s.config.tmp", filename);
tf = fopen(tmpfile, "w");
if(!tf) {
fprintf(stderr, "Could not open temporary file %s: %s\n", tmpfile, strerror(errno));
bool removed = false;
found = false;
- while(fgets(buf1, sizeof buf1, f)) {
- buf1[sizeof buf1 - 1] = 0;
- strncpy(buf2, buf1, sizeof buf2);
+ while(fgets(buf1, sizeof(buf1), f)) {
+ buf1[sizeof(buf1) - 1] = 0;
+ strncpy(buf2, buf1, sizeof(buf2));
// Parse line in a simple way
char *bvalue;
bool success = true;
char portstr[16];
- snprintf(portstr, sizeof portstr, "%d", port);
+ snprintf(portstr, sizeof(portstr), "%d", port);
if(getaddrinfo(NULL, portstr, &hint, &ai) || !ai)
return false;
int port = 0x1000 + (rand() & 0x7fff);
if(try_bind(port)) {
char filename[PATH_MAX];
- snprintf(filename, sizeof filename, "%s" SLASH "hosts" SLASH "%s", confbase, name);
+ snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", confbase, name);
FILE *f = fopen(filename, "a");
if(!f) {
fprintf(stderr, "Could not open %s: %s\n", filename, strerror(errno));
if(tty) {
char buf[1024];
fprintf(stderr, "Enter the Name you want your tinc node to have: ");
- if(!fgets(buf, sizeof buf, stdin)) {
+ if(!fgets(buf, sizeof(buf), stdin)) {
fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
return 1;
}
#ifndef HAVE_MINGW
char filename[PATH_MAX];
- snprintf(filename, sizeof filename, "%s" SLASH "tinc-up", confbase);
+ snprintf(filename, sizeof(filename), "%s" SLASH "tinc-up", confbase);
if(access(filename, F_OK)) {
FILE *f = fopenmask(filename, "w", 0777);
if(!f) {
if(strncmp(argv[1], "hosts" SLASH, 6)) {
for(int i = 0; conffiles[i]; i++) {
if(!strcmp(argv[1], conffiles[i])) {
- snprintf(filename, sizeof filename, "%s" SLASH "%s", confbase, argv[1]);
+ snprintf(filename, sizeof(filename), "%s" SLASH "%s", confbase, argv[1]);
break;
}
}
}
if(!*filename) {
- snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, argv[1]);
+ snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, argv[1]);
char *dash = strchr(argv[1], '-');
if(dash) {
*dash++ = 0;
static int export(const char *name, FILE *out) {
char filename[PATH_MAX];
- snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, name);
+ snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name);
FILE *in = fopen(filename, "r");
if(!in) {
fprintf(stderr, "Could not open configuration file %s: %s\n", filename, strerror(errno));
fprintf(out, "Name = %s\n", name);
char buf[4096];
- while(fgets(buf, sizeof buf, in)) {
+ while(fgets(buf, sizeof(buf), in)) {
if(strcspn(buf, "\t =") != 4 || strncasecmp(buf, "Name", 4))
fputs(buf, out);
}
int count = 0;
bool firstline = true;
- while(fgets(buf, sizeof buf, in)) {
+ while(fgets(buf, sizeof(buf), in)) {
if(sscanf(buf, "Name = %4095s", name) == 1) {
firstline = false;
if(out)
fclose(out);
- snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, name);
+ snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name);
if(!force && !access(filename, F_OK)) {
fprintf(stderr, "Host configuration file %s already exists, skipping.\n", filename);
}
char fname[PATH_MAX];
- snprintf(fname, sizeof fname, "%s/%s/tinc.conf", confdir, ent->d_name);
+ snprintf(fname, sizeof(fname), "%s/%s/tinc.conf", confdir, ent->d_name);
if(!access(fname, R_OK))
printf("%s\n", ent->d_name);
}
}
char fname[PATH_MAX];
- snprintf(fname, sizeof fname, "%s" SLASH "ed25519_key.priv", confbase);
+ snprintf(fname, sizeof(fname), "%s" SLASH "ed25519_key.priv", confbase);
FILE *fp = fopen(fname, "r");
if(!fp) {
fprintf(stderr, "Could not open %s: %s\n", fname, strerror(errno));
newline = data + skip;
char fname[PATH_MAX];
- snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, node);
+ snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, node);
FILE *fp = fopen(fname, "r");
if(!fp) {
fprintf(stderr, "Could not open %s: %s\n", fname, strerror(errno));
sendline(fd, "%d %d", CONTROL, REQ_DUMP_SUBNETS);
}
- while(recvline(fd, line, sizeof line)) {
+ while(recvline(fd, line, sizeof(line))) {
char item[4096];
int n = sscanf(line, "%d %d %4095s", &code, &req, item);
if(n == 2) {
char buf[4096];
char *line = NULL;
int maxargs = argc + 16;
- char **nargv = xmalloc(maxargs * sizeof *nargv);
+ char **nargv = xmalloc(maxargs * sizeof(*nargv));
for(int i = 0; i < argc; i++)
nargv[i] = argv[i];
if(line)
copy = xstrdup(line);
} else {
- line = fgets(buf, sizeof buf, stdin);
+ line = fgets(buf, sizeof(buf), stdin);
}
#else
if(tty)
fputs(prompt, stdout);
- line = fgets(buf, sizeof buf, stdin);
+ line = fgets(buf, sizeof(buf), stdin);
#endif
if(!line)
while(p && *p) {
if(nargc >= maxargs) {
maxargs *= 2;
- nargv = xrealloc(nargv, maxargs * sizeof *nargv);
+ nargv = xrealloc(nargv, maxargs * sizeof(*nargv));
}
nargv[nargc++] = p;
for list_each(nodestats_t, ns, &node_list)
ns->known = false;
- while(recvline(fd, line, sizeof line)) {
+ while(recvline(fd, line, sizeof(line))) {
int n = sscanf(line, "%d %d %4095s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &code, &req, name, &in_packets, &in_bytes, &out_packets, &out_bytes);
if(n == 2)
found = ns;
break;
} else {
- found = xzalloc(sizeof *found);
+ found = xzalloc(sizeof(*found));
found->name = xstrdup(name);
list_insert_before(&node_list, node, found);
changed = true;
}
if(!found) {
- found = xzalloc(sizeof *found);
+ found = xzalloc(sizeof(*found));
found->name = xstrdup(name);
list_insert_tail(&node_list, found);
changed = true;
static int n = 0;
if(changed) {
n = 0;
- sorted = xrealloc(sorted, node_list.count * sizeof *sorted);
+ sorted = xrealloc(sorted, node_list.count * sizeof(*sorted));
for list_each(nodestats_t, ns, &node_list)
sorted[n++] = ns;
changed = false;
sorted[i]->i = i;
if(sorted)
- qsort(sorted, n, sizeof *sorted, sortfunc);
+ qsort(sorted, n, sizeof(*sorted), sortfunc);
for(int i = 0, row = 3; i < n; i++, row++) {
nodestats_t *node = sorted[i];
fcntl(write_fd, F_SETFD, FD_CLOEXEC);
#endif
- setsockopt(write_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one);
+ setsockopt(write_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
if(fcntl(write_fd, F_SETFL, O_NONBLOCK) < 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
fcntl(data_fd, F_SETFD, FD_CLOEXEC);
#endif
- setsockopt(data_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one);
+ setsockopt(data_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
if(fcntl(data_fd, F_SETFL, O_NONBLOCK) < 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
gettimeofday(&tv, NULL);
name.usecs = tv.tv_usec;
data_sun.sun_family = AF_UNIX;
- memcpy(&data_sun.sun_path, &name, sizeof name);
+ memcpy(&data_sun.sun_path, &name, sizeof(name));
- if(bind(data_fd, (struct sockaddr *)&data_sun, sizeof data_sun) < 0) {
+ if(bind(data_fd, (struct sockaddr *)&data_sun, sizeof(data_sun)) < 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not bind data %s: %s", device_info, strerror(errno));
event_exit();
return false;
fcntl(device_fd, F_SETFD, FD_CLOEXEC);
#endif
- setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one);
+ setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
if(fcntl(listen_fd, F_SETFL, O_NONBLOCK) < 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
}
listen_sun.sun_family = AF_UNIX;
- strncpy(listen_sun.sun_path, device, sizeof listen_sun.sun_path);
- if(bind(listen_fd, (struct sockaddr *)&listen_sun, sizeof listen_sun) < 0) {
+ strncpy(listen_sun.sun_path, device, sizeof(listen_sun.sun_path));
+ if(bind(listen_fd, (struct sockaddr *)&listen_sun, sizeof(listen_sun)) < 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not bind %s to %s: %s", device_info, device, strerror(errno));
return false;
}
switch(state) {
case 0: {
struct sockaddr sa;
- socklen_t salen = sizeof sa;
+ socklen_t salen = sizeof(sa);
request_fd = accept(listen_fd, &sa, &salen);
if(request_fd < 0) {
}
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 false;
}
- if(connect(write_fd, (struct sockkadr *)&request.sock, sizeof request.sock) < 0) {
+ if(connect(write_fd, (struct sockkadr *)&request.sock, sizeof(request.sock)) < 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not bind write %s: %s", device_info, strerror(errno));
event_exit();
return false;
}
- write(request_fd, &data_sun, sizeof data_sun);
+ write(request_fd, &data_sun, sizeof(data_sun));
device_fd = data_fd;
logger(DEBUG_ALWAYS, LOG_INFO, "Connection with UML established");
// Note that we can't simply use listen_socket[].sa because this won't have the port
// if we're running with Port=0 (dynamically assigned port).
sockaddr_t sa;
- socklen_t salen = sizeof sa;
+ socklen_t salen = sizeof(sa);
if (getsockname(socket, &sa.sa, &salen)) {
logger(DEBUG_PROTOCOL, LOG_ERR, "[upnp] Unable to get socket address: [%d] %s", sockerrno, sockstrerror(sockerrno));
return;
// Use a lease twice as long as the refresh period so that the mapping won't expire before we refresh.
char lease_duration[16];
- snprintf(lease_duration, sizeof lease_duration, "%d", upnp_refresh_period * 2);
+ snprintf(lease_duration, sizeof(lease_duration), "%d", upnp_refresh_period * 2);
int error = UPNP_AddPortMapping(urls->controlURL, data->first.servicetype, port, port, myaddr, identname, proto, NULL, lease_duration);
if (error == 0) {
struct UPNPUrls urls;
struct IGDdatas data;
char myaddr[64];
- int result = UPNP_GetValidIGD(devices, &urls, &data, myaddr, sizeof myaddr);
+ int result = UPNP_GetValidIGD(devices, &urls, &data, myaddr, sizeof(myaddr));
if (result <= 0) {
logger(DEBUG_PROTOCOL, LOG_WARNING, "[upnp] No IGD found");
freeUPNPDevlist(devices);
const char *winerror(int err) {
static char buf[1024], *ptr;
- ptr = buf + snprintf(buf, sizeof buf, "(%d) ", err);
+ ptr = buf + snprintf(buf, sizeof(buf), "(%d) ", err);
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), ptr, sizeof(buf) - (ptr - buf), NULL)) {
unsigned int bitfield_to_int(const void *bitfield, size_t size) {
unsigned int value = 0;
- if(size > sizeof value)
- size = sizeof value;
+ if(size > sizeof(value))
+ size = sizeof(value);
memcpy(&value, bitfield, size);
return value;
}
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid Name: environment variable %s does not exist\n", name + 1);
return NULL;
}
- if (gethostname(hostname, sizeof hostname) || !*hostname) {
+ if (gethostname(hostname, sizeof(hostname)) || !*hostname) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not get hostname: %s\n", sockstrerror(sockerrno));
return NULL;
}
static inline int xvasprintf(char **strp, const char *fmt, va_list ap) {
#ifdef HAVE_MINGW
char buf[1024];
- int result = vsnprintf(buf, sizeof buf, fmt, ap);
+ int result = vsnprintf(buf, sizeof(buf), fmt, ap);
if(result < 0)
abort();
*strp = xstrdup(buf);
static ssize_t do_arp(uint8_t *buf, ssize_t len, struct sockaddr_in *in) {
struct ether_arp arp;
- memcpy(&arp, buf + 14, sizeof arp);
+ memcpy(&arp, buf + 14, sizeof(arp));
// Is it a valid ARP request?
- if(ntohs(arp.arp_hrd) != ARPHRD_ETHER || ntohs(arp.arp_pro) != ETH_P_IP || arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof in->sin_addr.s_addr || ntohs(arp.arp_op) != ARPOP_REQUEST)
+ if(ntohs(arp.arp_hrd) != ARPHRD_ETHER || ntohs(arp.arp_pro) != ETH_P_IP || arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof(in->sin_addr.s_addr) || ntohs(arp.arp_op) != ARPOP_REQUEST)
return 0;
// Does it match our address?
memcpy(buf + 6, mymac, 6);
arp.arp_op = htons(ARPOP_REPLY);
- memcpy(arp.arp_tpa, arp.arp_spa, sizeof arp.arp_tpa);
- memcpy(arp.arp_tha, arp.arp_sha, sizeof arp.arp_tha);
- memcpy(arp.arp_spa, &in->sin_addr.s_addr, sizeof in->sin_addr.s_addr);
+ memcpy(arp.arp_tpa, arp.arp_spa, sizeof(arp.arp_tpa));
+ memcpy(arp.arp_tha, arp.arp_sha, sizeof(arp.arp_tha));
+ memcpy(arp.arp_spa, &in->sin_addr.s_addr, sizeof(in->sin_addr.s_addr));
memcpy(arp.arp_sha, mymac, 6);
- memcpy(buf + 14, &arp, sizeof arp);
+ memcpy(buf + 14, &arp, sizeof(arp));
return len;
}
if(memcmp(buf, mymac, 6))
return 0;
- memcpy(&ip, buf + 14, sizeof ip);
+ memcpy(&ip, buf + 14, sizeof(ip));
if(memcmp(&ip.ip_dst, &in->sin_addr.s_addr, 4))
return 0;
if(ip.ip_p != IPPROTO_ICMP)
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, &ip, sizeof(ip));
+ memcpy(buf + 14 + sizeof(ip), &icmp, sizeof icmp);
return len;
}
}
static const int one = 1;
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof one);
+ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one));
if(bind(fd, ai->ai_addr, ai->ai_addrlen)) {
fprintf(stderr, "Could not bind socket: %s\n", strerror(errno));
case AF_INET: {
struct ip_mreq mreq;
struct sockaddr_in in;
- memcpy(&in, ai->ai_addr, sizeof in);
+ memcpy(&in, ai->ai_addr, sizeof(in));
mreq.imr_multiaddr.s_addr = in.sin_addr.s_addr;
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
- if(setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof mreq)) {
+ if(setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq))) {
fprintf(stderr, "Cannot join multicast group: %s\n", strerror(errno));
return 1;
}
#ifdef IP_MULTICAST_LOOP
- setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof one);
+ setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof(one));
#endif
} break;
case AF_INET6: {
struct ipv6_mreq mreq;
struct sockaddr_in6 in6;
- memcpy(&in6, ai->ai_addr, sizeof in6);
- memcpy(&mreq.ipv6mr_multiaddr, &in6.sin6_addr, sizeof mreq.ipv6mr_multiaddr);
+ memcpy(&in6, ai->ai_addr, sizeof(in6));
+ memcpy(&mreq.ipv6mr_multiaddr, &in6.sin6_addr, sizeof(mreq.ipv6mr_multiaddr));
mreq.ipv6mr_interface = in6.sin6_scope_id;
- if(setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof mreq)) {
+ if(setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof(mreq))) {
fprintf(stderr, "Cannot join multicast group: %s\n", strerror(errno));
return 1;
}
#ifdef IPV6_MULTICAST_LOOP
- setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof one);
+ setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof(one));
#endif
} break;
#endif
uint8_t buf[10000];
struct sockaddr src;
socklen_t srclen;
- ssize_t len = recvfrom(fd, buf, sizeof buf, 0, &src, &srclen);
+ ssize_t len = recvfrom(fd, buf, sizeof(buf), 0, &src, &srclen);
if(len <= 0)
break;