--- ntop/configure.in 2005-05-12 12:04:25.000000000 -0500
+++ ntop/configure.in 2005-05-13 15:02:38.294273252 -0500
@@ -61,7 +61,7 @@ AM_CONFIG_HEADER(config.h)
 HAS_ERROR=
 HAS_WARNING=
 
-NTOP_VERSION_EXTRA=""
+NTOP_VERSION_EXTRA=" librrd.so"
 
 echo
 echo "Welcome to $PACKAGE_NAME, Version $PACKAGE_VERSION $NTOP_VERSION_EXTRA"
@@ -128,7 +128,6 @@ dnl> make NTOPDIR the default for the in
 AC_PREFIX_DEFAULT(${NTOPDIR:-/usr/local})
 
 # Set constants and defaults
-MYRRD=`pwd`/myrrd
 SO_VERSION_PATCH=
 MAKE_SHARED_LIBRARY_PARM="-bundle -flat_namespace -undefined suppress"
 
@@ -2506,6 +2472,37 @@ else
 fi
 
 dnl>
+dnl> Shared librrd.so...
+dnl>
+AC_CHECK_HEADERS([rrd.h])
+AC_CHECK_LIB(rrd, rrd_open)
+AC_MSG_CHECKING([for rrd])
+if test ".${ac_cv_header_rrd_h}" = ".yes"         &&
+   test ".${ac_cv_lib_rrd_rrd_open}" = ".yes"; then
+    AC_MSG_RESULT(ok)
+    AC_DEFINE_UNQUOTED(MAKE_WITH_RRDLIB, 1, [librrd.so is available])
+else
+    AC_MSG_WARN(error)
+    echo
+    echo "*******************************************************************"
+    echo "*"
+    echo "* WARNING:  One or more items required for shared rrds are missing:"
+    echo "*           (yes means it was found, no means it was not found)"
+    echo "*"
+    echo "*                  rrd.h...${ac_cv_header_rrd_h}"
+    echo "*                  librrd.so...${ac_cv_lib_rrd_rrd_open}"
+    echo "*"
+    echo "*>>>    The rrd plugin will not work"
+    echo "*"
+    echo "*???     1. Install the necessary headers and libraries."
+    echo "*???    and rerun ./configure"
+    echo "*"
+    echo "*******************************************************************"
+    echo
+    HAS_WARNING="yes"
+fi
+
+dnl>
 dnl> SNMP Support
 dnl>
 if test ".${ac_disable_snmp}" != ".yes"; then
@@ -2953,7 +2949,6 @@ AC_SUBST(SCRIPTVER)
 AC_SUBST(SO_VERSION_PATCH)
 
 AC_CONFIG_FILES([Makefile])
-AC_CONFIG_FILES([myrrd/Makefile])
 
 if test ".${ac_disable_plugins}" != ".yes"; then
     AC_CONFIG_FILES([plugins/Makefile])
--- ntop/Makefile.am 2005-05-11 11:10:40.000000000 -0500
+++ ntop/Makefile.am 2005-05-13 15:31:37.613699220 -0500
@@ -33,7 +33,7 @@ PROGRAM  = $(PKGNAME)-$(VERSION)
 DEFS      = @DEFS@
 INCS      = @INCS@
 
-INCLUDES  = -I. $(INCS) -Imyrrd
+INCLUDES  = -I. $(INCS)
 LIBS      = @LIBS@
 AS        = @AS@
 AWK       = @AWK@
@@ -61,7 +61,7 @@ MAINTAINERCLEANFILES = COPYING Makefile.
                        stamp-h.in
 
 
-SUBDIRS = myrrd . @PLUGINS@
+SUBDIRS = . @PLUGINS@
 
 ETTER_PASSIVE_FILE = etter.finger.os
 ETTER_PASSIVE = $(ETTER_PASSIVE_FILE).gz
@@ -102,8 +102,8 @@ EXTRA_PROGRAMS = ntops sntop
 bin_SCRIPTS    = 
 
 ntop_SOURCES       = main.c admin.c
-ntop_DEPENDENCIES  = libntopreport.la libntop.la myrrd/libmyrrd.la
-ntop_LDADD         = libntopreport.la libntop.la myrrd/libmyrrd.la
+ntop_DEPENDENCIES  = libntopreport.la libntop.la
+ntop_LDADD         = libntopreport.la libntop.la
 ntop_LDFLAGS       = $(AM_LDFLAGS)
 ntop_CFLAGS        = 
 
