[pim] Fix net/host byte order
diff --git a/pimd/Makefile.am b/pimd/Makefile.am
index 57bd31a..4aae637 100644
--- a/pimd/Makefile.am
+++ b/pimd/Makefile.am
@@ -53,7 +53,7 @@
 	pim_oil.c pim_zlookup.c pim_pim.c pim_tlv.c pim_neighbor.c \
 	pim_hello.c pim_ifchannel.c pim_join.c pim_assert.c \
 	pim_msg.c pim_upstream.c pim_rpf.c pim_rand.c pim_macro.c \
-	pim_igmp_join.c pim_ssmpingd.c
+	pim_igmp_join.c pim_ssmpingd.c pim_int.c
 
 noinst_HEADERS = \
 	pimd.h pim_version.h pim_cmd.h pim_signals.h pim_iface.h \
@@ -62,7 +62,7 @@
 	pim_oil.h pim_zlookup.h pim_pim.h pim_tlv.h pim_neighbor.h \
 	pim_hello.h pim_ifchannel.h pim_join.h pim_assert.h \
 	pim_msg.h pim_upstream.h pim_rpf.h pim_rand.h pim_macro.h \
-	pim_igmp_join.h pim_ssmpingd.h
+	pim_igmp_join.h pim_ssmpingd.h pim_int.h
 
 pimd_SOURCES = \
 	pim_main.c $(libpim_a_SOURCES)
diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c
index 0ce0e5d..52168d6 100644
--- a/pimd/pim_assert.c
+++ b/pimd/pim_assert.c
@@ -30,6 +30,7 @@
 #include "pim_tlv.h"
 #include "pim_msg.h"
 #include "pim_pim.h"
+#include "pim_int.h"
 #include "pim_time.h"
 #include "pim_iface.h"
 #include "pim_hello.h"
@@ -297,7 +298,7 @@
     Parse assert metric preference
   */
 
-  msg_metric.metric_preference = ntohl(*(const uint32_t *) curr);
+  msg_metric.metric_preference = pim_read_uint32_host(curr);
 
   msg_metric.rpt_bit_flag = msg_metric.metric_preference & 0x80000000; /* save highest bit */
   msg_metric.metric_preference &= ~0x80000000; /* clear highest bit */
@@ -308,7 +309,7 @@
     Parse assert route metric
   */
 
-  msg_metric.route_metric = ntohl(*(const uint32_t *) curr);
+  msg_metric.route_metric = pim_read_uint32_host(curr);
 
   if (PIM_DEBUG_PIM_TRACE) {
     char neigh_str[100];
@@ -378,7 +379,7 @@
   return m1->ip_address.s_addr == m2->ip_address.s_addr;
 }
 
-int pim_assert_build_msg(char *pim_msg, int buf_size,
+int pim_assert_build_msg(uint8_t *pim_msg, int buf_size,
 			 struct interface *ifp,
 			 struct in_addr group_addr,
 			 struct in_addr source_addr,
@@ -386,8 +387,8 @@
 			 uint32_t route_metric,
 			 uint32_t rpt_bit_flag)
 {
-  char *buf_pastend = pim_msg + buf_size;
-  char *pim_msg_curr;
+  uint8_t *buf_pastend = pim_msg + buf_size;
+  uint8_t *pim_msg_curr;
   int pim_msg_size;
   int remain;
 
@@ -420,13 +421,13 @@
   }
 
   /* Metric preference */
-  *((uint32_t *) pim_msg_curr) = htonl(rpt_bit_flag ?
-				       metric_preference | 0x80000000 :
-				       metric_preference);
+  pim_write_uint32(pim_msg_curr, rpt_bit_flag ?
+		   metric_preference | 0x80000000 :
+		   metric_preference);
   pim_msg_curr += 4;
 
   /* Route metric */
-  *((uint32_t *) pim_msg_curr) = htonl(route_metric);
+  pim_write_uint32(pim_msg_curr, route_metric);
   pim_msg_curr += 4;
 
   /*
diff --git a/pimd/pim_assert.h b/pimd/pim_assert.h
index 6a8594c..feeb91d 100644
--- a/pimd/pim_assert.h
+++ b/pimd/pim_assert.h
@@ -58,7 +58,7 @@
 int pim_assert_metric_match(const struct pim_assert_metric *m1,
 			    const struct pim_assert_metric *m2);
 
-int pim_assert_build_msg(char *pim_msg, int buf_size,
+int pim_assert_build_msg(uint8_t *pim_msg, int buf_size,
 			 struct interface *ifp,
 			 struct in_addr group_addr,
 			 struct in_addr source_addr,
diff --git a/pimd/pim_int.c b/pimd/pim_int.c
new file mode 100644
index 0000000..2ff1a11
--- /dev/null
+++ b/pimd/pim_int.c
@@ -0,0 +1,44 @@
+/*
+  PIM for Quagga
+  Copyright (C) 2008  Everton da Silva Marques
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
+  
+  You should have received a copy of the GNU General Public License
+  along with this program; see the file COPYING; if not, write to the
+  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+  MA 02110-1301 USA
+  
+  $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <string.h>
+#include <netinet/in.h>
+
+#include "pim_int.h"
+
+uint32_t pim_read_uint32_host(const uint8_t *buf)
+{
+  uint32_t val;
+  memcpy(&val, buf, sizeof(val));
+  /* val is in netorder */
+  val = ntohl(val);
+  /* val is in hostorder */
+  return val;
+}
+
+void pim_write_uint32(uint8_t *buf, uint32_t val_host)
+{
+  /* val_host is in host order */
+  val_host = htonl(val_host);
+  /* val_host is in netorder */
+  memcpy(buf, &val_host, sizeof(val_host));
+}
diff --git a/pimd/pim_int.h b/pimd/pim_int.h
new file mode 100644
index 0000000..d64b103
--- /dev/null
+++ b/pimd/pim_int.h
@@ -0,0 +1,31 @@
+/*
+  PIM for Quagga
+  Copyright (C) 2008  Everton da Silva Marques
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
+  
+  You should have received a copy of the GNU General Public License
+  along with this program; see the file COPYING; if not, write to the
+  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+  MA 02110-1301 USA
+  
+  $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_INT_H
+#define PIM_INT_H
+
+#include <stdint.h>
+
+uint32_t pim_read_uint32_host(const uint8_t *buf);
+void pim_write_uint32(uint8_t *buf, uint32_t val_host);
+
+#endif /* PIM_INT_H */
diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c
index fc48c88..16b7e93 100644
--- a/pimd/pim_tlv.c
+++ b/pimd/pim_tlv.c
@@ -26,12 +26,13 @@
 #include "prefix.h"
 
 #include "pimd.h"
