Index: config_ndpmon.xml.in
===================================================================
--- config_ndpmon.xml.in	(revision 111)
+++ config_ndpmon.xml.in	(working copy)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <?xml-stylesheet type="text/xsl" href="config.xsl" ?>
-<!DOCTYPE config_ndpmon SYSTEM "@CONFDIR@/ndpmon/config_ndpmon.dtd">
+<!DOCTYPE config_ndpmon SYSTEM "@SHARE_INSTALL_PREFIX@/ndpmon/config_ndpmon.dtd">
 <config_ndpmon>
 	<ignor_autoconf>1</ignor_autoconf>
 	<syslog_facility>LOG_LOCAL1</syslog_facility>
@@ -8,12 +8,12 @@
         <actions_low_pri>
             <sendmail>1</sendmail>
             <syslog>1</syslog>
-            <exec_pipe_program>@prefix@/ndpmon/alerts_to_xml.py</exec_pipe_program>
+            <exec_pipe_program>@SHARE_INSTALL_PREFIX@/ndpmon/alerts_to_xml.py</exec_pipe_program>
         </actions_low_pri>
         <actions_high_pri>
             <sendmail>1</sendmail>
             <syslog>1</syslog>
-            <exec_pipe_program>@prefix@/ndpmon/alerts_to_xml.py</exec_pipe_program>
+            <exec_pipe_program>@SHARE_INSTALL_PREFIX@/ndpmon/alerts_to_xml.py</exec_pipe_program>
         </actions_high_pri>
         <use_reverse_hostlookups>1</use_reverse_hostlookups>
     <routers>
Index: routers.c
===================================================================
--- routers.c	(revision 111)
+++ routers.c	(working copy)
@@ -261,9 +261,11 @@
 		if (tmp->param_flags_reserved&ND_RA_FLAG_OTHER) {
 			fprintf(stderr,"OTHER ");
 		}
+#ifndef _FREEBSD_
 		if (tmp->param_flags_reserved&ND_RA_FLAG_HOME_AGENT) {
 			fprintf(stderr,"HOME_AGENT ");
 		}
+#endif
 		fprintf(stderr,"]\n");
 		fprintf(stderr,"        router lifetime: %u\n", tmp->param_router_lifetime);
 		fprintf(stderr,"        reachable timer: %u\n", tmp->param_reachable_timer);
@@ -297,9 +299,11 @@
 			if (ptmp->param_flags_reserved&ND_OPT_PI_FLAG_AUTO) {
 				fprintf(stderr,"AUTO ");
 			}
+#ifndef _FREEBSD_
 			if (ptmp->param_flags_reserved&ND_OPT_PI_FLAG_RADDR) {
 				fprintf(stderr,"RADDR ");
 			}
+#endif
 			fprintf(stderr,"]\n");
 			fprintf(stderr,"            valid time:     %u\n", ptmp->param_valid_time);
 			fprintf(stderr,"            preferred time: %u\n", ptmp->param_preferred_time);
Index: ndpmon_defs.h.in
===================================================================
--- ndpmon_defs.h.in	(revision 111)
+++ ndpmon_defs.h.in	(working copy)
@@ -9,12 +9,12 @@
 #include "./plugins/mac_resolv/mac_resolv.h"
 #endif
 