@@ -137,7 +137,7 @@ libntop_la_SOURCES = address.c    argv.c
                      traffic.c    vendor.c      version.c      \
                      ntop_darwin.c
 
-libntop_la_DEPENDENCIES =  myrrd/libmyrrd.la config.h
+libntop_la_DEPENDENCIES =  config.h
 libntop_la_LIBADD       = 
 libntop_la_LDFLAGS      = $(AM_LDFLAGS) -release $(VERSION) -export-dynamic @DYN_FLAGS@
 
@@ -148,22 +148,19 @@ libntopreport_la_SOURCES = emitter.c    
                            webInterface.c
 
 
-libntopreport_la_DEPENDENCIES =  myrrd/libmyrrd.la config.h
+libntopreport_la_DEPENDENCIES =  config.h
 libntopreport_la_LIBADD       = 
 libntopreport_la_LDFLAGS      = $(AM_LDFLAGS) -release $(VERSION) -export-dynamic @DYN_FLAGS@
 
 man_MANS = ntop.8
 
-myrrd/libmyrrd.la:
-	cd myrrd; make
-
 .PHONY: snapshot
 
 
 acinclude.m4: acinclude.m4.ntop libtool.m4.in
 	@cat acinclude.m4.ntop libtool.m4.in >acinclude.m4
 
