changeset 37:6a27e2f8816e draft

Clean up warnings on Sparc/Linux
author Roy Marples <roy@marples.name>
date Mon, 18 Dec 2006 14:30:32 +0000
parents 7b9e6ee0286f
children 525c585a08b6
files interface.c socket.c
diffstat 2 files changed, 37 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/interface.c	Mon Dec 18 10:28:32 2006 +0000
+++ b/interface.c	Mon Dec 18 14:30:32 2006 +0000
@@ -53,6 +53,7 @@
 #endif
 
 #include <errno.h>
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -373,7 +374,11 @@
   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 @@
 	  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 @@
 	    }
 
 	  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 @@
 	  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 @@
 }
 
 #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 @@
   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);
--- a/socket.c	Mon Dec 18 10:28:32 2006 +0000
+++ b/socket.c	Mon Dec 18 14:30:32 2006 +0000
@@ -507,7 +507,11 @@
 		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 @@
       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 @@
   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