-#define _CONFIG_PATH_ "@CONFDIR@/ndpmon/config_ndpmon.xml"
-#define _CONFIG_DTD_PATH_ "@CONFDIR@/ndpmon/config_ndpmon.dtd"
-#define _CACHE_PATH_ "@VARDATADIR@/ndpmon/neighbor_list.xml"
-#define _CACHE_DTD_PATH_ "@VARDATADIR@/ndpmon/neighbor_list.dtd"
-#define _DISCOVERY_HISTORY_PATH_ "@VARDATADIR@/ndpmon/discovery_history.dat"
-#define _MANUF_PATH_ "@prefix@/ndpmon/plugins/mac_resolv/manuf"
+#define _CONFIG_PATH_ "@SYSCONF_INSTALL_DIR@/ndpmon/config_ndpmon.xml"
+#define _CONFIG_DTD_PATH_ "@SHARE_INSTALL_PREFIX@/ndpmon/config_ndpmon.dtd"
+#define _CACHE_PATH_ "@SHARED_STATE_INSTALL_DIR@/ndpmon/neighbor_list.xml"
+#define _CACHE_DTD_PATH_ "@SHARE_INSTALL_PREFIX@/ndpmon/neighbor_list.dtd"
+#define _DISCOVERY_HISTORY_PATH_ "@SHARED_STATE_INSTALL_DIR@/ndpmon/discovery_history.dat"
+#define _MANUF_PATH_ "@MANUF_FILE_LOCATION@"
 
 extern int DEBUG;
 extern int learning;
Index: neighbor_list.xml.in
===================================================================
--- neighbor_list.xml.in	(revision 111)
+++ neighbor_list.xml.in	(working copy)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <?xml-stylesheet type="text/xsl" href="neighbor.xsl" ?>
 <!DOCTYPE neighbor_list
-SYSTEM "@VARDATADIR@/ndpmon/neighbor_list.dtd">
+SYSTEM "@SHARE_INSTALL_PREFIX@/ndpmon/neighbor_list.dtd">
 <neighbor_list>
 </neighbor_list>
Index: cmake_modules/FindPCAP.cmake
===================================================================
--- cmake_modules/FindPCAP.cmake	(revision 0)
+++ cmake_modules/FindPCAP.cmake	(revision 0)
@@ -0,0 +1,22 @@
+# Try to find the PCAP library
+# Once done this will define
+#
+#  PCAP_FOUND - system has the PCAP library
+#  PCAP_INCLUDE_DIRS - the PCAP include directory
+#  PCAP_LIBRARIES - The libraries needed to use PCAP
+#
+# Author: F. Kooman <fkooman@tuxed.net>
+# Version: 20110103
+#
+
+# Will find PCAP headers both on Mac and Windows
+FIND_PATH(PCAP_INCLUDE_DIRS NAMES pcap.h)
+# PCAP library is for Mac, WinSCard library is for Windows
+FIND_LIBRARY(PCAP_LIBRARIES NAMES PCAP pcap)
+
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCAP DEFAULT_MSG
+  PCAP_LIBRARIES
+  PCAP_INCLUDE_DIRS
+)
+MARK_AS_ADVANCED(PCAP_INCLUDE_DIRS PCAP_LIBRARIES)
Index: alarm.c
===================================================================
--- alarm.c	(revision 111)
+++ alarm.c	(working copy)
@@ -30,7 +30,7 @@
 Olivier Festor, Scientific Leader of the MADYNEs Project, 20 August 2006
 ***********************************************************************************/
 
-
+#include <assert.h>
 #include "alarm.h"
 #include "membounds.h"
 