-CLEANLIST = `ls -l $(DESTDIR)$(libdir)/*ntop*.so $(DESTDIR)$(libdir)/*Plugin*.so $(DESTDIR)$(libdir)/*myrrd*.so | \
+CLEANLIST = `ls -l $(DESTDIR)$(libdir)/*ntop*.so $(DESTDIR)$(libdir)/*Plugin*.so | \
           grep -v $(VERSION) | \
           grep -v '\->' | \
           $(AWK) '{ print $$NF }'`
--- ntop/Makefile.in 2005-05-11 12:34:45.000000000 -0500
+++ ntop/Makefile.in 2005-05-13 15:33:13.298356994 -0500
@@ -110,7 +110,7 @@ ntop_OBJECTS = $(am_ntop_OBJECTS)
 am__objects_1 = main.$(OBJEXT) admin.$(OBJEXT)
 am_ntops_OBJECTS = $(am__objects_1)
 ntops_OBJECTS = $(am_ntops_OBJECTS)
-am__DEPENDENCIES_1 = libntopreport.la libntop.la myrrd/libmyrrd.la
+am__DEPENDENCIES_1 = libntopreport.la libntop.la
 am_sntop_OBJECTS = $(am__objects_1) icmpPlugin.$(OBJEXT) \
 	lastSeenPlugin.$(OBJEXT) netflowPlugin.$(OBJEXT) \
 	snmpPlugin.$(OBJEXT) pdaPlugin.$(OBJEXT) sflowPlugin.$(OBJEXT) \
@@ -291,7 +290,7 @@ AUTOMAKE_OPTIONS = 1.6   # Require Autom
 #
 PKGNAME = @PACKAGE_NAME@
 PROGRAM = $(PKGNAME)-$(VERSION)
-INCLUDES = -I. $(INCS) -Imyrrd
+INCLUDES = -I. $(INCS)
 AM_CFLAGS = @CFLAGS@
 AM_LDFLAGS = @LDFLAGS@
 DISTCLEANFILES = *.db #* *~ *.log
@@ -304,7 +303,7 @@ MAINTAINERCLEANFILES = COPYING Makefile.
                        ltmain.sh missing mkinstalldirs \
                        stamp-h.in
 
-SUBDIRS = myrrd . @PLUGINS@
+SUBDIRS = . @PLUGINS@
 ETTER_PASSIVE_FILE = etter.finger.os
 ETTER_PASSIVE = $(ETTER_PASSIVE_FILE).gz
 ETTER_PASSIVE_DOWNLOAD_FROM = "http://cvs.sourceforge.net/viewcvs.py/ettercap/ettercap_ng/share"
@@ -327,8 +326,8 @@ DATABASEFILES = `cat database/FILES`
 DOCSFILES = `cat docs/FILES`
 bin_SCRIPTS = 
 ntop_SOURCES = main.c admin.c
-ntop_DEPENDENCIES = libntopreport.la libntop.la myrrd/libmyrrd.la
-ntop_LDADD = libntopreport.la libntop.la myrrd/libmyrrd.la
+ntop_DEPENDENCIES = libntopreport.la libntop.la
+ntop_LDADD = libntopreport.la libntop.la
 ntop_LDFLAGS = $(AM_LDFLAGS)
 ntop_CFLAGS = 
 ntops_SOURCES = $(ntop_SOURCES)
@@ -361,7 +360,7 @@ libntop_la_SOURCES = address.c    argv.c
                      traffic.c    vendor.c      version.c      \
                      ntop_darwin.c
 
-libntop_la_DEPENDENCIES = myrrd/libmyrrd.la config.h
+libntop_la_DEPENDENCIES = config.h
 libntop_la_LIBADD = 
 libntop_la_LDFLAGS = $(AM_LDFLAGS) -release $(VERSION) -export-dynamic @DYN_FLAGS@
 
@@ -371,11 +370,11 @@ libntopreport_la_SOURCES = emitter.c    
                            report.c        reportUtils.c     ssl.c   \
                            webInterface.c
 
-libntopreport_la_DEPENDENCIES = myrrd/libmyrrd.la config.h
+libntopreport_la_DEPENDENCIES = config.h
 libntopreport_la_LIBADD = 
 libntopreport_la_LDFLAGS = $(AM_LDFLAGS) -release $(VERSION) -export-dynamic @DYN_FLAGS@
 man_MANS = ntop.8
-CLEANLIST = `ls -l $(DESTDIR)$(libdir)/*ntop*.so $(DESTDIR)$(libdir)/*Plugin*.so $(DESTDIR)$(libdir)/*myrrd*.so | \
+CLEANLIST = `ls -l $(DESTDIR)$(libdir)/*ntop*.so $(DESTDIR)$(libdir)/*Plugin*.so | \
           grep -v $(VERSION) | \
           grep -v '\->' | \
           $(AWK) '{ print $$NF }'`
@@ -1159,9 +1158,6 @@ uninstall-man: uninstall-man8
 	uninstall-libLTLIBRARIES uninstall-man uninstall-man8
 
 
-myrrd/libmyrrd.la:
-	cd myrrd; make
-
 .PHONY: snapshot
 
 acinclude.m4: acinclude.m4.ntop libtool.m4.in
--- ntop/configure 2005-05-12 12:04:25.000000000 -0500
+++ ntop/configure 2005-05-13 15:02:59.283659478 -0500
@@ -1560,7 +1561,7 @@ umask 002
 HAS_ERROR=
 HAS_WARNING=
 
-NTOP_VERSION_EXTRA=""
+NTOP_VERSION_EXTRA=" librrd.so"
 
 echo
 echo "Welcome to $PACKAGE_NAME, Version $PACKAGE_VERSION $NTOP_VERSION_EXTRA"
@@ -2198,7 +2199,6 @@ fi
 
 
 # Set constants and defaults
-MYRRD=`pwd`/myrrd
 SO_VERSION_PATCH=
 MAKE_SHARED_LIBRARY_PARM="-bundle -flat_namespace -undefined suppress"
 
@@ -42857,6 +42065,263 @@ echo "$as_me: WARNING: error" >&2;}
     HAS_WARNING="yes"
 fi
 
+
+for ac_header in rrd.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+else
+  # Is the header compilable?
+echo "$as_me:$LINENO: checking $ac_header usability" >&5
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_header_compiler=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6
+
+# Is the header present?
+echo "$as_me:$LINENO: checking $ac_header presence" >&5
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <$ac_header>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
+    (
+      cat <<\_ASBOX
+## ------------------------------- ##
+## Report this to the ntop lists.  ##
+## ------------------------------- ##
+_ASBOX
+    ) |
+      sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  eval "$as_ac_Header=\$ac_header_preproc"
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+
+fi
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+echo "$as_me:$LINENO: checking for rrd_open in -lrrd" >&5
+echo $ECHO_N "checking for rrd_open in -lrrd... $ECHO_C" >&6
+if test "${ac_cv_lib_rrd_rrd_open+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lrrd  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char rrd_open ();
+int
+main ()
+{
+rrd_open ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_rrd_rrd_open=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_rrd_rrd_open=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_rrd_rrd_open" >&5
+echo "${ECHO_T}$ac_cv_lib_rrd_rrd_open" >&6
+if test $ac_cv_lib_rrd_rrd_open = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBRRD 1
+_ACEOF
+
+  LIBS="-lrrd $LIBS"
+
+fi
+
+echo "$as_me:$LINENO: checking for rrd" >&5
+echo $ECHO_N "checking for rrd... $ECHO_C" >&6
+if test ".${ac_cv_header_rrd_h}" = ".yes"         &&
+   test ".${ac_cv_lib_rrd_rrd_open}" = ".yes"; then
+    echo "$as_me:$LINENO: result: ok" >&5
+echo "${ECHO_T}ok" >&6
+
+cat >>confdefs.h <<_ACEOF
+#define MAKE_WITH_RRDLIB 1
+_ACEOF
+
+else
+    { echo "$as_me:$LINENO: WARNING: error" >&5
+echo "$as_me: WARNING: error" >&2;}
+    echo
+    echo "*******************************************************************"
+    echo "*"
+    echo "* WARNING:  One or more items required for shared rrds are missing:"
+    echo "*           (yes means it was found, no means it was not found)"
+    echo "*"
+    echo "*                  rrd.h...${ac_cv_header_rrd_h}"
+    echo "*                  librrd.so...${ac_cv_lib_rrd_rrd_open}"
+    echo "*"
+    echo "*>>>    The rrd plugin will not work"
+    echo "*"
+    echo "*???     1. Install the necessary headers and libraries."
+    echo "*???    and rerun ./configure"
+    echo "*"
+    echo "*******************************************************************"
+    echo
+    HAS_WARNING="yes"
+fi
+
 if test ".${ac_disable_snmp}" != ".yes"; then
 
 for ac_header in net-snmp/net-snmp-config.h
@@ -43886,8 +43350,6 @@ echo
 
           ac_config_files="$ac_config_files Makefile"
 
-          ac_config_files="$ac_config_files myrrd/Makefile"
-
 
 if test ".${ac_disable_plugins}" != ".yes"; then
               ac_config_files="$ac_config_files plugins/Makefile"
@@ -44465,7 +43927,6 @@ do
   case "$ac_config_target" in
   # Handling of arguments.
   "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
-  "myrrd/Makefile" ) CONFIG_FILES="$CONFIG_FILES myrrd/Makefile" ;;
   "plugins/Makefile" ) CONFIG_FILES="$CONFIG_FILES plugins/Makefile" ;;
   "depfiles" ) CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
   "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
--- ntop/plugins/rrdPlugin.c 2005-05-10 09:14:28.000000000 -0500
+++ ntop/plugins/rrdPlugin.c 2005-05-13 15:54:39.119628361 -0500
@@ -57,10 +57,9 @@ patch courtesy of Dominique Karg <dk@ips
 #define _GETOPT_H
 #endif
 
-#include "myrrd/rrd.h"
-#include "myrrd/rrd_tool.h"
-#include "myrrd/rrd_format.h"
-
+#include "rrd.h"
+#include "rrd_tool.h"
+#include "rrd_format.h"
 
 #if defined(RRD_DEBUG) && (RRD_DEBUG > 0)
  #define traceEventRRDebug(level, ...) { if(RRD_DEBUG >= level) \
@@ -495,6 +463,8 @@ static int graphCounter(char *rrdPath, c
 #endif
   struct stat statbuf;
   int argc = 0, rc, x, y;
+  double ymin, ymax;
+  FILE *fd;
 
 #ifdef DEBUG
   traceEvent(CONST_TRACE_INFO, "graphCounter(%s, %s, %s, %s, %s, %s...)", 
@@ -584,7 +554,7 @@ static int graphCounter(char *rrdPath, c
     fillupArgv(argc, sizeof(argv)/sizeof(char*), argv);
     rrd_clear_error();
     addRrdDelay();
-    rc = rrd_graph(argc, argv, &calcpr, &x, &y);
+    rc = rrd_graph(argc, argv, &calcpr, &x, &y, fd, &ymin, &ymax);
 
     calfree();
 
@@ -630,6 +600,8 @@ static void netflowSummary(char *rrdPath
   char fname[384], *label;
   char **rrds = NULL;
   int argc = 0, rc, x, y, i, entryId=0;
+  double ymin, ymax;
+  FILE *fd;
 
   path[0] = '\0';
 
@@ -722,7 +694,7 @@ static void netflowSummary(char *rrdPath
   fillupArgv(argc, sizeof(argv)/sizeof(char*), argv);
   rrd_clear_error();
   addRrdDelay();
-  rc = rrd_graph(argc, argv, &calcpr, &x, &y);
+  rc = rrd_graph(argc, argv, &calcpr, &x, &y, fd, &ymin, &ymax);
 
   calfree();
 
@@ -788,6 +760,8 @@ static void graphSummary(char *rrdPath, 
   int argc = 0, rc, x, y, i, entryId=0;
   DIR* directoryPointer;
   char *rrd_custom[3], file_a[32], file_b[32];
+  double ymin, ymax;
+  FILE *fd;
 
   path[0] = '\0', label = "";
 
@@ -985,7 +959,7 @@ static void graphSummary(char *rrdPath, 
       traceEvent(CONST_TRACE_ERROR, "[%d] '%s'", j, argv[j]);
   }
 
-  rc = rrd_graph(argc, argv, &calcpr, &x, &y);
+  rc = rrd_graph(argc, argv, &calcpr, &x, &y, fd, &ymin, &ymax);
   calfree();
 
   if(rc == 0) {
@@ -1487,40 +1461,6 @@ static void commonRRDinit(void) {
 
 /* ****************************** */
 