+#include "pim_int.h"
 #include "pim_tlv.h"
 #include "pim_str.h"
 #include "pim_msg.h"
 
-char *pim_tlv_append_uint16(char *buf,
-			    const char *buf_pastend,
+char *pim_tlv_append_uint16(uint8_t *buf,
+			    const uint8_t *buf_pastend,
 			    uint16_t option_type,
 			    uint16_t option_value)
 {
@@ -54,8 +55,8 @@
   return buf;
 }
 
-char *pim_tlv_append_2uint16(char *buf,
-			     const char *buf_pastend,
+char *pim_tlv_append_2uint16(uint8_t *buf,
+			     const uint8_t *buf_pastend,
 			     uint16_t option_type,
 			     uint16_t option_value1,
 			     uint16_t option_value2)
@@ -81,8 +82,8 @@
   return buf;
 }
 
-char *pim_tlv_append_uint32(char *buf,
-			    const char *buf_pastend,
+char *pim_tlv_append_uint32(uint8_t *buf,
+			    const uint8_t *buf_pastend,
 			    uint16_t option_type,
 			    uint32_t option_value)
 {
@@ -99,7 +100,7 @@
   buf += 2;
   *(uint16_t *) buf = htons(option_len);
   buf += 2;
-  *(uint32_t *) buf = htonl(option_value);
+  pim_write_uint32(buf, option_value);
   buf += option_len;
 
   return buf;
@@ -107,14 +108,14 @@
 
 #define ucast_ipv4_encoding_len (2 + sizeof(struct in_addr))
 
-char *pim_tlv_append_addrlist_ucast(char *buf,
-				    const char *buf_pastend,
+char *pim_tlv_append_addrlist_ucast(uint8_t *buf,
+				    const uint8_t *buf_pastend,
 				    struct list *ifconnected)
 {
   struct listnode *node;
   uint16_t option_len = 0;
 
-  char *curr;
+  uint8_t *curr;
 
   node = listhead(ifconnected);
 
@@ -323,7 +324,7 @@
   PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_DR_PRIORITY);
   
   *hello_option_dr_priority = PIM_TLV_GET_DR_PRIORITY(tlv_curr);
-  
+
   return 0;
 }
 
diff --git a/pimd/pim_tlv.h b/pimd/pim_tlv.h
index 9602cb1..5ec3dc4 100644
--- a/pimd/pim_tlv.h
+++ b/pimd/pim_tlv.h
@@ -71,21 +71,21 @@
 #define PIM_TLV_MIN_SIZE                (PIM_TLV_TYPE_SIZE + PIM_TLV_LENGTH_SIZE)
 #define PIM_TLV_OPTION_SIZE(option_len) (PIM_TLV_MIN_SIZE + (option_len))
 
-char *pim_tlv_append_uint16(char *buf,
-			    const char *buf_pastend,
+char *pim_tlv_append_uint16(uint8_t *buf,
+			    const uint8_t *buf_pastend,
 			    uint16_t option_type,
 			    uint16_t option_value);
-char *pim_tlv_append_2uint16(char *buf,
-			     const char *buf_pastend,
+char *pim_tlv_append_2uint16(uint8_t *buf,
+			     const uint8_t *buf_pastend,
 			     uint16_t option_type,
 			     uint16_t option_value1,
 			     uint16_t option_value2);
-char *pim_tlv_append_uint32(char *buf,
-			    const char *buf_pastend,
+char *pim_tlv_append_uint32(uint8_t *buf,
+			    const uint8_t *buf_pastend,
 			    uint16_t option_type,
 			    uint32_t option_value);
-char *pim_tlv_append_addrlist_ucast(char *buf,
-				    const char *buf_pastend,
+char *pim_tlv_append_addrlist_ucast(uint8_t *buf,
+				    const uint8_t *buf_pastend,
 				    struct list *ifconnected);
 
 int pim_tlv_parse_holdtime(const char *ifname, struct in_addr src_addr,