diff -u -ru ../freeipmi-0.2.3/bmc-info/src/bmc-info.c ./bmc-info/src/bmc-info.c
--- ../freeipmi-0.2.3/bmc-info/src/bmc-info.c	Wed Apr 19 08:34:27 2006
+++ ./bmc-info/src/bmc-info.c	Sun Aug 13 14:04:31 2006
@@ -20,7 +20,9 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
+#ifdef HAVE_ERROR_H
 #include <error.h>
+#endif
 #include <string.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
diff -u -ru ../freeipmi-0.2.3/bmc-watchdog/src/bmc-watchdog.c ./bmc-watchdog/src/bmc-watchdog.c
--- ../freeipmi-0.2.3/bmc-watchdog/src/bmc-watchdog.c	Mon Feb  6 02:36:30 2006
+++ ./bmc-watchdog/src/bmc-watchdog.c	Sun Aug 13 14:04:31 2006
@@ -45,7 +45,9 @@
 #endif
 #include <errno.h>
 #include <getopt.h>
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #include <sys/stat.h>
 #include <sys/select.h>
 #if TIME_WITH_SYS_TIME
diff -u -ru ../freeipmi-0.2.3/common/src/argp-common.c ./common/src/argp-common.c
--- ../freeipmi-0.2.3/common/src/argp-common.c	Wed Jul 12 17:26:38 2006
+++ ./common/src/argp-common.c	Sun Aug 13 14:04:31 2006
@@ -29,7 +29,9 @@
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#ifdef HAVE_ERROR_H
 #include <error.h>
+#endif
 #include <argp.h>
 
 #include "freeipmi.h"
diff -u -ru ../freeipmi-0.2.3/common/src/ipmi-common.c ./common/src/ipmi-common.c
--- ../freeipmi-0.2.3/common/src/ipmi-common.c	Thu Feb  9 22:59:03 2006
+++ ./common/src/ipmi-common.c	Sun Aug 13 14:04:31 2006
@@ -29,7 +29,9 @@
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#ifdef HAVE_ERROR_H
 #include <error.h>
+#endif
 #include <argp.h>
 
 #include "freeipmi.h"
diff -u -ru ../freeipmi-0.2.3/configure.ac ./configure.ac
--- ../freeipmi-0.2.3/configure.ac	Tue Jul 25 16:56:57 2006
+++ ./configure.ac	Sun Aug 13 14:13:29 2006
@@ -97,6 +97,20 @@
 fi
 AC_SUBST(WITH_DEBUG)
 
