]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Use sizeof with the variable, not the declaration more.
authorRoy Marples <roy@marples.name>
Mon, 28 Jan 2008 17:47:54 +0000 (17:47 +0000)
committerRoy Marples <roy@marples.name>
Mon, 28 Jan 2008 17:47:54 +0000 (17:47 +0000)
arp.c
client.c
configure.c
dhcp.c
info.c
interface.c
socket.c

diff --git a/arp.c b/arp.c
index 01ce1e786689ad615a93d3e4ea118e1a2d83c1b3..542fe07a77461550efbe7688e4b8588d358950ff 100644 (file)
--- a/arp.c
+++ b/arp.c
@@ -77,7 +77,7 @@ static int send_arp (const interface_t *iface, int op, struct in_addr sip,
                     const unsigned char *taddr, struct in_addr tip)
 {
        struct arphdr *arp;
-       size_t arpsize = arphdr_len2 (iface->hwlen, sizeof (struct in_addr));
+       size_t arpsize = arphdr_len2 (iface->hwlen, sizeof (sip));
        caddr_t tha;
        int retval;
 
@@ -85,7 +85,7 @@ static int send_arp (const interface_t *iface, int op, struct in_addr sip,
        arp->ar_hrd = htons (iface->family);
        arp->ar_pro = htons (ETHERTYPE_IP);
        arp->ar_hln = iface->hwlen;
-       arp->ar_pln = sizeof (struct in_addr);
+       arp->ar_pln = sizeof (sip);
        arp->ar_op = htons (op);
        memcpy (ar_sha (arp), iface->hwaddr, (size_t) arp->ar_hln);
        memcpy (ar_spa (arp), &sip, (size_t) arp->ar_pln);
@@ -134,7 +134,7 @@ int arp_claim (interface_t *iface, struct in_addr address)
        if (! open_socket (iface, ETHERTYPE_ARP))
                return (-1);
 
-       memset (&null_address, 0, sizeof (struct in_addr));
+       memset (&null_address, 0, sizeof (null_address));
 
        buffer = xmalloc (iface->buffer_length);
        reply = xmalloc (iface->buffer_length);
@@ -247,7 +247,7 @@ int arp_claim (interface_t *iface, struct in_addr address)
                        /* Protocol must be IP. */
                        if (reply->ar_pro != htons (ETHERTYPE_IP))
                                continue;
-                       if (reply->ar_pln != sizeof (struct in_addr))
+                       if (reply->ar_pln != sizeof (address))
                                continue;
                        if ((unsigned) bytes < sizeof (reply) + 
                            2 * (4 + reply->ar_hln))
index 061a183c74214c785854283bbe14accf676aa475..6b0c22fefc47b14e767e06a214f1444a9aff1a1e 100644 (file)
--- a/client.c
+++ b/client.c
@@ -921,7 +921,7 @@ static int handle_packet (state_t *state, const options_t *options)
           The benefit is that if we get >1 DHCP packet in our buffer and
           the first one fails for any reason, we can use the next. */
 
-       memset (&message, 0, sizeof (struct dhcpmessage_t));
+       memset (&message, 0, sizeof (message));
        new_dhcp = xmalloc (sizeof (*new_dhcp));
 
        do {
index 476b38b63cd701dd503f9399d52f5ae55264d2ca..47a0e263359945f544b381787e679a6686c70577 100644 (file)
@@ -423,7 +423,7 @@ static char *lookuphostname (char *hostname, const dhcp_t *dhcp,
 
        logger (LOG_DEBUG, "Looking up hostname via DNS");
        addr = xmalloc (sizeof (char) * NI_MAXHOST);
-       salen = sizeof (struct sockaddr);
+       salen = sizeof (su.sa);
        memset (&su.sa, 0, salen);
        su.sin.sin_family = AF_INET;
        memcpy (&su.sin.sin_addr, &dhcp->address, sizeof (su.sin.sin_addr));
diff --git a/dhcp.c b/dhcp.c
index 42b991548007a94ae6a61399f17cb1692187243a..0f49c49b18c8792489466c93987e4bd57a7949c2 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -385,8 +385,8 @@ ssize_t send_message (const interface_t *iface, const dhcp_t *dhcp,
        logger (LOG_DEBUG, "sending %s with xid 0x%x",
                dhcp_message (type), xid);
        retval = send_packet (iface, ETHERTYPE_IP, (unsigned char *) packet,
-                             message_length + sizeof (struct ip) +
-                             sizeof (struct udphdr));
+                             message_length +
+                             sizeof (packet->ip) + sizeof (packet->udp));
        free (packet);
        return (retval);
 }
@@ -535,10 +535,9 @@ static bool dhcp_add_address (address_t **address,
 
        for (i = 0; i < length; i += 4) {
                if (*address == NULL) {
-                       *address = xzalloc (sizeof (address_t));
-                       p = *address;
+                       p = *address = xzalloc (sizeof (*p));
                } else {
-                       p->next = xzalloc (sizeof (address_t));
+                       p->next = xzalloc (sizeof (*p));
                        p = p->next;
                }
 
diff --git a/info.c b/info.c
index 1c8302ee09eed8d4b0b6848a971276cc6a197e4c..e24d87bcd49754dc65398fe29335f4d562db7a1d 100644 (file)
--- a/info.c
+++ b/info.c
@@ -322,7 +322,7 @@ static bool parse_addresses (address_t **address, char *value, const char *var)
        bool retval = true;
 
        while ((token = strsep (&p, " "))) {
-               address_t *a = xzalloc (sizeof (address_t));
+               address_t *a = xzalloc (sizeof (*a));
 
                if (inet_aton (token, &a->address) == 0) {
                        logger (LOG_ERR, "%s: invalid address `%s'", var, token);
index b1e6542a8a80fbb1c99faf7fa6d38fb057ac7559..1aaf48aee6a004107ab7e6ac44685f6f2ca232e9 100644 (file)
@@ -240,7 +240,7 @@ static int _do_interface (const char *ifname,
                ifr = ifreqs.ifr;
 
 #ifdef __linux__
-               p += sizeof (struct ifreq);
+               p += sizeof (*ifr);
 #else
                p += sizeof (ifr->ifr_name) +
                        MAX (ifr->ifr_addr.sa_len, sizeof (struct sockaddr));
@@ -583,12 +583,6 @@ static int do_route (const char *ifname,
                     int change, int del)
 {
        int s;
-       struct rtm 
-       {
-               struct rt_msghdr hdr;
-               char buffer[sizeof (struct sockaddr_storage) * 3];
-       } rtm;
-       char *bp = rtm.buffer;
        static int seq;
        union sockunion {
                struct sockaddr sa;
@@ -599,7 +593,12 @@ static int do_route (const char *ifname,
                struct sockaddr_dl sdl;
                struct sockaddr_storage ss;
        } su;
-
+       struct rtm 
+       {
+               struct rt_msghdr hdr;
+               char buffer[sizeof (su) * 3];
+       } rtm;
+       char *bp = rtm.buffer;
        size_t l;
 
        if (! ifname)
@@ -623,10 +622,10 @@ static int do_route (const char *ifname,
        rtm.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK;
 
 #define ADDADDR(_addr) \
-       memset (&su, 0, sizeof (struct sockaddr_storage)); \
+       memset (&su, 0, sizeof (su)); \
        su.sin.sin_family = AF_INET; \
-       su.sin.sin_len = sizeof (struct sockaddr_in); \
-       memcpy (&su.sin.sin_addr, &_addr, sizeof (struct in_addr)); \
+       su.sin.sin_len = sizeof (su.sin.sin_addr); \
+       memcpy (&su.sin.sin_addr, &_addr, sizeof (su.sin.sin_addr)); \
        l = SA_SIZE (&(su.sa)); \
        memcpy (bp, &(su), l); \
        bp += l;
@@ -645,8 +644,8 @@ static int do_route (const char *ifname,
 
                hwaddr = xmalloc (sizeof (unsigned char) * HWADDR_LEN);
                _do_interface (ifname, hwaddr, &hwlen, NULL, false, false);
-               memset (&su, 0, sizeof (struct sockaddr_storage));
-               su.sdl.sdl_len = sizeof (struct sockaddr_dl);
+               memset (&su, 0, sizeof (su));
+               su.sdl.sdl_len = sizeof (su.sdl);
                su.sdl.sdl_family = AF_LINK;
                su.sdl.sdl_nlen = strlen (ifname);
                memcpy (&su.sdl.sdl_data, ifname, (size_t) su.sdl.sdl_nlen);
@@ -791,7 +790,7 @@ static int send_netlink(struct nlmsghdr *hdr)
                                goto eexit;
                        }
 
-                       if ((unsigned) l < sizeof (struct nlmsgerr)) {
+                       if ((unsigned) l < sizeof (*err)) {
                                logger (LOG_ERR, "netlink: error truncated");
                                goto eexit;
                        }
index 16daceec701acf4b40976c2b1ccdc4eaa82b3f6b..a3af6d24ac165dd511dfc58a601606917e013ab0 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -425,8 +425,8 @@ ssize_t get_packet (const interface_t *iface, unsigned char *data,
                                } pay;
                                pay.buffer = payload;
                                len = ntohs (pay.packet->ip.ip_len) -
-                                       sizeof (struct ip) -
-                                       sizeof (struct udphdr);
+                                       sizeof (pay.packet->ip) -
+                                       sizeof (pay.packet->udp);
                                memcpy (data, &pay.packet->dhcp, len);
                                have_data = true;
                        }
@@ -595,7 +595,9 @@ ssize_t get_packet (const interface_t *iface, unsigned char *data,
                return (bytes);
        }
 
-       if ((unsigned) bytes < (sizeof (struct ip) + sizeof (struct udphdr))) {
+       if ((unsigned) bytes < (sizeof (pay.packet->ip) +
+                               sizeof (pay.packet->udp)))
+       {
                logger (LOG_DEBUG, "message too short, ignoring");
                return (-1);
        }