@@ -73,26 +73,47 @@
 	if(watch)
 	{
 		char mailmessage[MAIL_MESSAGE_SIZE];
+		char buffer[MAIL_MESSAGE_SIZE];
+		bzero(mailmessage, MAIL_MESSAGE_SIZE);
+
 		/* Build mailmessage to send or to pipe to external program */
-		snprintf(mailmessage, MAIL_MESSAGE_SIZE, "%-9s%s\n","Reason:",reason);
+		snprintf(buffer, MAIL_MESSAGE_SIZE, "%-9s%s\n","Reason:",reason);
+                assert((MAIL_MESSAGE_SIZE - strlen(mailmessage)) > 0);
+		strncat(mailmessage,buffer,MAIL_MESSAGE_SIZE-1-strlen(mailmessage));
+
 		if (mac_addr != NULL) {
-			snprintf(mailmessage, MAIL_MESSAGE_SIZE, "%s%-9s%s\n",mailmessage,"MAC:",ether_ntoa(mac_addr));
+			snprintf(buffer, MAIL_MESSAGE_SIZE, "%-9s%s\n","MAC:",ether_ntoa(mac_addr));
+                        assert((MAIL_MESSAGE_SIZE - strlen(mailmessage)) > 0);
+	                strncat(mailmessage,buffer,MAIL_MESSAGE_SIZE-1-strlen(mailmessage));
+
 #ifdef _MACRESOLUTION_
-       			snprintf(mailmessage,MAIL_MESSAGE_SIZE, "%s%-9s%s\n",mailmessage,"Vendor:",get_manufacturer(manuf, *mac_addr));
+       			snprintf(buffer,MAIL_MESSAGE_SIZE, "%-9s%s\n","Vendor:",get_manufacturer(manuf, *mac_addr));
+                        assert((MAIL_MESSAGE_SIZE - strlen(mailmessage)) > 0);
+                        strncat(mailmessage,buffer,MAIL_MESSAGE_SIZE-1-strlen(mailmessage));
 #endif
 		}
 		if (mac_addr2 != NULL) {
-			snprintf(mailmessage, MAIL_MESSAGE_SIZE, "%s%-9s%s\n",mailmessage,"MAC:",ether_ntoa(mac_addr2));
+			snprintf(buffer, MAIL_MESSAGE_SIZE, "%-9s%s\n","MAC:",ether_ntoa(mac_addr2));
+                        assert((MAIL_MESSAGE_SIZE - strlen(mailmessage)) > 0);
+                        strncat(mailmessage,buffer,MAIL_MESSAGE_SIZE-1-strlen(mailmessage));
+
 #ifdef _MACRESOLUTION_
-       			snprintf(mailmessage, MAIL_MESSAGE_SIZE, "%s%-9s%s\n",mailmessage,"Vendor:",get_manufacturer(manuf, *mac_addr2));
+       			snprintf(buffer, MAIL_MESSAGE_SIZE, "%-9s%s\n","Vendor:",get_manufacturer(manuf, *mac_addr2));
+                        assert((MAIL_MESSAGE_SIZE - strlen(mailmessage)) > 0);
+                        strncat(mailmessage,buffer,MAIL_MESSAGE_SIZE-1-strlen(mailmessage));
 #endif
 		}
 		if (strlen(ipv6)>0) {
-                        snprintf(mailmessage, MAIL_MESSAGE_SIZE, "%s%-9s%s\n",mailmessage,"IPv6:",ipv6);
+                        snprintf(buffer, MAIL_MESSAGE_SIZE, "%-9s%s\n","IPv6:",ipv6);
+                        assert((MAIL_MESSAGE_SIZE - strlen(mailmessage)) > 0);
+                        strncat(mailmessage,buffer,MAIL_MESSAGE_SIZE-1-strlen(mailmessage));
+
                         if (use_reverse_hostlookups==1) {
 	                        gethostfromipv6(ipv6,hostname);
 	                        if (DEBUG) fprintf(stderr,"DNS Resolution result for %s: %s\n",ipv6,hostname);
-        	                snprintf(mailmessage, MAIL_MESSAGE_SIZE, "%s%-9s%s\n",mailmessage,"DNS:",hostname);
+        	                snprintf(buffer, MAIL_MESSAGE_SIZE, "%-9s%s\n","DNS:",hostname);
+				assert((MAIL_MESSAGE_SIZE - strlen(mailmessage)) > 0);
+	                        strncat(mailmessage,buffer,MAIL_MESSAGE_SIZE-1-strlen(mailmessage));
                         }
                 }
 
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 0)
+++ CMakeLists.txt	(revision 0)
@@ -0,0 +1,71 @@
+PROJECT(ndpmon C)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
+SET(VERSION "2.0.0")
+
+SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/)
+
+SET(SYSCONF_INSTALL_DIR /usr/local/etc CACHE PATH "Host-specific system configuration")
+SET(SHARE_INSTALL_PREFIX /usr/local/share CACHE PATH "Architecture-independent data")
+SET(SHARED_STATE_INSTALL_DIR /var/local CACHE PATH "Variable state information")
+
+SET(ENABLE_MACRESOLUTION FALSE CACHE BOOL "Enable MAC Manufacturer Resolution")
+SET(ENABLE_COUNTERMEASURES FALSE CACHE BOOL "Enable Countermeasures")
+
+SET(MANUF_FILE_LOCATION ${SHARE_INSTALL_PREFIX}/ndpmon/plugins/mac_resolv/manuf CACHE FILE "Location of 'manuf' File")
+
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/ndpmon_defs.h.in ${CMAKE_CURRENT_BINARY_DIR}/ndpmon_defs.h @ONLY)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config_ndpmon.xml.in ${CMAKE_CURRENT_BINARY_DIR}/config_ndpmon.xml @ONLY)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/neighbor_list.xml.in ${CMAKE_CURRENT_BINARY_DIR}/neighbor_list.xml @ONLY)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/alerts_to_xml.py.in ${CMAKE_CURRENT_BINARY_DIR}/alerts_to_xml.py @ONLY)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/ndpmon.8.in ${CMAKE_CURRENT_BINARY_DIR}/ndpmon.8 @ONLY)
+
+INCLUDE(FindLibXml2)
+INCLUDE(FindPCAP)
+INCLUDE(FindOpenSSL)
+
+IF(CMAKE_SYSTEM_NAME MATCHES Linux)
+  ADD_DEFINITIONS(-D_LINUX_)
+ELSEIF(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
+  ADD_DEFINITIONS(-D_FREEBSD_)
+  # Bug in FindLibXml2.cmake on FreeBSD requires this include
+  INCLUDE_DIRECTORIES(/usr/local/include)
+ELSEIF(CMAKE_SYSTEM_NAME MATCHES Darwin)
+  ADD_DEFINITIONS(-D_FREEBSD_)
+ELSEIF(CMAKE_SYSTEM_NAME MATCHES OpenBSD)
+  ADD_DEFINITIONS(-D_OPENBSD_)
+ENDIF()
+
+FILE(GLOB SRC *.c)
+INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR} ${PCAP_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS})
+
+IF(ENABLE_MACRESOLUTION) 
+  ADD_DEFINITIONS(-D_MACRESOLUTION_)
+  SET(MACRESOLUTION_PATH plugins/mac_resolv)
+  FILE(GLOB MACRESOLUTION_SRC ${MACRESOLUTION_PATH}/*.c)
+  INCLUDE_DIRECTORIES(${MACRESOLUTION_PATH})
+ENDIF()
+
+IF(ENABLE_COUNTERMEASURES)
+  ADD_DEFINITIONS(-D_COUNTERMEASURES_)
+  SET(COUNTERMEASURES_PATH plugins/countermeasures)
+  FILE(GLOB COUNTERMEASURES_SRC ${COUNTERMEASURES_PATH}/*.c)
+  INCLUDE_DIRECTORIES(${COUNTERMEASURES_PATH})
+ENDIF()
+
+ADD_EXECUTABLE(ndpmon ${SRC} ${MACRESOLUTION_SRC} ${COUNTERMEASURES_SRC})
+TARGET_LINK_LIBRARIES(ndpmon ${LIBXML2_LIBRARIES} ${PCAP_LIBRARIES} ${OPENSSL_LIBRARIES})
+
+INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/ndpmon DESTINATION ${CMAKE_INSTALL_PREFIX}/sbin)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/config_ndpmon.xml DESTINATION ${SYSCONF_INSTALL_DIR}/ndpmon)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/ndpmon.8 DESTINATION ${SHARE_INSTALL_PREFIX}/man/man8)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/alerts.xml DESTINATION ${SHARED_STATE_INSTALL_DIR}/ndpmon)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/neighbor_list.xml DESTINATION ${SHARED_STATE_INSTALL_DIR}/ndpmon)
+INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/alerts_to_xml.py DESTINATION ${SHARE_INSTALL_PREFIX}/ndpmon)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config_ndpmon.dtd DESTINATION ${SHARE_INSTALL_PREFIX}/ndpmon)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/neighbor_list.dtd DESTINATION ${SHARE_INSTALL_PREFIX}/ndpmon)
+
+# If the location of the 'manuf' file was not specified, we install the local copy
+# Some systems provide a 'manuf' file already as part of Wireshark
+IF(MANUF_FILE_LOCATION STREQUAL ${SHARE_INSTALL_PREFIX}/ndpmon/plugins/mac_resolv/manuf)
+  INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/plugins/mac_resolv/manuf DESTINATION ${SHARE_INSTALL_PREFIX}/ndpmon/plugins/mac_resolv)
+ENDIF()
Index: plugins/countermeasures/countermeasures.c
===================================================================
--- plugins/countermeasures/countermeasures.c	(revision 111)
+++ plugins/countermeasures/countermeasures.c	(working copy)
@@ -1,5 +1,5 @@
 
-#include "membounds.h"
+#include "../../membounds.h"
 #include "countermeasures.h"
 
 /* All counter measures that are currently on link and have not yet been captured. */
Index: plugins/mac_resolv/mac_resolv.c
===================================================================
--- plugins/mac_resolv/mac_resolv.c	(revision 111)
+++ plugins/mac_resolv/mac_resolv.c	(working copy)
@@ -1,6 +1,6 @@
 #include <stdlib.h>
 
-#include "membounds.h"
+#include "../../membounds.h"
 #include "mac_resolv.h"
 
 /* gcc -Wall -O2 -g mac_resolv.c -o mac_resolv */
Index: ndpmon.8.in
===================================================================
--- ndpmon.8.in	(revision 0)
+++ ndpmon.8.in	(revision 0)
@@ -0,0 +1,193 @@
+.TH NDPMON 8 "November 2006"
+.SH NAME
+ndpmon - Neighbor Discovery Protocol Monitor
+.SH SYNOPSIS
+.na
+.B ndpmon
+[
+.B -i
+.I interfacename
+] [
+.B -f
+.I configfile
+] [
+.B -d
+.I dtd_file
+] [
+.B -F
+.I filter
+]
+.br
+.ti +7
+[
+.B -n
+.I number
+] [
+.B -L
+] [
+.B -v
+] [
+.B -h
+] [
+.B -d
+.I dtd_file
+]
+.br
+.ti +7
+[
+.B -g
+.I neighbor_file
+]
+.ad
+.SH DESCRIPTION
+.B NDPMon
+is  a monitoring software for ipv6 Neighbor Discovery. It syslogs activity and reports by email malicious ND message.
+.B NDPMon
+uses
+.BR libpcap
+to listen for icmp6 packets and 
+.BR libxml2
+to use configuration and neighbor cache files.
+.LP
+The
+.B -i
+flag is used to change the default interface eth0.
+.LP
+The
+.B -f
+flag is used to change the path of the configuration file.
+The default is
+.IR @SYSCONF_INSTALL_DIR@/ndpmon/config_ndpmon.xml
+.LP
+The 
+.B -e
+flag is used to change the path to the DTD file for the configuration file. The default is
+.I @SHARE_INSTALL_PREFIX@/ndpmon/config_ndpmon.dtd
+.LP
+The
+.B -n
+flag uses libpcap to specify a limited number of packet to capture.
+.LP
+The
+.B -F
+flag allows to change the default icmp6 filter.
+.LP
+The
+.B -L
+flag is used to disable syslog and mail reports. This is used to do a learning phase and constitue the neighbor cache.
+.LP
+The
+.B -v
+is used to enable the DEBUG mode.
+.LP
+The 
+.B -d
+flag is used to change the path to the DTD file for the neighbor cache. The default is
+.I @SHARE_INSTALL_PREFIX@/ndpmon/neighbor_list.dtd
+.LP
+The
+.B -g
+flag is used to change the path to the neighbor cache. The default is 
+.I @SHARED_STATE_INSTALL_DIR@/ndpmon/neighbor_list.xml
+.LP
+Note that an empty
+.I neighbor_cache.xml
+file must be created before the first time you run
+.BR ndpmon.
+.LP 
+.BR NDPMon
+must be run with
+.BR root
+rights to work.
+.LP
+.SH "REPORT MESSAGES"
+Here's the list of the report messages generated by
+.BR ndpmon:
+.TP
+.B "wrong couple MAC/IP"
+Separately, the MAC and IP addresses are valid, but not as
+a couple.
+.TP
+.B "wrong router mac"
+The ethernet address of the RA message is not specified in the 
+configuration file.
+.TP
+.B "wrong router ip"
+The ip address of the RA message is not specified in the 
+configuration file.
+.TP
+.B "wrong prefix"
+The prefix announced in the RA message is not specified in the 
+configuration file.
+.TP
+.B "wrong router redirect"
+The RD message does'nt come from a router specified in the configuration file.
+.TP
+.B "NA router flag"
+The NA specifies a router but isn't one according to the configuration file.
+.TP
+.B "DAD DOS"
+The NA answer to NS to avoid it to get an ip address.
+.TP
+.B "changed ethernet address"
+The host switched to a new ethernet address.
+.TP
+.B "flip flop"
+The ethernet address has changed from the most recently seen address to
+the second most recently seen address.
+.TP
+.B "reused old ethernet address"
+The ethernet address has changed from the most recently seen address to
+the third (or greater) least recently seen address.
+.SH "SYSLOG MESSAGES"
+Here are some of the syslog messages;
+note that messages that are reported are also sysloged.
+.TP
+.B "new activity"
+This ethernet/ip6 address pair has been announced for last time two
+months or more.
+.TP
+.B "new station"
+The ethernet address has not been seen before on the link.
+.TP
+.B "ethernet broadcast"
+The mac ethernet address of the host is a broadcast address.
+.TP
+.B "ip broadcast"
+The ip address of the host is a broadcast address.
+.TP
+.B "bogon"
+The source ip address is not local to the local subnet.
+.TP
+.B "ethernet mismatch"
+The source mac ethernet address didn't match the address announced in
+option of the ND message.
+.SH FILES
+.na
+.nh
+.nf
+config_ndpmon.xml - contains settings which must be fill by the administrator
+neighbor_list.xml - neighbor cache: all neighbors known to be on the link 
+.ad
+.hy
+.fi
+.SH "SEE ALSO"
+.na
+.nh
+.BR arpwatch (8)
+.BR ipv6 (7),
+.BR pcap (3),
+.BR libxml (3).
+.ad
+.hy
+.SH AUTHOR
+Thibault Cholez and Frederic Beck for
+MADYNES Project,
+Loria,
+Fr.
+.RE
+.SH BUGS
+.TP
+Please send bug reports to frederic.beck@loria.fr
+or thibault.cholez@esial.uhp-nancy.fr 
+.LP
Index: alerts_to_xml.py.in
===================================================================
--- alerts_to_xml.py.in	(revision 111)
+++ alerts_to_xml.py.in	(working copy)
@@ -11,7 +11,7 @@
 from xml.dom import Node
 
 # The file in which we will write the alerts 
-alerts = "@VARDATADIR@/ndpmon/alerts.xml"
+alerts = "@SHARED_STATE_INSTALL_DIR@/ndpmon/alerts.xml"
 
 # The alert itself piped from NDPmon to this script
 lines = sys.stdin.readlines()