-/* Find the timestamp of the first DETAIL row in an rrd - Ripped from rrd_dump.c
- *
- *  Note the issue - this assumes that the RRA[0] is the most detailed (which SHOULD be true).
- *
- *  A more complete version has been submitted to Tobi for rrdtool 1.0.49+
- *  replace with that version when/if it's becomes available.
- */
-
-static time_t rrd_first(char *path) {
-    FILE *in_file;
-    time_t now;
-    long timer=0, rra_start;
-    rrd_t rrd;
-
-    if(path == NULL) {
-        return(-1);
-    }
-    if(rrd_open(path, &in_file, &rrd, RRD_READONLY)==-1){
-        return(-1);
-    }
-
-    rra_start = ftell(in_file);
-    fseek(in_file,(rra_start +(rrd.rra_ptr[0].cur_row+1) * rrd.stat_head->ds_cnt * sizeof(rrd_value_t)), SEEK_SET);
-    timer = - (rrd.rra_def[0].row_cnt-1);
-    now = (rrd.live_head->last_up - 
-           rrd.live_head->last_up % (rrd.rra_def[0].pdp_cnt*rrd.stat_head->pdp_step)) +
-          (timer*rrd.rra_def[0].pdp_cnt*rrd.stat_head->pdp_step);
-    rrd_free(&rrd);
-    fclose(in_file);
-    return(now);
-}
-
-/* ****************************** */
-
 static void arbitraryAction(char *rrdName,
                             char *rrdInterface,
                             char *rrdIP,
@@ -1625,18 +1565,25 @@ static void arbitraryAction(char *rrdNam
       sendString("\"\n\n");
     }
 
-
-    argv[argc++] = "rrd_fetch";
-    argv[argc++] = path;
-    argv[argc++] = "AVERAGE";
-
     if((startTime != NULL) && (startTime[0] == '0') && (startTime[1] == '\0')) {
-      startTimeFound = rrd_first(path);
+      argv[argc++] = "rrd_first";
+      argv[argc++] = path;
+      fillupArgv(argc, sizeof(argv)/sizeof(char*), argv);
+      rrd_clear_error();
+      startTimeFound = rrd_first(argc, argv);
       if(startTimeFound != ((time_t)-1)) {
         safe_snprintf(__FILE__, __LINE__, startWorkTime, sizeof(startWorkTime), "%u", startTimeFound);
-        argv[argc++] = "--start";
-        argv[argc++] = startWorkTime;
       }
+    }
+
+    argc=0;
+    argv[argc++] = "rrd_first";
+    argv[argc++] = path;
+    argv[argc++] = "AVERAGE";
+
+    if(startWorkTime[0] != '\0') {
+      argv[argc++] = "--start";
+      argv[argc++] = startWorkTime;
     } else if(startTime != NULL) {
       argv[argc++] = "--start";
       argv[argc++] = startTime;
