}
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(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(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(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(packet->data + 10, &type, sizeof type);
+ memcpy(packet->data + 10, &type, sizeof(type));
if(write(device_fd, packet->data + 10, packet->len - 10) < 0) {
logger(LOG_ERR, "Can't write to %s %s: %s", device_info, device,
}
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/tinc.conf", confbase);
+ snprintf(fname, sizeof(fname), "%s/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/conf.d", confbase);
+ snprintf(dname, sizeof(dname), "%s/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/%s", dname, ep->d_name);
+ snprintf(fname, sizeof(fname), "%s/%s", dname, ep->d_name);
x = read_config_file(config_tree, fname);
}
}
read_config_options(c->config_tree, c->name);
- snprintf(fname, sizeof fname, "%s/hosts/%s", confbase, c->name);
+ snprintf(fname, sizeof(fname), "%s/hosts/%s", confbase, c->name);
x = read_config_file(c->config_tree, fname);
return x;
if(!r)
return;
- snprintf(tmpfile, sizeof tmpfile, "%s.tmp", filename);
+ snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", filename);
w = fopen(tmpfile, "w");
- while(fgets(buf, sizeof buf, r)) {
+ while(fgets(buf, sizeof(buf), r)) {
if(!strncmp(buf, "-----BEGIN RSA", 14)) {
buf[11] = 'O';
buf[12] = 'L';
#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
what, filename);
fflush(stdout);
- fn = readline(stdin, line, sizeof line);
+ fn = readline(stdin, line, sizeof(line));
if(!fn) {
fprintf(stderr, "Error while reading stdin: %s\n",
if(fn[0] != '/') {
#endif
/* The directory is a relative path or a filename. */
- getcwd(directory, sizeof directory);
- snprintf(abspath, sizeof abspath, "%s/%s", directory, fn);
+ getcwd(directory, sizeof(directory));
+ snprintf(abspath, sizeof(abspath), "%s/%s", directory, fn);
fn = abspath;
}
for(node = connection_tree->head; node; node = node->next) {
c = node->data;
logger(LOG_DEBUG, " %s at %s options %x socket %d status %04x outbuf %d/%d/%d",
- c->name, c->hostname, c->options, c->socket, bitfield_to_int(&c->status, sizeof c->status),
+ c->name, c->hostname, c->options, c->socket, bitfield_to_int(&c->status, sizeof(c->status)),
c->outbufsize, c->outbufstart, c->outbuflen);
}
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) {
send_ans_key(n);
break;
case LOGMODE_FILE:
now = time(NULL);
- strftime(timestr, sizeof timestr, "%Y-%m-%d %H:%M:%S", localtime(&now));
+ strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", localtime(&now));
fprintf(logfile, "%s %s[%ld]: ", timestr, logident, (long)logpid);
vfprintf(logfile, format, ap);
fprintf(logfile, "\n");
char message[4096];
const char *messages[] = {message};
vsnprintf(message, sizeof(message), format, ap);
- message[sizeof message - 1] = 0;
+ message[sizeof(message) - 1] = 0;
ReportEvent(loghandle, priority, 0, 0, NULL, 1, 0, messages, NULL);
}
#else
#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)) {
closesocket(device_fd);
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(LOG_ERR, "Cannot join multicast group %s %s: %s", host, port, sockstrerror(sockerrno));
closesocket(device_fd);
free(host);
return false;
}
#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(LOG_ERR, "Cannot join multicast group %s %s: %s", host, port, sockstrerror(sockerrno));
closesocket(device_fd);
free(host);
return false;
}
#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, packet->data + 6, sizeof ignore_src)) {
+ if(!memcmp(&ignore_src, packet->data + 6, sizeof(ignore_src))) {
ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Ignoring loopback packet of %d bytes from %s", lenin, device_info);
packet->len = 0;
return true;
device_total_out += packet->len;
- memcpy(&ignore_src, packet->data + 6, sizeof ignore_src);
+ memcpy(&ignore_src, packet->data + 6, sizeof(ignore_src));
return true;
}
} else {
if(c->status.remove) {
logger(LOG_WARNING, "Old connection_t for %s (%s) status %04x still lingering, deleting...",
- c->name, c->hostname, bitfield_to_int(&c->status, sizeof c->status));
+ c->name, c->hostname, bitfield_to_int(&c->status, sizeof(c->status)));
connection_del(c);
continue;
}
static bool try_mac(const node_t *n, const vpn_packet_t *inpkt) {
unsigned char hmac[EVP_MAX_MD_SIZE];
- if(!n->indigest || !n->inmaclength || !n->inkey || inpkt->len < sizeof inpkt->seqno + n->inmaclength)
+ if(!n->indigest || !n->inmaclength || !n->inkey || inpkt->len < sizeof(inpkt->seqno) + n->inmaclength)
return false;
HMAC(n->indigest, n->inkey, n->inkeylength, (unsigned char *) &inpkt->seqno, inpkt->len - n->inmaclength, (unsigned char *)hmac, NULL);
void receive_tcppacket(connection_t *c, const char *buffer, int len) {
vpn_packet_t outpkt;
- if(len > sizeof outpkt.data)
+ if(len > sizeof(outpkt.data))
return;
outpkt.len = len;
if(origpriority == -1 && n->prevedge) {
sock = rand() % listen_sockets;
- memset(&broadcast, 0, sizeof broadcast);
+ memset(&broadcast, 0, sizeof(broadcast));
if(listen_socket[sock].sa.sa.sa_family == AF_INET6) {
broadcast.in6.sin6_family = AF_INET6;
broadcast.in6.sin6_addr.s6_addr[0x0] = 0xff;
free(name);
return false;
}
- if(gethostname(hostname, sizeof hostname) || !*hostname) {
+ if(gethostname(hostname, sizeof(hostname)) || !*hostname) {
fprintf(stderr, "Could not get hostname: %s\n", strerror(errno));
free(name);
return false;
}
for(i = 0; i < listen_sockets; i++) {
- salen = sizeof sa;
+ salen = sizeof(sa);
if(getsockname(i + 3, &sa.sa, &salen) < 0) {
logger(LOG_ERR, "Could not get address of listen fd %d: %s", i + 3, sockstrerror(errno));
return false;
if(!port_specified) {
sockaddr_t sa;
- socklen_t salen = sizeof sa;
+ socklen_t salen = sizeof(sa);
if(!getsockname(listen_socket[0].udp, &sa.sa, &salen)) {
free(myport);
sockaddr2str(&sa, NULL, &myport);
#if defined(SOL_IPV6) && defined(IPV6_V6ONLY)
if(sa->sa.sa_family == AF_INET6)
- setsockopt(nfd, SOL_IPV6, IPV6_V6ONLY, (void *)&option, sizeof option);
+ setsockopt(nfd, SOL_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option));
#endif
if(get_config_string(lookup_config(config_tree, "BindToInterface"), &iface)) {
#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 we cannot resolve the address, maybe we are using a proxy that can?
if(!c->outgoing->ai && proxytype != PROXY_NONE && is_valid_host_port(address, port)) {
- memset(&c->address, 0, sizeof c->address);
+ memset(&c->address, 0, sizeof(c->address));
c->address.sa.sa_family = AF_UNKNOWN;
c->address.unknown.address = address;
c->address.unknown.port = port;
#if defined(SOL_IPV6) && defined(IPV6_V6ONLY)
int option = 1;
if(c->address.sa.sa_family == AF_INET6)
- setsockopt(c->socket, SOL_IPV6, IPV6_V6ONLY, (void *)&option, sizeof option);
+ setsockopt(c->socket, SOL_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option));
#endif
bind_to_interface(c->socket);
avl_insert(node_udp_tree, n);
ifdebug(PROTOCOL) logger(LOG_DEBUG, "UDP address of %s set to %s", n->name, n->hostname);
} else {
- memset(&n->address, 0, sizeof n->address);
+ memset(&n->address, 0, sizeof(n->address));
n->hostname = NULL;
ifdebug(PROTOCOL) logger(LOG_DEBUG, "UDP address of %s cleared", n->name);
}
logger(LOG_DEBUG, " %s at %s cipher %d digest %d maclength %d compression %d options %x status %04x nexthop %s via %s pmtu %d (min %d max %d)",
n->name, n->hostname, n->outcipher ? EVP_CIPHER_nid(n->outcipher) : 0,
n->outdigest ? EVP_MD_type(n->outdigest) : 0, n->outmaclength, n->outcompression,
- n->options, bitfield_to_int(&n->status, sizeof n->status), n->nexthop ? n->nexthop->name : "-",
+ n->options, bitfield_to_int(&n->status, sizeof(n->status)), n->nexthop ? n->nexthop->name : "-",
n->via ? n->via->name : "-", n->mtu, n->minmtu, n->maxmtu);
}
}
if(!strchr(program_name, '\\')) {
- GetCurrentDirectory(sizeof command - 1, command + 1);
- strncat(command, "\\", sizeof command - strlen(command));
+ GetCurrentDirectory(sizeof(command) - 1, command + 1);
+ strncat(command, "\\", sizeof(command) - strlen(command));
}
- strncat(command, program_name, sizeof command - strlen(command));
+ strncat(command, program_name, sizeof(command) - strlen(command));
- strncat(command, "\"", sizeof command - strlen(command));
+ strncat(command, "\"", sizeof(command) - strlen(command));
for(argp = g_argv + 1; *argp; argp++) {
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(buffer, sizeof buffer, format, args);
- buffer[sizeof buffer - 1] = 0;
+ len = vsnprintf(buffer, sizeof(buffer), format, args);
+ buffer[sizeof(buffer) - 1] = 0;
va_end(args);
- if(len < 0 || len > sizeof buffer - 1) {
+ if(len < 0 || len > sizeof(buffer) - 1) {
logger(LOG_ERR, "Output buffer overflow while sending request to %s (%s)",
c->name, c->hostname);
return false;
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);
static void update_address_ipv4(connection_t *c, void *address, void *port) {
sockaddrfree(&c->address);
- memset(&c->address, 0, sizeof c->address);
+ memset(&c->address, 0, sizeof(c->address));
c->address.sa.sa_family = AF_INET;
if(address)
memcpy(&c->address.in.sin_addr, address, sizeof(ipv4_t));
static void update_address_ipv6(connection_t *c, void *address, void *port) {
sockaddrfree(&c->address);
- memset(&c->address, 0, sizeof c->address);
+ memset(&c->address, 0, sizeof(c->address));
c->address.sa.sa_family = AF_INET6;
if(address)
memcpy(&c->address.in6.sin6_addr, address, sizeof(ipv6_t));
strcpy(s4req + 8, proxyuser);
else
s4req[8] = 0;
- s4req[sizeof s4req - 1] = 0;
+ s4req[sizeof(s4req) - 1] = 0;
c->allow_request = PROXY;
- return send_meta(c, s4req, sizeof s4req);
+ return send_meta(c, s4req, sizeof(s4req));
}
case PROXY_SOCKS5: {
if(i > len)
abort();
c->allow_request = PROXY;
- return send_meta(c, s5req, sizeof s5req);
+ return send_meta(c, s5req, sizeof(s5req));
}
case PROXY_HTTP: {
static void swap_mac_addresses(vpn_packet_t *packet) {
mac_t tmp;
- memcpy(&tmp, &packet->data[0], sizeof tmp);
- memcpy(&packet->data[0], &packet->data[6], sizeof tmp);
- memcpy(&packet->data[6], &tmp, sizeof tmp);
+ memcpy(&tmp, &packet->data[0], sizeof(tmp));
+ memcpy(&packet->data[0], &packet->data[6], sizeof(tmp));
+ memcpy(&packet->data[6], &tmp, sizeof(tmp));
}
/* RFC 792 */
if(s->expires && s->expires <= now) {
ifdebug(TRAFFIC) {
char netstr[MAXNETSTR];
- if(net2str(netstr, sizeof netstr, s))
+ if(net2str(netstr, sizeof(netstr), s))
logger(LOG_INFO, "Subnet %s expired", netstr);
}
node_t *via;
ipv4_t dest;
- memcpy(&dest, &packet->data[30], sizeof dest);
+ memcpy(&dest, &packet->data[30], sizeof(dest));
subnet = lookup_subnet_ipv4(&dest);
if(!subnet) {
node_t *via;
ipv6_t dest;
- memcpy(&dest, &packet->data[38], sizeof dest);
+ memcpy(&dest, &packet->data[38], sizeof(dest));
subnet = lookup_subnet_ipv6(&dest);
if(!subnet) {
if(source == myself) {
mac_t src;
- memcpy(&src, &packet->data[6], sizeof src);
+ memcpy(&src, &packet->data[6], sizeof(src));
learn_mac(&src);
}
/* Lookup destination address */
- memcpy(&dest, &packet->data[0], sizeof dest);
+ memcpy(&dest, &packet->data[0], sizeof(dest));
subnet = lookup_subnet_mac(NULL, &dest);
if(!subnet) {
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);
continue;
if(owner && cache_mac_subnet[i] && cache_mac_subnet[i]->owner != owner)
continue;
- if(!memcmp(address, &cache_mac_address[i], sizeof *address))
+ if(!memcmp(address, &cache_mac_address[i], sizeof(*address)))
return cache_mac_subnet[i];
}
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->status.reachable)
break;
// Cache the result
cache_mac_slot = !cache_mac_slot;
- memcpy(&cache_mac_address[cache_mac_slot], address, sizeof *address);
+ memcpy(&cache_mac_address[cache_mac_slot], address, sizeof(*address));
cache_mac_subnet[cache_mac_slot] = r;
cache_mac_valid[cache_mac_slot] = true;
for(i = 0; i < 2; i++) {
if(!cache_ipv4_valid[i])
continue;
- if(!memcmp(address, &cache_ipv4_address[i], sizeof *address))
+ if(!memcmp(address, &cache_ipv4_address[i], sizeof(*address)))
return cache_ipv4_subnet[i];
}
// Cache the result
cache_ipv4_slot = !cache_ipv4_slot;
- memcpy(&cache_ipv4_address[cache_ipv4_slot], address, sizeof *address);
+ memcpy(&cache_ipv4_address[cache_ipv4_slot], address, sizeof(*address));
cache_ipv4_subnet[cache_ipv4_slot] = r;
cache_ipv4_valid[cache_ipv4_slot] = true;
for(i = 0; i < 2; i++) {
if(!cache_ipv6_valid[i])
continue;
- if(!memcmp(address, &cache_ipv6_address[i], sizeof *address))
+ if(!memcmp(address, &cache_ipv6_address[i], sizeof(*address)))
return cache_ipv6_subnet[i];
}
// Cache the result
cache_ipv6_slot = !cache_ipv6_slot;
- memcpy(&cache_ipv6_address[cache_ipv6_slot], address, sizeof *address);
+ memcpy(&cache_ipv6_address[cache_ipv6_slot], address, sizeof(*address));
cache_ipv6_subnet[cache_ipv6_slot] = r;
cache_ipv6_valid[cache_ipv6_slot] = true;
if(!subnet) {
for(node = owner->subnet_tree->head; node; node = node->next) {
subnet = node->data;
- 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
char *weight = strchr(netstr, '#');
execute_script(name, envp);
}
} 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(node = subnet_tree->head; node; node = node->next) {
subnet = node->data;
- if(!net2str(netstr, sizeof netstr, subnet))
+ if(!net2str(netstr, sizeof(netstr), subnet))
continue;
logger(LOG_DEBUG, " %s owner %s", netstr, subnet->owner->name);
}
} else
fprintf(stderr, "Done.\n");
- snprintf(filename, sizeof filename, "%s/rsa_key.priv", confbase);
+ snprintf(filename, sizeof(filename), "%s/rsa_key.priv", confbase);
f = ask_and_open(filename, "private RSA key");
if(!f) {
char *name = get_name();
if(name) {
- snprintf(filename, sizeof filename, "%s/hosts/%s", confbase, name);
+ snprintf(filename, sizeof(filename), "%s/hosts/%s", confbase, name);
free(name);
} else {
- snprintf(filename, sizeof filename, "%s/rsa_key.pub", confbase);
+ snprintf(filename, sizeof(filename), "%s/rsa_key.pub", confbase);
}
f = ask_and_open(filename, "public RSA key");
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(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(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(LOG_ERR, "Could not bind data %s: %s", device_info, strerror(errno));
running = false;
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(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(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((lenin = read(request_fd, &request, sizeof request)) != sizeof request) {
+ if((lenin = read(request_fd, &request, sizeof(request))) != sizeof request) {
logger(LOG_ERR, "Error while reading request from %s %s: %s", device_info,
device, strerror(errno));
running = false;
return false;
}
- if(connect(write_fd, &request.sock, sizeof request.sock) < 0) {
+ if(connect(write_fd, &request.sock, sizeof(request.sock)) < 0) {
logger(LOG_ERR, "Could not bind write %s: %s", device_info, strerror(errno));
running = false;
return false;
}
- write(request_fd, &data_sun, sizeof data_sun);
+ write(request_fd, &data_sun, sizeof(data_sun));
device_fd = data_fd;
logger(LOG_INFO, "Connection with UML established");
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;
}
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);