]> git.meshlink.io Git - meshlink/commitdiff
Remove unnecessary parentheses from sizeof, apply sizeof to variables instead of...
authorGuus Sliepen <guus@tinc-vpn.org>
Thu, 11 Dec 2008 15:56:18 +0000 (15:56 +0000)
committerGuus Sliepen <guus@tinc-vpn.org>
Thu, 11 Dec 2008 15:56:18 +0000 (15:56 +0000)
19 files changed:
src/bsd/device.c
src/conf.c
src/control.c
src/cygwin/device.c
src/linux/device.c
src/logger.c
src/mingw/device.c
src/net.c
src/net_packet.c
src/net_socket.c
src/netutl.c
src/node.c
src/protocol.c
src/protocol_key.c
src/raw_socket/device.c
src/route.c
src/subnet.c
src/tincctl.c
src/tincd.c

index 70f4757fedbf5669e1b75c834df1072bc4ab06cd..35038c74d16f2b0df3a109550c85b624095d8ce4 100644 (file)
@@ -175,7 +175,7 @@ bool read_packet(vpn_packet_t *packet) {
 
                case DEVICE_TYPE_TUNIFHEAD: {
                        u_int32_t type;
-                       struct iovec vector[2] = {{&type, sizeof(type)}, {packet->data + 14, MTU - 14}};
+                       struct iovec vector[2] = {{&type, sizeof type}, {packet->data + 14, MTU - 14}};
 
                        if((inlen = readv(device_fd, vector, 2)) <= 0) {
                                logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
@@ -244,7 +244,7 @@ bool write_packet(vpn_packet_t *packet) {
 
                case DEVICE_TYPE_TUNIFHEAD: {
                        u_int32_t type;
-                       struct iovec vector[2] = {{&type, sizeof(type)}, {packet->data + 14, packet->len - 14}};
+                       struct iovec vector[2] = {{&type, sizeof type}, {packet->data + 14, packet->len - 14}};
                        int af;
                        
                        af = (packet->data[12] << 8) + packet->data[13];
index 5dc7017191c6f15d857201c4aaf8ad819741a383..1b0ac641fceda969305e347da768cd27eff6a6b8 100644 (file)
@@ -218,9 +218,9 @@ bool get_config_subnet(const config_t *cfg, subnet_t ** result) {
        /* Teach newbies what subnets are... */
 
        if(((subnet.type == SUBNET_IPV4)
-               && !maskcheck(&subnet.net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof(ipv4_t)))
+               && !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(ipv6_t)))) {
+               && !maskcheck(&subnet.net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof subnet.net.ipv6.address))) {
                logger(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;
index 35d7d85ff4a3359f1b11672079f855066bd88a1f..19f074a6a691136b8ea1fa6257085de5a54af929 100644 (file)
@@ -40,17 +40,17 @@ static void handle_control_data(struct bufferevent *event, void *data) {
        struct evbuffer *res_data = NULL;
        void *req_data;
 
-       if(EVBUFFER_LENGTH(event->input) < sizeof(tinc_ctl_request_t))
+       if(EVBUFFER_LENGTH(event->input) < sizeof req)
                return;
 
        /* Copy the structure to ensure alignment */
-       memcpy(&req, EVBUFFER_DATA(event->input), sizeof(tinc_ctl_request_t));
+       memcpy(&req, EVBUFFER_DATA(event->input), sizeof req);
 
        if(EVBUFFER_LENGTH(event->input) < req.length)
                return;
-       req_data = EVBUFFER_DATA(event->input) + sizeof(tinc_ctl_request_t);
+       req_data = EVBUFFER_DATA(event->input) + sizeof req;
 
-       if(req.length < sizeof(tinc_ctl_request_t))
+       if(req.length < sizeof req)
                goto failure;
 
        memset(&res, 0, sizeof res);
@@ -109,10 +109,10 @@ static void handle_control_data(struct bufferevent *event, void *data) {
                debug_t new_debug_level;
 
                logger(LOG_NOTICE, _("Got '%s' command"), "debug");
-               if(req.length != sizeof(req) + sizeof debug_level)
+               if(req.length != sizeof req + sizeof debug_level)
                        res.res_errno = EINVAL;
                else {
-                       memcpy(&new_debug_level, req_data, sizeof(debug_t));
+                       memcpy(&new_debug_level, req_data, sizeof new_debug_level);
                        logger(LOG_NOTICE, _("Changing debug level from %d to %d"),
                                   debug_level, new_debug_level);
                        if(evbuffer_add_printf(res_data,
index c4c85d8083a4923683d00cc1675ef3d147308919..6b0dbea4819f782da832be2dd0b2dc86f901c5bb 100644 (file)
@@ -72,18 +72,18 @@ bool setup_device(void) {
        }
 
        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);
@@ -107,7 +107,7 @@ bool setup_device(void) {
                                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);
@@ -129,7 +129,7 @@ bool setup_device(void) {
        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.
@@ -153,7 +153,7 @@ bool setup_device(void) {
 
        /* 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(LOG_ERR, _("Could not get MAC address from Windows tap device %s (%s): %s"), device, iface, winerror(GetLastError()));
                return false;
        }
index 90ba384921fe337bd374be6fca086626886ddd63..5be210a582f6eb2b33b8916fab0b8b92dcd9b229 100644 (file)
@@ -75,7 +75,7 @@ bool setup_device(void) {
 #ifdef HAVE_LINUX_IF_TUN_H
        /* Ok now check if this is an old ethertap or a new tun/tap thingie */
 
-       memset(&ifr, 0, sizeof(ifr));
+       memset(&ifr, 0, sizeof ifr);
        if(routing_mode == RMODE_ROUTER) {
                ifr.ifr_flags = IFF_TUN;
                device_type = DEVICE_TYPE_TUN;
index 8e73a6d3759376eccc2ff0301ae99152c8b8f673..effcb7887b883f6259eddf4e72ef3161aa2e1e70 100644 (file)
@@ -88,7 +88,7 @@ void logger(int priority, const char *format, ...) {
                        {
                                char message[4096];
                                char *messages[] = {message};
-                               vsnprintf(message, sizeof(message), format, ap);
+                               vsnprintf(message, sizeof message, format, ap);
                                ReportEvent(loghandle, priority, 0, 0, NULL, 1, 0, messages, NULL);
                        }
 #else
@@ -98,7 +98,7 @@ void logger(int priority, const char *format, ...) {
 #else
                        {
                                char message[4096];
-                               vsnprintf(message, sizeof(message), format, ap);
+                               vsnprintf(message, sizeof message, format, ap);
                                syslog(priority, "%s", message);
                        }
 #endif
index b3cbe3b327c9732a422892b5b6ee6248708deb77..d6dde92d6d2e990db7f4ad65ce47510121665ac9 100644 (file)
@@ -160,18 +160,18 @@ bool setup_device(void) {
        }
 
        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);
@@ -195,7 +195,7 @@ bool setup_device(void) {
                                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;
@@ -219,7 +219,7 @@ bool setup_device(void) {
        /* 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);
        }
        
@@ -230,7 +230,7 @@ bool setup_device(void) {
 
        /* 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(LOG_ERR, _("Could not get MAC address from Windows tap device %s (%s): %s"), device, iface, winerror(GetLastError()));
                return false;
        }
@@ -298,7 +298,7 @@ bool setup_device(void) {
        /* Set media status for newer TAP-Win32 devices */
 
        status = true;
-       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);
 
        device_info = _("Windows tap device");
 
index b811754aacf221d5de67614bdded2f510509716d..659b0784418cb8107eb977c36b9fcf63c2feb5e1 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -203,7 +203,7 @@ static void timeout_handler(int fd, short events, void *event) {
 void handle_meta_connection_data(int fd, short events, void *data) {
        connection_t *c = data;
        int result;
-       socklen_t len = sizeof(result);
+       socklen_t len = sizeof result;
 
        if(c->status.connecting) {
                c->status.connecting = false;
index eee3972e16135a54bb0fcc72f89ac29b971d167c..754e669964ca58a5e5153fb56aa5c8e67e5268c4 100644 (file)
@@ -171,7 +171,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
 
        /* Check packet length */
 
-       if(inpkt->len < sizeof(inpkt->seqno) + digest_length(&myself->digest)) {
+       if(inpkt->len < sizeof inpkt->seqno + digest_length(&myself->digest)) {
                ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Got too short packet from %s (%s)"),
                                        n->name, n->hostname);
                return;
@@ -201,28 +201,28 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
 
        /* Check the sequence number */
 
-       inpkt->len -= sizeof(inpkt->seqno);
+       inpkt->len -= sizeof inpkt->seqno;
        inpkt->seqno = ntohl(inpkt->seqno);
 
        if(inpkt->seqno != n->received_seqno + 1) {
-               if(inpkt->seqno >= n->received_seqno + sizeof(n->late) * 8) {
+               if(inpkt->seqno >= n->received_seqno + sizeof n->late * 8) {
                        logger(LOG_WARNING, _("Lost %d packets from %s (%s)"),
                                           inpkt->seqno - n->received_seqno - 1, n->name, n->hostname);
                        
-                       memset(n->late, 0, sizeof(n->late));
+                       memset(n->late, 0, sizeof n->late);
                } else if (inpkt->seqno <= n->received_seqno) {
-                       if((n->received_seqno >= sizeof(n->late) * 8 && inpkt->seqno <= n->received_seqno - sizeof(n->late) * 8) || !(n->late[(inpkt->seqno / 8) % sizeof(n->late)] & (1 << inpkt->seqno % 8))) {
+                       if((n->received_seqno >= sizeof n->late * 8 && inpkt->seqno <= n->received_seqno - sizeof n->late * 8) || !(n->late[(inpkt->seqno / 8) % sizeof n->late] & (1 << inpkt->seqno % 8))) {
                                logger(LOG_WARNING, _("Got late or replayed packet from %s (%s), seqno %d, last received %d"),
                                           n->name, n->hostname, inpkt->seqno, n->received_seqno);
                                return;
                        }
                } else {
                        for(i = n->received_seqno + 1; i < inpkt->seqno; i++)
-                               n->late[(i / 8) % sizeof(n->late)] |= 1 << i % 8;
+                               n->late[(i / 8) % sizeof n->late] |= 1 << i % 8;
                }
        }
        
-       n->late[(inpkt->seqno / 8) % sizeof(n->late)] &= ~(1 << inpkt->seqno % 8);
+       n->late[(inpkt->seqno / 8) % sizeof n->late] &= ~(1 << inpkt->seqno % 8);
 
        if(inpkt->seqno > n->received_seqno)
                n->received_seqno = inpkt->seqno;
@@ -285,7 +285,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
 
                /* Since packet is on the stack of handle_tap_input(), we have to make a copy of it first. */
 
-               *(copy = xmalloc(sizeof(*copy))) = *inpkt;
+               *(copy = xmalloc(sizeof *copy)) = *inpkt;
 
                list_insert_tail(n->queue, copy);
 
@@ -320,7 +320,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
        /* Add sequence number */
 
        inpkt->seqno = htonl(++(n->sent_seqno));
-       inpkt->len += sizeof(inpkt->seqno);
+       inpkt->len += sizeof inpkt->seqno;
 
        /* Encrypt the packet */
 
@@ -360,7 +360,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
           && listen_socket[sock].sa.sa.sa_family == AF_INET) {
                priority = origpriority;
                ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Setting outgoing packet priority to %d"), priority);
-               if(setsockopt(listen_socket[sock].udp, SOL_IP, IP_TOS, &priority, sizeof(priority)))    /* SO_PRIORITY doesn't seem to work */
+               if(setsockopt(listen_socket[sock].udp, SOL_IP, IP_TOS, &priority, sizeof priority))     /* SO_PRIORITY doesn't seem to work */
                        logger(LOG_ERR, _("System call `%s' failed: %s"), "setsockopt", strerror(errno));
        }
 #endif
@@ -456,7 +456,7 @@ void handle_incoming_vpn_data(int sock, short events, void *data) {
        vpn_packet_t pkt;
        char *hostname;
        sockaddr_t from;
-       socklen_t fromlen = sizeof(from);
+       socklen_t fromlen = sizeof from;
        node_t *n;
 
        cp();
index c2c1da968f459d43d0646053a974dec545b195a2..44b7ec7829d58f8b139f02d089607caa362468f0 100644 (file)
@@ -70,12 +70,12 @@ static void configure_tcp(connection_t *c) {
 
 #if defined(SOL_TCP) && defined(TCP_NODELAY)
        option = 1;
-       setsockopt(c->socket, SOL_TCP, TCP_NODELAY, &option, sizeof(option));
+       setsockopt(c->socket, SOL_TCP, TCP_NODELAY, &option, sizeof option);
 #endif
 
 #if defined(SOL_IP) && defined(IP_TOS) && defined(IPTOS_LOWDELAY)
        option = IPTOS_LOWDELAY;
-       setsockopt(c->socket, SOL_IP, IP_TOS, &option, sizeof(option));
+       setsockopt(c->socket, SOL_IP, IP_TOS, &option, sizeof option);
 #endif
 }
 
@@ -97,17 +97,17 @@ int setup_listen_socket(const sockaddr_t *sa) {
        /* Optimize TCP settings */
 
        option = 1;
-       setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option));
+       setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof option);
 
        if(get_config_string
           (lookup_config(config_tree, "BindToInterface"), &iface)) {
 #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, &ifr, sizeof(ifr))) {
+               if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof ifr)) {
                        closesocket(nfd);
                        logger(LOG_ERR, _("Can't bind to interface %s: %s"), iface,
                                   strerror(errno));
@@ -175,7 +175,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa) {
 #endif
 
        option = 1;
-       setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option));
+       setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof option);
 
 #if defined(SOL_IP) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO)
        {
@@ -183,7 +183,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa) {
 
                if(get_config_bool(lookup_config(myself->connection->config_tree, "PMTUDiscovery"), &choice) && choice) {
                        option = IP_PMTUDISC_DO;
-                       setsockopt(nfd, SOL_IP, IP_MTU_DISCOVER, &option, sizeof(option));
+                       setsockopt(nfd, SOL_IP, IP_MTU_DISCOVER, &option, sizeof option);
                }
        }
 #endif
@@ -194,7 +194,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa) {
 
                if(get_config_bool(lookup_config(myself->connection->config_tree, "PMTUDiscovery"), &choice) && choice) {
                        option = IPV6_PMTUDISC_DO;
-                       setsockopt(nfd, SOL_IPV6, IPV6_MTU_DISCOVER, &option, sizeof(option));
+                       setsockopt(nfd, SOL_IPV6, IPV6_MTU_DISCOVER, &option, sizeof option);
                }
        }
 #endif
@@ -205,10 +205,10 @@ int setup_vpn_in_socket(const sockaddr_t *sa) {
                struct ifreq ifr;
 
                if(get_config_string(lookup_config(config_tree, "BindToInterface"), &iface)) {
-                       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, &ifr, sizeof(ifr))) {
+                       if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof ifr)) {
                                closesocket(nfd);
                                logger(LOG_ERR, _("Can't bind to interface %s: %s"), iface,
                                           strerror(errno));
@@ -426,7 +426,7 @@ void handle_new_meta_connection(int sock, short events, void *data) {
        connection_t *c;
        sockaddr_t sa;
        int fd;
-       socklen_t len = sizeof(sa);
+       socklen_t len = sizeof sa;
 
        cp();
 
@@ -488,7 +488,7 @@ void try_outgoing_connections(void) {
                        continue;
                }
 
-               outgoing = xmalloc_and_zero(sizeof(*outgoing));
+               outgoing = xmalloc_and_zero(sizeof *outgoing);
                outgoing->name = name;
                setup_outgoing_connection(outgoing);
        }
index ca30ec49c7157e8b4c4a93349d452b11179f0536..116d858d41f194ac53599d9803fbbc26b6229d80 100644 (file)
@@ -96,7 +96,7 @@ void sockaddr2str(const sockaddr_t *sa, char **addrstr, char **portstr) {
                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(LOG_ERR, _("Error while translating addresses: %s"),
@@ -128,7 +128,7 @@ char *sockaddr2hostname(const sockaddr_t *sa) {
                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(LOG_ERR, _("Error while looking up hostname: %s"),
@@ -163,20 +163,20 @@ int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b) {
                        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(LOG_ERR, _("sockaddrcmp() was called with unknown address family %d, exitting!"),
index 99bbb6db1cf200bca7f940b033e20a6948d4d718..5ddd8f36d41ce816c18935ced754e1894f216beb 100644 (file)
@@ -67,7 +67,7 @@ void exit_nodes(void) {
 }
 
 node_t *new_node(void) {
-       node_t *n = xmalloc_and_zero(sizeof(*n));
+       node_t *n = xmalloc_and_zero(sizeof *n);
 
        cp();
 
index cae3a0fe93f218d19915e4a6ac0dd75b1588dbdd..24ba88b9c9741719a0c6b625eedec9c0a7a73bac 100644 (file)
@@ -196,7 +196,7 @@ bool seen_request(char *request) {
                ifdebug(SCARY_THINGS) logger(LOG_DEBUG, _("Already seen request"));
                return true;
        } else {
-               new = xmalloc(sizeof(*new));
+               new = xmalloc(sizeof *new);
                new->request = xstrdup(request);
                new->firstseen = time(NULL);
                splay_insert(past_request_tree, new);
index 71f28bf744e9e19a01d7d10263d5ceb6e976609f..0cd840be1822ce49bd0dece3b3adb363f60edb4c 100644 (file)
@@ -122,7 +122,7 @@ bool req_key_h(connection_t *c, char *request) {
        if(to == myself) {                      /* Yes, send our own key back */
                mykeyused = true;
                from->received_seqno = 0;
-               memset(from->late, 0, sizeof(from->late));
+               memset(from->late, 0, sizeof from->late);
                send_ans_key(c, myself, from);
        } else {
                if(tunnelserver)
index c246d1bb0e7b2b5f615210328315c7353d9b8c06..3694cb128e7a95c50e03f0bd80a06bbe28b00cdc 100644 (file)
@@ -60,7 +60,7 @@ bool setup_device(void) {
                return false;
        }
 
-       memset(&ifr, 0, sizeof(ifr));
+       memset(&ifr, 0, sizeof ifr);
        strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ);
        if(ioctl(device_fd, SIOCGIFINDEX, &ifr)) {
                close(device_fd);
@@ -69,12 +69,12 @@ bool setup_device(void) {
                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(LOG_ERR, _("Could not bind %s to %s: %s"), device, iface, strerror(errno));
                return false;
        }
index dbe38dfbf2f0206a6984199fa8976b7593d5c942..f3622f59c195b08c47ef5941c94c1f0c360a9146 100644 (file)
@@ -457,7 +457,7 @@ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t
 
        /* 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(packet->data + ether_size + ip6_size + icmp6_size, ntohl(pseudo.length) - icmp6_size, checksum);
 
@@ -575,7 +575,7 @@ static void route_neighborsol(node_t *source, vpn_packet_t *packet)
 
        /* Generate checksum */
 
-       checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
+       checksum = inet_checksum(&pseudo, sizeof pseudo, ~0);
        checksum = inet_checksum(&ns, ns_size, checksum);
        checksum = inet_checksum(&opt, opt_size, checksum);
        checksum = inet_checksum(packet->data + ether_size + ip6_size + ns_size + opt_size, ETH_ALEN, checksum);
@@ -632,7 +632,7 @@ static void route_neighborsol(node_t *source, vpn_packet_t *packet)
 
        /* Generate checksum */
 
-       checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
+       checksum = inet_checksum(&pseudo, sizeof pseudo, ~0);
        checksum = inet_checksum(&ns, ns_size, checksum);
        checksum = inet_checksum(&opt, opt_size, checksum);
        checksum = inet_checksum(packet->data + ether_size + ip6_size + ns_size + opt_size, ETH_ALEN, checksum);
@@ -693,7 +693,7 @@ static void route_arp(node_t *source, vpn_packet_t *packet)
        /* 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) {
                ifdebug(TRAFFIC) logger(LOG_WARNING, _("Cannot route packet: received unknown type ARP request"));
                return;
        }
@@ -717,9 +717,9 @@ static void route_arp(node_t *source, vpn_packet_t *packet)
        memcpy(packet->data, packet->data + ETH_ALEN, ETH_ALEN);        /* copy destination address */
        packet->data[ETH_ALEN * 2 - 1] ^= 0xFF; /* mangle source address so it looks like it's not from us */
 
-       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, packet->data + ETH_ALEN, ETH_ALEN); /* add fake source hard addr */
index 46006a169dec15ac98f295ca2ecbd9574e6effd7..d820227b1ed686ae703bcdb053a1e654441a53c2 100644 (file)
@@ -43,7 +43,7 @@ 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(mac_t));
+       result = memcmp(&a->net.mac.address, &b->net.mac.address, sizeof a->net.mac.address);
 
        if(result || !a->owner || !b->owner)
                return result;
@@ -55,7 +55,7 @@ static int subnet_compare_ipv4(const subnet_t *a, const subnet_t *b)
 {
        int result;
 
-       result = memcmp(&a->net.ipv4.address, &b->net.ipv4.address, sizeof(ipv4_t));
+       result = memcmp(&a->net.ipv4.address, &b->net.ipv4.address, sizeof a->net.ipv4.address);
 
        if(result)
                return result;
@@ -72,7 +72,7 @@ static int subnet_compare_ipv6(const subnet_t *a, const subnet_t *b)
 {
        int result;
 
-       result = memcmp(&a->net.ipv6.address, &b->net.ipv6.address, sizeof(ipv6_t));
+       result = memcmp(&a->net.ipv6.address, &b->net.ipv6.address, sizeof a->net.ipv6.address);
 
        if(result)
                return result;
@@ -368,7 +368,7 @@ subnet_t *lookup_subnet_ipv4(const ipv4_t *address)
                                subnet.net.ipv4.prefixlength = p->net.ipv4.prefixlength - 1;
                                if(subnet.net.ipv4.prefixlength < 0 || subnet.net.ipv4.prefixlength > 32)
                                        return NULL;
-                               maskcpy(&subnet.net.ipv4.address, &p->net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof(ipv4_t));
+                               maskcpy(&subnet.net.ipv4.address, &p->net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof subnet.net.ipv4.address);
                        }
                }
        } while(p);
@@ -406,7 +406,7 @@ subnet_t *lookup_subnet_ipv6(const ipv6_t *address)
                                subnet.net.ipv6.prefixlength = p->net.ipv6.prefixlength - 1;
                                if(subnet.net.ipv6.prefixlength < 0 || subnet.net.ipv6.prefixlength > 128)
                                        return NULL;
-                               maskcpy(&subnet.net.ipv6.address, &p->net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof(ipv6_t));
+                               maskcpy(&subnet.net.ipv6.address, &p->net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof subnet.net.ipv6.address);
                        }
                }
        } while(p);
index 38bc4cf77b00e7b52e326c75270a6850d5899658..7cfc62e5f382bac67cdcfba5d93090dbf61e471c 100644 (file)
@@ -292,7 +292,7 @@ static void make_names(void) {
 #ifdef HAVE_MINGW
        HKEY key;
        char installdir[1024] = "";
-       long len = sizeof(installdir);
+       long len = sizeof installdir;
 #endif
 
        if(netname)
@@ -360,7 +360,7 @@ static int send_ctl_request(int fd, enum request_type type,
        tinc_ctl_request_t req;
        int rv;
        struct iovec vector[2] = {
-               {&req, sizeof(req)},
+               {&req, sizeof req},
                {(void*) outdata, outdatalen}
        };
        void *indata;
@@ -611,7 +611,7 @@ int main(int argc, char *argv[], char *envp[]) {
                }
                debuglevel = atoi(argv[optind+1]);
                return send_ctl_request_cooked(fd, REQ_SET_DEBUG, &debuglevel,
-                                                                          sizeof(debuglevel)) != -1;
+                                                                          sizeof debuglevel) != -1;
        }
 
        if(!strcasecmp(argv[optind], "retry")) {
index 0f78e45a6239e3a02625d7309d04eb44e6be9cdd..3e3b7b0dfd9586b435912958d2c275c2f9a70fca 100644 (file)
@@ -186,7 +186,7 @@ static void make_names(void)
 #ifdef HAVE_MINGW
        HKEY key;
        char installdir[1024] = "";
-       long len = sizeof(installdir);
+       long len = sizeof installdir;
 #endif
 
        if(netname)