]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Clean up warnings on Sparc/Linux
authorRoy Marples <roy@marples.name>
Mon, 18 Dec 2006 14:30:32 +0000 (14:30 +0000)
committerRoy Marples <roy@marples.name>
Mon, 18 Dec 2006 14:30:32 +0000 (14:30 +0000)
interface.c
socket.c

index ea9d674ccf01d5f058b7907d97d35d78298b626f..e2b5041f587384f9da62f03a633f2166581099db 100644 (file)
@@ -53,6 +53,7 @@
 #endif
 
 #include <errno.h>
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -373,7 +374,11 @@ static int send_netlink(struct nlmsghdr *hdr)
   struct msghdr msg;
   static unsigned int seq;
   char buffer[16384];
-  struct nlmsghdr *h;
+  union
+  {
+    char *buffer;
+    struct nlmsghdr *nlm;
+  } h;
 
   if ((s = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) 
     {
@@ -438,10 +443,10 @@ static int send_netlink(struct nlmsghdr *hdr)
          goto eexit;
        }
 
-      for (h = (struct nlmsghdr *) buffer; bytes >= (signed) sizeof (*h); )
+      for (h.buffer = buffer; bytes >= (signed) sizeof (*h.nlm); )
        {
-         int len = h->nlmsg_len;
-         int l = len - sizeof (*h);
+         int len = h.nlm->nlmsg_len;
+         int l = len - sizeof (*h.nlm);
 
          if (l < 0 || len > bytes)
            {
@@ -453,15 +458,15 @@ static int send_netlink(struct nlmsghdr *hdr)
            }
 
          if (nl.nl_pid != 0 ||
-             (pid_t) h->nlmsg_pid != mypid ||
-             h->nlmsg_seq != seq)
+             (pid_t) h.nlm->nlmsg_pid != mypid ||
+             h.nlm->nlmsg_seq != seq)
            /* Message isn't for us, so skip it */
            goto next;
 
          /* We get an NLMSG_ERROR back with a code of zero for success */
-         if (h->nlmsg_type == NLMSG_ERROR)
+         if (h.nlm->nlmsg_type == NLMSG_ERROR)
            {
-             struct nlmsgerr *err = (struct nlmsgerr *) NLMSG_DATA (h);
+             struct nlmsgerr *err = (struct nlmsgerr *) NLMSG_DATA (h.nlm);
              if ((unsigned) l < sizeof (struct nlmsgerr))
                logger (LOG_ERR, "truncated error message");
              else
@@ -483,7 +488,7 @@ static int send_netlink(struct nlmsghdr *hdr)
          logger (LOG_ERR, "unexpected reply");
 next:
          bytes -= NLMSG_ALIGN (len);
-         h = (struct nlmsghdr *) ((char *) h + NLMSG_ALIGN (len));
+         h.buffer += NLMSG_ALIGN (len);
        }
 
       if (msg.msg_flags & MSG_TRUNC)
@@ -505,10 +510,10 @@ eexit:
 }
 
 #define NLMSG_TAIL(nmsg) \
- ((struct rtattr *) (((unsigned char *) (nmsg)) \
-                    + NLMSG_ALIGN((nmsg)->nlmsg_len)))
-static int add_attr_l(struct nlmsghdr *n, unsigned int maxlen, int type, const void *data,
-                     int alen)
+  ((struct rtattr *) (((ptrdiff_t) (nmsg)) + NLMSG_ALIGN ((nmsg)->nlmsg_len)))
+
+static int add_attr_l(struct nlmsghdr *n, unsigned int maxlen, int type,
+                     const void *data, int alen)
 {
   int len = RTA_LENGTH(alen);
   struct rtattr *rta;
@@ -528,10 +533,12 @@ static int add_attr_l(struct nlmsghdr *n, unsigned int maxlen, int type, const v
   return 0;
 }
 
-static int add_attr_32(struct nlmsghdr *n, unsigned int maxlen, int type, uint32_t data)
+static int add_attr_32(struct nlmsghdr *n, unsigned int maxlen, int type,
+                      uint32_t data)
 {
   int len = RTA_LENGTH (sizeof (uint32_t));
   struct rtattr *rta;
+  
   if (NLMSG_ALIGN (n->nlmsg_len) + len > maxlen)
     {
       logger (LOG_ERR, "add_attr32: message exceeded bound of %d\n", maxlen);
index 3c4cd4ac4151450b3c4fe895f9a2d86d8f63aba9..88fcafe3aca6749631be28b3ab9194eadc8b8baa 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -507,7 +507,11 @@ int get_packet (const interface_t *iface, unsigned char *data,
                unsigned char *buffer, int *buffer_len, int *buffer_pos)
 {
   long bytes;
-  struct udp_dhcp_packet *dhcp;
+  union
+  {
+      unsigned char *buffer;
+      struct udp_dhcp_packet *packet;
+  } pay;
 
   /* We don't use the given buffer, but we need to rewind the position */
   *buffer_pos = 0;
@@ -535,21 +539,22 @@ int get_packet (const interface_t *iface, unsigned char *data,
       return -1;
     }
 
-  dhcp = (struct udp_dhcp_packet *) buffer;
-  if (bytes < ntohs (dhcp->ip.ip_len))
+  pay.buffer = buffer;
+  if (bytes < ntohs (pay.packet->ip.ip_len))
     {
       logger (LOG_DEBUG, "truncated packet, ignoring");
       return -1;
     }
 
-  bytes = ntohs (dhcp->ip.ip_len);
+  bytes = ntohs (pay.packet->ip.ip_len);
 
   /* This is like our BPF filter above */
-  if (dhcp->ip.ip_p != IPPROTO_UDP || dhcp->ip.ip_v != IPVERSION ||
-      dhcp->ip.ip_hl != sizeof (dhcp->ip) >> 2 ||
-      dhcp->udp.uh_dport != htons (DHCP_CLIENT_PORT) ||
+  if (pay.packet->ip.ip_p != IPPROTO_UDP || pay.packet->ip.ip_v != IPVERSION ||
+      pay.packet->ip.ip_hl != sizeof (pay.packet->ip) >> 2 ||
+      pay.packet->udp.uh_dport != htons (DHCP_CLIENT_PORT) ||
       bytes > (int) sizeof (struct udp_dhcp_packet) ||
-      ntohs (dhcp->udp.uh_ulen) != (uint16_t) (bytes - sizeof (dhcp->ip)))
+      ntohs (pay.packet->udp.uh_ulen)
+      != (uint16_t) (bytes - sizeof (pay.packet->ip)))
     {
       return -1;
     }
@@ -557,10 +562,10 @@ int get_packet (const interface_t *iface, unsigned char *data,
   if (valid_dhcp_packet (buffer) < 0)
     return -1;
 
-  memcpy(data, &dhcp->dhcp, bytes - (sizeof (dhcp->ip) +
-                                    sizeof (dhcp->udp)));
+  memcpy(data, &pay.packet->dhcp,
+  bytes - (sizeof (pay.packet->ip) + sizeof (pay.packet->udp)));
 
-  return bytes - (sizeof (dhcp->ip) + sizeof (dhcp->udp));
+  return bytes - (sizeof (pay.packet->ip) + sizeof (pay.packet->udp));
 }
 
 #else