+dnl Search for argp functions, in standard C library or in argp-standalone
+AC_CHECK_FUNC([argp_parse], ,
+	AC_CHECK_LIB([argp], [argp_parse], ,
+		AC_MSG_ERROR([argp library not found. Install argp-standalone.])
+	)
+)
+
+dnl Search for getopt_long() in standard C library or in libgnugetopt
+AC_CHECK_FUNC([getopt_long], ,
+	AC_CHECK_LIB([gnugetopt], [getopt_long], ,
+		AC_MSG_ERROR([gnugetopt library not found. Install gnugetopt.])
+	)
+)
+
 dnl See if they want to build fish.
 AC_ARG_ENABLE([fish],
               AC_HELP_STRING([--disable-fish], [don't build the fish IPMI shell]))
@@ -163,13 +177,14 @@
 dnl Checks for library functions.
 AC_FUNC_ALLOCA
 AC_FUNC_MMAP
-AC_CHECK_FUNCS([strchr memcpy memset getopt_long mlock])
+AC_CHECK_FUNCS([strchr memcpy memset mlock])
 
 dnl Checks for header files.
 AC_HEADER_STDC
 AC_HEADER_TIME
 AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS([unistd.h fcntl.h])
+AC_CHECK_HEADERS([unistd.h fcntl.h stdint.h getopt.h linux/types.h error.h])
+AC_CHECK_HEADERS([netpacket/packet.h net/bpf.h])
 
 dnl Check for random number paths
 AC_CHECK_FILE([/dev/urandom], AC_DEFINE([HAVE_DEVURANDOM], [1], [Define that you found /dev/urandom]))
diff -u -ru ../freeipmi-0.2.3/fish/src/fi-utils.c ./fish/src/fi-utils.c
--- ../freeipmi-0.2.3/fish/src/fi-utils.c	Tue Dec  6 13:48:30 2005
+++ ./fish/src/fi-utils.c	Sun Aug 13 14:04:31 2006
@@ -135,38 +135,51 @@
 get_home_directory (void)
 {
   struct passwd *current_passwd;
-  uid_t user_id;
-  setpwent ();
-  user_id = getuid ();
   char * username = "unknownuser";
   char * dir;
+  char *tmpdir;
 
-  while ((current_passwd = getpwent ()))
-    {
-      if (current_passwd->pw_uid == user_id) {
-	username = current_passwd->pw_name ? current_passwd->pw_name :
-	  username;
-	if (access (current_passwd->pw_dir, R_OK|W_OK|X_OK)) 
-	  break;
-	else
-	  return current_passwd->pw_dir;
-      } 
-    }
-  dir = calloc (strlen ("/tmp") + 1 + strlen (username) + 1, 1);
-  sprintf (dir, "/tmp/%s", username);
-  return mkdir (dir, 0755) ? NULL : dir;
+  current_passwd = getpwuid(getuid());
+  if (current_passwd != NULL) {
+    if (current_passwd->pw_dir != NULL &&
+        access(current_passwd->pw_dir, R_OK | W_OK | X_OK) == 0)
+      return strdup(current_passwd->pw_dir);
+    if (current_passwd->pw_name != NULL)
+      username = current_passwd->pw_name;
+  }
+
+  tmpdir = getenv("TMPDIR");
+  if (tmpdir == NULL)
+    tmpdir = "/tmp";
+  dir = malloc (strlen (tmpdir) + 1 + sizeof("freeipmi-") - 1 +
+    strlen (username) + 1);
+  if (dir == NULL)
+    return NULL;
+  sprintf (dir, "%s/freeipmi-%s", tmpdir, username);
+  if (mkdir (dir, 0700) < 0 && errno != EEXIST) {
+    free(dir);
+    return NULL;
+  }
+  return dir;
 }
 
 char *
 get_config_directory (void)
 {
   char *config_directory;
-  int length =
-    strlen (get_home_directory ()) + strlen (FI_CONFIG_DIRECTORY) + 2;
+  char *homedir;
+  int length;
+
+  homedir = get_home_directory();
+  if (homedir == NULL)
+    return NULL;
+
+  length = strlen (homedir) + strlen (FI_CONFIG_DIRECTORY) + 2;
 
   config_directory = (char *) calloc (length, sizeof (char));
-  sprintf (config_directory, "%s/" FI_CONFIG_DIRECTORY,
-	   get_home_directory ());
+  sprintf (config_directory, "%s/" FI_CONFIG_DIRECTORY, homedir);
+
+  free(homedir);
 
   return config_directory;
 }
@@ -175,10 +188,20 @@
 get_config_filename (void)
 {
   char *config_filename;
-  int length = strlen (get_home_directory ()) + strlen (FI_CONFIG_FILE) + 2;
+  char *homedir;
+  int length;
+
+  homedir = get_home_directory();
+  if (homedir == NULL)
+    return NULL;
+
+  length = strlen (homedir) + strlen (FI_CONFIG_FILE) + 2;
 
   config_filename = (char *) calloc (length, sizeof (char));
-  sprintf (config_filename, "%s/" FI_CONFIG_FILE, get_home_directory ());
+  sprintf (config_filename, "%s/" FI_CONFIG_FILE, homedir);
+
+  free(homedir);
+
   return config_filename;
 }
 
@@ -198,11 +221,18 @@
 get_local_extensions_directory (void)
 {
   char *local_extensions_directory = NULL;
-  
+  char *homedir;
+
+  homedir = get_home_directory();
+  if (homedir == NULL)
+    return NULL;
+
   asprintf (&local_extensions_directory, 
 	    "%s/%s", 
-	    get_home_directory (),
+		homedir,
 	    FI_LOCAL_EXTENSIONS_DIRECTORY);
+
+  free(homedir);
   
   return local_extensions_directory;
 }
diff -u -ru ../freeipmi-0.2.3/ipmi-raw/src/ipmi-raw.c ./ipmi-raw/src/ipmi-raw.c
--- ../freeipmi-0.2.3/ipmi-raw/src/ipmi-raw.c	Wed Apr 19 08:34:29 2006
+++ ./ipmi-raw/src/ipmi-raw.c	Sun Aug 13 14:04:31 2006
@@ -20,7 +20,9 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
+#ifdef HAVE_ERROR_H
 #include <error.h>
+#endif
 #include <string.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
diff -u -ru ../freeipmi-0.2.3/ipmipower/src/conffile.c ./ipmipower/src/conffile.c
--- ../freeipmi-0.2.3/ipmipower/src/conffile.c	Fri Dec 16 14:48:40 2005
+++ ./ipmipower/src/conffile.c	Sun Aug 13 14:04:31 2006
@@ -33,7 +33,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <ctype.h>
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #include <sys/stat.h>
 #include <fcntl.h>
 
diff -u -ru ../freeipmi-0.2.3/ipmipower/src/fd.h ./ipmipower/src/fd.h
--- ../freeipmi-0.2.3/ipmipower/src/fd.h	Fri Dec 16 14:48:40 2005
+++ ./ipmipower/src/fd.h	Sun Aug 13 14:04:31 2006
@@ -33,7 +33,9 @@
 #  include "config.h"
 #endif /* HAVE_CONFIG_H */
 
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
diff -u -ru ../freeipmi-0.2.3/ipmipower/src/ipmipower.c ./ipmipower/src/ipmipower.c
--- ../freeipmi-0.2.3/ipmipower/src/ipmipower.c	Fri Dec 16 14:48:40 2005
+++ ./ipmipower/src/ipmipower.c	Sun Aug 13 14:04:31 2006
@@ -47,7 +47,9 @@
 #  include <time.h>
 # endif
 #endif
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #include <sys/stat.h>
 #include <sys/resource.h>
 #if HAVE_FCNTL_H
diff -u -ru ../freeipmi-0.2.3/ipmipower/src/ipmipower_config.c ./ipmipower/src/ipmipower_config.c
--- ../freeipmi-0.2.3/ipmipower/src/ipmipower_config.c	Tue Jan 24 06:34:32 2006
+++ ./ipmipower/src/ipmipower_config.c	Sun Aug 13 14:04:31 2006
@@ -35,7 +35,9 @@
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #include <getopt.h>
 
 #include "ipmipower_config.h"
diff -u -ru ../freeipmi-0.2.3/ipmipower/src/ipmipower_connection.c ./ipmipower/src/ipmipower_connection.c
--- ../freeipmi-0.2.3/ipmipower/src/ipmipower_connection.c	Sat Jan 28 21:03:39 2006
+++ ./ipmipower/src/ipmipower_connection.c	Sun Aug 13 14:04:31 2006
@@ -39,7 +39,9 @@
 #endif
 #include <errno.h>
 
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
diff -u -ru ../freeipmi-0.2.3/ipmipower/src/ipmipower_packet.c ./ipmipower/src/ipmipower_packet.c
--- ../freeipmi-0.2.3/ipmipower/src/ipmipower_packet.c	Mon Feb  6 02:36:30 2006
+++ ./ipmipower/src/ipmipower_packet.c	Sun Aug 13 14:04:31 2006
@@ -35,7 +35,9 @@
 #endif
 #include <errno.h>
 #include <assert.h>
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 
 #include "ipmipower_packet.h"
 #include "ipmipower_auth.h"
diff -u -ru ../freeipmi-0.2.3/ipmipower/src/ipmipower_prompt.c ./ipmipower/src/ipmipower_prompt.c
--- ../freeipmi-0.2.3/ipmipower/src/ipmipower_prompt.c	Tue Jan 24 06:34:32 2006
+++ ./ipmipower/src/ipmipower_prompt.c	Sun Aug 13 14:04:31 2006
@@ -33,7 +33,9 @@
 #if STDC_HEADERS
 #include <string.h>
 #endif
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #include <sys/stat.h>
 #if HAVE_FCNTL_H
 #include <fcntl.h>
diff -u -ru ../freeipmi-0.2.3/ipmipower/src/ipmipower_util.c ./ipmipower/src/ipmipower_util.c
--- ../freeipmi-0.2.3/ipmipower/src/ipmipower_util.c	Fri Dec 16 14:48:40 2005
+++ ./ipmipower/src/ipmipower_util.c	Sun Aug 13 14:04:31 2006
@@ -35,7 +35,9 @@
 #endif
 #include <errno.h>
 #include <assert.h>
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #include <sys/stat.h>
 #include <sys/mman.h>
 #if HAVE_FCNTL_H
diff -u -ru ../freeipmi-0.2.3/ipmipower/src/wrappers.c ./ipmipower/src/wrappers.c
--- ../freeipmi-0.2.3/ipmipower/src/wrappers.c	Sat Jan 28 21:03:39 2006
+++ ./ipmipower/src/wrappers.c	Sun Aug 13 14:04:31 2006
@@ -42,9 +42,10 @@
 #if HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #include <sys/socket.h>
-#include <stdint.h>
 #if HAVE_SYS_WAIT_H
 #include <sys/wait.h>
 #endif
diff -u -ru ../freeipmi-0.2.3/ipmipower/src/wrappers.h ./ipmipower/src/wrappers.h
--- ../freeipmi-0.2.3/ipmipower/src/wrappers.h	Fri Dec 16 14:48:40 2005
+++ ./ipmipower/src/wrappers.h	Sun Aug 13 14:04:31 2006
@@ -27,12 +27,13 @@
 #ifndef WRAPPERS_H
 #define WRAPPERS_H
 
-#ifdef __FreeBSD__
+#include <sys/types.h>
+
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
 #endif
 #include <regex.h>
 #include <netdb.h>
-#include <stdint.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <sys/poll.h>
diff -u -ru ../freeipmi-0.2.3/libfreeipmi/src/freeipmi.h ./libfreeipmi/src/freeipmi.h
--- ../freeipmi-0.2.3/libfreeipmi/src/freeipmi.h	Tue Feb  7 23:19:25 2006
+++ ./libfreeipmi/src/freeipmi.h	Sun Aug 13 14:04:31 2006
@@ -39,7 +39,9 @@
 #include <sys/stat.h>
 #include <sys/ipc.h>
 #include <sys/sem.h>
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #include <sys/select.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
@@ -176,8 +178,13 @@
 # define _OUTB(data, port)  outb (data, port)
 #endif
 
-#if defined(__FreeBSD__) && !defined(EBADMSG)
-# define EBADMSG    ENOMSG
+#if defined(__FreeBSD__)
+# ifndef EBADMSG
+#  define EBADMSG    ENOMSG
+# endif
+# ifndef O_SYNC
+#  define O_SYNC	O_FSYNC
+# endif
 #endif
 
 #ifdef FREEIPMI_LIBRARY
diff -u -ru ../freeipmi-0.2.3/libfreeipmi/src/ipmi-lan-interface.c ./libfreeipmi/src/ipmi-lan-interface.c
--- ../freeipmi-0.2.3/libfreeipmi/src/ipmi-lan-interface.c	Sun Jul 23 01:55:52 2006
+++ ./libfreeipmi/src/ipmi-lan-interface.c	Sun Aug 13 14:04:31 2006
@@ -1109,7 +1109,12 @@
 {
   fiid_field_t *tmpl_lan_packet = NULL;
   int lan_packet_length = 0;
-  
+  int rmcp_length = 0;
+  int session_length = 0;
+  int hdr_length = 0;
+  int cmd_length = 0;
+  int trlr_length = 0;
+
   if (!dev
       || !pkt
       || !obj_cmd
@@ -1119,12 +1124,6 @@
       return (-1);
     }
 
-  int rmcp_length = 0;
-  int session_length = 0;
-  int hdr_length = 0;
-  int cmd_length = 0;
-  int trlr_length = 0;
-  
   ERR ((rmcp_length = 
 	fiid_obj_len_bytes (*(dev->io.outofband.rs.tmpl_hdr_rmcp_ptr))) != -1);
   ERR ((session_length = 
diff -u -ru ../freeipmi-0.2.3/libfreeipmi/src/ipmi-smic-interface.c ./libfreeipmi/src/ipmi-smic-interface.c
--- ../freeipmi-0.2.3/libfreeipmi/src/ipmi-smic-interface.c	Fri Dec 16 14:48:40 2005
+++ ./libfreeipmi/src/ipmi-smic-interface.c	Sun Aug 13 14:04:31 2006
@@ -20,7 +20,9 @@
 */
 
 #include "freeipmi.h"
+#ifdef HAVE_LINUX_TYPES_H
 #include <linux/types.h>
+#endif
 
 #if defined(__FreeBSD__) && !defined(USE_IOPERM)
 static int ipmi_smic_dev_io_fd = -1;
