Merge isisd into the Quagga's framework:
  - add privs support
  - use misc quagga's definitions
  - make it compile"able"
  - fix segfault cases related to hostname()
  - add debug isis xxx command

This patch has been approved by Paul Jakma.
diff --git a/isisd/Makefile.am b/isisd/Makefile.am
index b9a0c7c..fd4c199 100644
--- a/isisd/Makefile.am
+++ b/isisd/Makefile.am
@@ -43,13 +43,3 @@
 	  fi; fi; \
 	done
 
-depend:
-	@$(CPP) -MM $(INCLUDES) $(LDFLAGS) *.c
-
-## File dependency.
-isis_adjacency.o : isis_adjacency.c ../lib/version.h ../lib/log.h \
- ../isisd/isis_adjacency.h
-isis_pdu.o : isis_pdu.c ../lib/log.h ../isisd/isisd.h \
- ../isisd/isis_constants.h ../isisd/isis_adjacency.h \
- ../isisd/isis_pdu.h
-isis_circuit.o : isis_circuit.c ../isisd/isis_circuit.h
diff --git a/isisd/Makefile.in b/isisd/Makefile.in
index 46aae73..7cb2e59 100644
--- a/isisd/Makefile.in
+++ b/isisd/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.6.2 from Makefile.am.
+# Makefile.in generated by automake 1.7.9 from Makefile.am.
 # @configure_input@
 
-# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
+# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
 # Free Software Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -13,98 +13,138 @@
 # PARTICULAR PURPOSE.
 
 @SET_MAKE@
-SHELL = @SHELL@
 
 srcdir = @srcdir@
 top_srcdir = @top_srcdir@
 VPATH = @srcdir@
-prefix = @prefix@
-exec_prefix = @exec_prefix@
-
-bindir = @bindir@
-sbindir = @sbindir@
-libexecdir = @libexecdir@
-datadir = @datadir@
-sysconfdir = @sysconfdir@
-sharedstatedir = @sharedstatedir@
-localstatedir = @localstatedir@
-libdir = @libdir@
-infodir = @infodir@
-mandir = @mandir@
-includedir = @includedir@
-oldincludedir = /usr/include
 pkgdatadir = $(datadir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 top_builddir = ..
 
-ACLOCAL = @ACLOCAL@
-AUTOCONF = @AUTOCONF@
-AUTOMAKE = @AUTOMAKE@
-AUTOHEADER = @AUTOHEADER@
-
 am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
 INSTALL = @INSTALL@
-INSTALL_PROGRAM = @INSTALL_PROGRAM@
-INSTALL_DATA = @INSTALL_DATA@
 install_sh_DATA = $(install_sh) -c -m 644
 install_sh_PROGRAM = $(install_sh) -c
 install_sh_SCRIPT = $(install_sh) -c
-INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_HEADER = $(INSTALL_DATA)
-transform = @program_transform_name@
+transform = $(program_transform_name)
 NORMAL_INSTALL = :
 PRE_INSTALL = :
 POST_INSTALL = :
 NORMAL_UNINSTALL = :
 PRE_UNINSTALL = :
 POST_UNINSTALL = :
-host_alias = @host_alias@
 host_triplet = @host@
-
-EXEEXT = @EXEEXT@
-OBJEXT = @OBJEXT@
-PATH_SEPARATOR = @PATH_SEPARATOR@
+ACLOCAL = @ACLOCAL@
+AMDEP_FALSE = @AMDEP_FALSE@
+AMDEP_TRUE = @AMDEP_TRUE@
 AMTAR = @AMTAR@
 AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
 BGPD = @BGPD@
 CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CONFDATE = @CONFDATE@
 CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
 CURSES = @CURSES@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
 DEPDIR = @DEPDIR@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
 IF_METHOD = @IF_METHOD@
 IF_PROC = @IF_PROC@
 
 # INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -Itopology
 INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib 
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 IPFORWARD = @IPFORWARD@
 ISISD = @ISISD@
 KERNEL_METHOD = @KERNEL_METHOD@
+LDFLAGS = @LDFLAGS@
+LIBCAP = @LIBCAP@
+LIBOBJS = @LIBOBJS@
 LIBPAM = @LIBPAM@
+LIBS = @LIBS@ 
 LIB_IPV6 = @LIB_IPV6@
 LIB_REGEX = @LIB_REGEX@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
 MULTIPATH_NUM = @MULTIPATH_NUM@
+OBJEXT = @OBJEXT@
 OSPF6D = @OSPF6D@
+OSPFAPI = @OSPFAPI@
+OSPFCLIENT = @OSPFCLIENT@
 OSPFD = @OSPFD@
 OTHER_METHOD = @OTHER_METHOD@
 PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
 RANLIB = @RANLIB@
 RIPD = @RIPD@
 RIPNGD = @RIPNGD@
 RTREAD_METHOD = @RTREAD_METHOD@
 RT_METHOD = @RT_METHOD@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
 STRIP = @STRIP@
 VERSION = @VERSION@
 VTYSH = @VTYSH@
 ZEBRA = @ZEBRA@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_RANLIB = @ac_ct_RANLIB@
+ac_ct_STRIP = @ac_ct_STRIP@
+am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
+am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
 am__include = @am__include@
+am__leading_dot = @am__leading_dot@
 am__quote = @am__quote@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+datadir = @datadir@
+exampledir = @exampledir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+includedir = @includedir@
+infodir = @infodir@
 install_sh = @install_sh@
-DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
+libdir = @libdir@
+libexecdir = @libexecdir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+oldincludedir = @oldincludedir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
 INSTALL_SDATA = @INSTALL@ -m 600
-LIBS = @LIBS@ 
 noinst_LIBRARIES = libisis.a
 sbin_PROGRAMS = isisd 
 
@@ -132,6 +172,7 @@
 
 EXTRA_DIST = $(sysconf_DATA)
 subdir = isisd
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
 CONFIG_HEADER = $(top_builddir)/config.h
 CONFIG_CLEAN_FILES =
@@ -161,9 +202,8 @@
 isisd_OBJECTS = $(am_isisd_OBJECTS)
 isisd_DEPENDENCIES = ../lib/libzebra.a
 isisd_LDFLAGS =
+
 DEFAULT_INCLUDES =  -I. -I$(srcdir) -I$(top_builddir)
-CPPFLAGS = @CPPFLAGS@
-LDFLAGS = @LDFLAGS@
 depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/dict.Po \
@@ -183,23 +223,22 @@
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 CCLD = $(CC)
 LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
-CFLAGS = @CFLAGS@
 DIST_SOURCES = $(libisis_a_SOURCES) $(isisd_SOURCES)
 DATA = $(sysconf_DATA)
 
 HEADERS = $(noinst_HEADERS)
 
-DIST_COMMON = README $(noinst_HEADERS) AUTHORS COPYING ChangeLog \
-	Makefile.am Makefile.in TODO
+DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/Makefile.in AUTHORS \
+	COPYING ChangeLog Makefile.am TODO
 SOURCES = $(libisis_a_SOURCES) $(isisd_SOURCES)
 
 all: all-am
 
 .SUFFIXES:
 .SUFFIXES: .c .o .obj
-$(srcdir)/Makefile.in:  Makefile.am  $(top_srcdir)/configure.in $(ACLOCAL_M4)
+$(srcdir)/Makefile.in:  Makefile.am  $(top_srcdir)/configure.ac $(ACLOCAL_M4)
 	cd $(top_srcdir) && \
-	  $(AUTOMAKE) --gnu  isisd/Makefile
+	  $(AUTOMAKE) --foreign  isisd/Makefile
 Makefile:  $(srcdir)/Makefile.in  $(top_builddir)/config.status
 	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
 
@@ -217,18 +256,16 @@
 	  p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
 	  if test -f $$p \
 	  ; then \
-	    p1=`echo "$$p1" | sed -e 's,^.*/,,'`; \
-	    f=`echo $$p1|sed '$(transform);s/$$/$(EXEEXT)/'`; \
+	    f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
 	   echo " $(INSTALL_PROGRAM_ENV) $(sbinPROGRAMS_INSTALL) $$p $(DESTDIR)$(sbindir)/$$f"; \
-	   $(INSTALL_PROGRAM_ENV) $(sbinPROGRAMS_INSTALL) $$p $(DESTDIR)$(sbindir)/$$f; \
+	   $(INSTALL_PROGRAM_ENV) $(sbinPROGRAMS_INSTALL) $$p $(DESTDIR)$(sbindir)/$$f || exit 1; \
 	  else :; fi; \
 	done
 
 uninstall-sbinPROGRAMS:
 	@$(NORMAL_UNINSTALL)
 	@list='$(sbin_PROGRAMS)'; for p in $$list; do \
-	  f=`echo $$p|sed 's/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
-	  f=`echo "$$f" | sed -e 's,^.*/,,'`; \
+	  f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
 	  echo " rm -f $(DESTDIR)$(sbindir)/$$f"; \
 	  rm -f $(DESTDIR)$(sbindir)/$$f; \
 	done
@@ -266,21 +303,27 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isisd.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iso_checksum.Po@am__quote@
 
-distclean-depend:
-	-rm -rf ./$(DEPDIR)
-
 .c.o:
-@AMDEP_TRUE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
-@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-	$(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
+@am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
+@am__fastdepCC_TRUE@	  -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \
+@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
+@am__fastdepCC_TRUE@	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@	fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
 
 .c.obj:
-@AMDEP_TRUE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
-@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-	$(COMPILE) -c `cygpath -w $<`
-CCDEPMODE = @CCDEPMODE@
+@am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
+@am__fastdepCC_TRUE@	  -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
+@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
+@am__fastdepCC_TRUE@	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@	fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`
 uninstall-info-am:
 sysconfDATA_INSTALL = $(INSTALL_DATA)
 
@@ -295,6 +338,9 @@
 ETAGS = etags
 ETAGSFLAGS =
 
+CTAGS = ctags
+CTAGSFLAGS =
+
 tags: TAGS
 
 ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
@@ -320,20 +366,41 @@
 	  || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
 	     $$tags $$unique
 
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	tags=; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	test -z "$(CTAGS_ARGS)$$tags$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$tags $$unique
+
 GTAGS:
 	here=`$(am__cd) $(top_builddir) && pwd` \
 	  && cd $(top_srcdir) \
 	  && gtags -i $(GTAGS_ARGS) $$here
 
 distclean-tags:
-	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 
 top_distdir = ..
 distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
 
 distdir: $(DISTFILES)
-	@list='$(DISTFILES)'; for file in $$list; do \
+	@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
+	list='$(DISTFILES)'; for file in $$list; do \
+	  case $$file in \
+	    $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
+	    $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
+	  esac; \
 	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
 	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
 	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
@@ -359,7 +426,6 @@
 
 installdirs:
 	$(mkinstalldirs) $(DESTDIR)$(sbindir) $(DESTDIR)$(sysconfdir)
-
 install: install-am
 install-exec: install-exec-am
 install-data: install-data-am
@@ -371,7 +437,7 @@
 installcheck: installcheck-am
 install-strip:
 	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-	  INSTALL_STRIP_FLAG=-s \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
 	  `test -z '$(STRIP)' || \
 	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
 mostlyclean-generic:
@@ -379,7 +445,7 @@
 clean-generic:
 
 distclean-generic:
-	-rm -f Makefile $(CONFIG_CLEAN_FILES)
+	-rm -f $(CONFIG_CLEAN_FILES)
 
 maintainer-clean-generic:
 	@echo "This command is intended for maintainers to use"
@@ -390,9 +456,10 @@
 	mostlyclean-am
 
 distclean: distclean-am
-
-distclean-am: clean-am distclean-compile distclean-depend \
-	distclean-generic distclean-tags
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
 
 dvi: dvi-am
 
@@ -413,27 +480,36 @@
 installcheck-am:
 
 maintainer-clean: maintainer-clean-am
-
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
 maintainer-clean-am: distclean-am maintainer-clean-generic
 
 mostlyclean: mostlyclean-am
 
 mostlyclean-am: mostlyclean-compile mostlyclean-generic
 
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
 uninstall-am: uninstall-info-am uninstall-sbinPROGRAMS \
 	uninstall-sysconfDATA
 
-.PHONY: GTAGS all all-am check check-am clean clean-generic \
-	clean-noinstLIBRARIES clean-sbinPROGRAMS distclean \
-	distclean-compile distclean-depend distclean-generic \
-	distclean-tags distdir dvi dvi-am info info-am install \
-	install-am install-data install-data-am install-exec \
-	install-exec-am install-info install-info-am install-man \
-	install-sbinPROGRAMS install-strip install-sysconfDATA \
-	installcheck installcheck-am installdirs maintainer-clean \
-	maintainer-clean-generic mostlyclean mostlyclean-compile \
-	mostlyclean-generic tags uninstall uninstall-am \
-	uninstall-info-am uninstall-sbinPROGRAMS uninstall-sysconfDATA
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+	clean-noinstLIBRARIES clean-sbinPROGRAMS ctags distclean \
+	distclean-compile distclean-generic distclean-tags distdir dvi \
+	dvi-am info info-am install install-am install-data \
+	install-data-am install-exec install-exec-am install-info \
+	install-info-am install-man install-sbinPROGRAMS install-strip \
+	install-sysconfDATA installcheck installcheck-am installdirs \
+	maintainer-clean maintainer-clean-generic mostlyclean \
+	mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
+	tags uninstall uninstall-am uninstall-info-am \
+	uninstall-sbinPROGRAMS uninstall-sysconfDATA
 
 
 install-sysconfDATA: $(sysconf_DATA)
@@ -448,16 +524,6 @@
 	    $(INSTALL_SDATA) $$p $(DESTDIR)$(sysconfdir)/$$p; \
 	  fi; fi; \
 	done
-
-depend:
-	@$(CPP) -MM $(INCLUDES) $(LDFLAGS) *.c
-
-isis_adjacency.o : isis_adjacency.c ../lib/version.h ../lib/log.h \
- ../isisd/isis_adjacency.h
-isis_pdu.o : isis_pdu.c ../lib/log.h ../isisd/isisd.h \
- ../isisd/isis_constants.h ../isisd/isis_adjacency.h \
- ../isisd/isis_pdu.h
-isis_circuit.o : isis_circuit.c ../isisd/isis_circuit.h
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
diff --git a/isisd/isis_dynhn.c b/isisd/isis_dynhn.c
index 9e151d0..0ba1842 100644
--- a/isisd/isis_dynhn.c
+++ b/isisd/isis_dynhn.c
@@ -117,7 +117,7 @@
 	     VTY_NEWLINE);
   }
   
-  vty_out (vty,  "     * %s %s%s", sysid_print (isis->sysid), host.name, 
+  vty_out (vty,  "     * %s %s%s", sysid_print (isis->sysid), unix_hostname(), 
 	   VTY_NEWLINE);
   return;
 }
diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c
index 6bfb0fd..f797b9e 100644
--- a/isisd/isis_lsp.c
+++ b/isisd/isis_lsp.c
@@ -60,7 +60,6 @@
 
 extern struct isis *isis;
 extern struct thread_master *master;
-extern struct host host;
 
 int 
 lsp_id_cmp (u_char *id1, u_char *id2)
@@ -638,7 +637,7 @@
   if (dyn)
     sprintf (id, "%.14s", dyn->name.name);
   else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost)
-    sprintf (id, "%.14s", host.name);
+    sprintf (id, "%.14s", unix_hostname());
    else {
     memcpy(id, sysid_print (lsp_id), 15);
   }
@@ -1053,8 +1052,9 @@
   if (area->dynhostname) {
     lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV, 
                                       sizeof (struct hostname));
-    memcpy (&lsp->tlv_data.hostname->name, host.name, strlen(host.name));
-    lsp->tlv_data.hostname->namelen = strlen (host.name);
+    memcpy (&lsp->tlv_data.hostname->name, unix_hostname(),
+            strlen(unix_hostname()));
+    lsp->tlv_data.hostname->namelen = strlen (unix_hostname());
   }
 #ifdef TOPOLOGY_GENERATE
   /*
@@ -1337,8 +1337,10 @@
   if (area->dynhostname) {
     lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV, 
                                       sizeof (struct hostname));
-    memcpy (lsp->tlv_data.hostname->name, host.name, strlen (host.name));
-    lsp->tlv_data.hostname->namelen = strlen (host.name);
+
+    memcpy (lsp->tlv_data.hostname->name, unix_hostname(),
+            strlen (unix_hostname()));
+    lsp->tlv_data.hostname->namelen = strlen (unix_hostname());
   }
 
   /*
@@ -1553,13 +1555,14 @@
   if (area->dynhostname) {
     tlv_ptr = lsppdu_realloc (lsp,MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
     *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
-    *(tlv_ptr+1) = strlen (host.name); /* Length */
+    *(tlv_ptr+1) = strlen (unix_hostname()); /* Length */
     lsp->tlv_data.hostname = (struct hostname *)
       (lsppdu_realloc(lsp,
 		      MTYPE_ISIS_TLV,
 		      /* the -1 is to fit the length in the struct */
-		      strlen (host.name)) - 1); 
-    memcpy (lsp->tlv_data.hostname->name, host.name, strlen(host.name));
+		      strlen (unix_hostname())) - 1); 
+    memcpy (lsp->tlv_data.hostname->name, unix_hostname(),
+            strlen(unix_hostname()));
   }
 
 }
diff --git a/isisd/isis_main.c b/isisd/isis_main.c
index baf5f38..8106492 100644
--- a/isisd/isis_main.c
+++ b/isisd/isis_main.c
@@ -33,6 +33,7 @@
 #include "memory.h"
 #include "stream.h"
 #include "if.h"
+#include "privs.h"
 
 #include "isisd/dict.h"
 #include "include-netbsd/iso.h"
@@ -48,12 +49,36 @@
 /* Default vty port */
 #define ISISD_VTY_PORT       2607
 
+/* isisd privileges */
+zebra_capabilities_t _caps_p [] = 
+{
+  ZCAP_RAW,
+  ZCAP_BIND
+};
+
+struct zebra_privs_t isisd_privs =
+{
+#if defined(QUAGGA_USER)
+  .user = QUAGGA_USER,
+#endif
+#if defined QUAGGA_GROUP
+  .group = QUAGGA_GROUP,
+#endif
+#ifdef VTY_GROUP
+  .vty_group = VTY_GROUP,
+#endif
+  .caps_p = _caps_p,
+  .cap_num_p = 2,
+  .cap_num_i = 0
+};
+
 /* isisd options */
 struct option longopts[] = 
 {
   { "daemon",      no_argument,       NULL, 'd'},
   { "config_file", required_argument, NULL, 'f'},
   { "vty_port",    required_argument, NULL, 'P'},
+  { "user",        required_argument, NULL, 'u'},
   { "version",     no_argument,       NULL, 'v'},
   { "help",        no_argument,       NULL, 'h'},
   { 0 }
@@ -94,6 +119,7 @@
 -d, --daemon       Runs in daemon mode\n\
 -f, --config_file  Set configuration file name\n\
 -P, --vty_port     Set vty's port number\n\
+-u, --user         User and group to run as\n\
 -v, --version      Print program version\n\
 -h, --help         Display this help and exit\n\
 \n\
@@ -230,7 +256,7 @@
   /* Command line argument treatment. */
   while (1) 
     {
-      opt = getopt_long (argc, argv, "df:hAp:P:v", longopts, 0);
+      opt = getopt_long (argc, argv, "df:hAp:P:u:v", longopts, 0);
     
       if (opt == EOF)
         break;
@@ -249,7 +275,19 @@
           vty_addr = optarg;
           break;
         case 'P':
+         /* Deal with atoi() returning 0 on failure, and isisd not
+             listening on isisd port... */
+          if (strcmp(optarg, "0") == 0) 
+            {
+              vty_port = 0;
+              break;
+            } 
           vty_port = atoi (optarg);
+          vty_port = (vty_port ? vty_port : ISISD_VTY_PORT);
+	  break;
+        case 'u':
+          isisd_privs.user = isisd_privs.group = optarg;
+          break;
           break;
         case 'v':
 	  printf("ISISd version %s\n", ISISD_VERSION);
@@ -276,9 +314,10 @@
   /*
    *  initializations
    */
+  zprivs_init (&isisd_privs);
   signal_init ();
   cmd_init (1);
-  vty_init ();
+  vty_init (master);
   memory_init ();
   isis_init ();
   dyn_cache_init ();
@@ -295,19 +334,18 @@
   if (daemon_mode)
     daemon (0, 0);
 
-  /* Problems with the build env ?*/
-#ifndef PATH_ISISD_PID
-#define PATH_ISISD_PID "/var/run/isisd.pid"
-#endif
   /* Process ID file creation. */
   pid_output (PATH_ISISD_PID);
 
   /* Make isis vty socket. */
-  vty_serv_sock (vty_addr, vty_port ? vty_port : ISISD_VTY_PORT, 
-                 ISIS_VTYSH_PATH);
+  vty_serv_sock (vty_addr, vty_port, ISIS_VTYSH_PATH);
   
   /* Print banner. */
+#if defined(ZEBRA_VERSION)
   zlog_info ("ISISd %s starting: vty@%d", ZEBRA_VERSION, vty_port);
+#elif defined(QUAGGA_VERSION)
+  zlog_info ("Quagga-ISISd %s starting: vty@%d", QUAGGA_VERSION, vty_port);
+#endif
 #ifdef HAVE_IPV6
   zlog_info ("IPv6 enabled");
 #endif
diff --git a/isisd/isis_misc.c b/isisd/isis_misc.c
index 763ae24..cf558e8 100644
--- a/isisd/isis_misc.c
+++ b/isisd/isis_misc.c
@@ -28,12 +28,13 @@
 #include <ctype.h>
 #include <zebra.h>
 #include <net/ethernet.h>
-
+#include <sys/utsname.h>
 
 #include "stream.h"
 #include "vty.h"
 #include "hash.h"
 #include "if.h"
+#include "command.h"
 
 #include "isisd/dict.h"
 #include "isisd/isis_constants.h"
@@ -432,7 +433,22 @@
   return new_prefix;
 }
 
+/*
+ * Returns host.name if any, otherwise
+ * it returns the system hostname.
+ */
+const char *
+unix_hostname(void)
+{
+  static struct utsname names;
+  const char *hostname;
+  extern struct host host;
 
+  hostname = host.name;
+  if (!hostname) { 
+    uname(&names);
+    hostname = names.nodename;
+  }
 
-
-
+  return hostname;
+}
diff --git a/isisd/isis_misc.h b/isisd/isis_misc.h
index 0e219c6..ca0c0ae 100644
--- a/isisd/isis_misc.h
+++ b/isisd/isis_misc.h
@@ -53,6 +53,8 @@
  */
 int  speaks (struct nlpids *nlpids, int family);
 unsigned long isis_jitter (unsigned long timer, unsigned long jitter);
+const char * unix_hostname(void);
+
 
 /*
  * macros
diff --git a/isisd/isis_network.c b/isisd/isis_network.c
index d22f3dd..c10aeeb 100644
--- a/isisd/isis_network.c
+++ b/isisd/isis_network.c
@@ -42,6 +42,10 @@
 #include "isisd/isis_circuit.h"
 #include "isisd/isis_network.h"
 
+#include "privs.h"
+
+extern struct zebra_privs_t isisd_privs;
+
 /*
  * On linux we can use the packet(7) sockets, in other OSs we have to do with
  * Berkley Packet Filter (BPF). Please tell me if you can think of a better 
@@ -297,28 +301,39 @@
 {
   int retval = ISIS_OK;
 
+  if ( isisd_privs.change (ZPRIVS_RAISE) )
+    zlog_err ("%s: could not raise privs, %s", __func__,
+               strerror (errno) );
 
 #ifdef GNU_LINUX
   retval = open_packet_socket (circuit);
 #else
   retval = open_bpf_dev (circuit);
 #endif
-  
-  if (retval == ISIS_OK) {
-    if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
-      circuit->tx = isis_send_pdu_bcast;
-      circuit->rx = isis_recv_pdu_bcast;
-    }
-    else if (circuit->circ_type == CIRCUIT_T_P2P) {
-      circuit->tx = isis_send_pdu_p2p;
-      circuit->rx = isis_recv_pdu_p2p;
-    }
-    else {
-      zlog_warn ("isis_sock_init(): unknown circuit type");
-      retval = ISIS_WARNING;
-    }
+
+  if (retval != ISIS_OK) {
+    zlog_warn("%s: could not initialize the socket",
+              __func__);
+    goto end;
   }
-  
+ 
+  if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
+    circuit->tx = isis_send_pdu_bcast;
+    circuit->rx = isis_recv_pdu_bcast;
+  } else if (circuit->circ_type == CIRCUIT_T_P2P) {
+    circuit->tx = isis_send_pdu_p2p;
+    circuit->rx = isis_recv_pdu_p2p;
+  } else {
+    zlog_warn ("isis_sock_init(): unknown circuit type");
+    retval = ISIS_WARNING;
+    goto end;
+  }
+ 
+end:
+  if ( isisd_privs.change (ZPRIVS_LOWER) )
+    zlog_err ("%s: could not lower privs, %s", __func__,
+               strerror (errno) );
+
   return retval;
 }
 
diff --git a/isisd/isisd.c b/isisd/isisd.c
index 8794a12..3b8a0a6 100644
--- a/isisd/isisd.c
+++ b/isisd/isisd.c
@@ -506,6 +506,79 @@
   return CMD_SUCCESS;
 }
 
+/* Debug node. */
+static struct cmd_node debug_node =
+{
+  DEBUG_NODE,
+ "",
+ 1
+};
+
+static int
+config_write_debug (struct vty *vty)
+{
+  int write = 0;
+  int flags = isis->debugs;
+
+  if (flags & DEBUG_ADJ_PACKETS) {
+    vty_out (vty, "debug isis adj-packets%s",
+             VTY_NEWLINE);
+    write++;
+  }
+  if (flags & DEBUG_CHECKSUM_ERRORS) {
+    vty_out (vty, "debug isis checksum-errors%s",
+             VTY_NEWLINE);
+    write++;
+  }
+  if (flags & DEBUG_LOCAL_UPDATES) {
+    vty_out (vty, "debug isis local-updates%s",
+             VTY_NEWLINE);
+    write++;
+  }
+  if (flags & DEBUG_PROTOCOL_ERRORS) {
+    vty_out (vty, "debug isis protocol-errors%s",  
+             VTY_NEWLINE);
+    write++;
+  }
+  if (flags & DEBUG_SNP_PACKETS) {
+    vty_out (vty, "debug isis snp-packets%s",
+             VTY_NEWLINE);
+    write++;
+  }
+  if (flags & DEBUG_SPF_EVENTS) {
+    vty_out (vty, "debug isis spf-events%s",
+             VTY_NEWLINE);
+    write++;
+  }
+  if (flags & DEBUG_SPF_STATS) {
+    vty_out (vty, "debug isis spf-statistics%s",
+             VTY_NEWLINE);
+    write++;
+  }
+  if (flags & DEBUG_SPF_TRIGGERS) {
+    vty_out (vty, "debug isis spf-triggers%s",
+             VTY_NEWLINE);
+    write++;
+  }
+  if (flags & DEBUG_UPDATE_PACKETS) {
+    vty_out (vty, "debug isis update-packets%s",
+             VTY_NEWLINE);
+    write++;
+  }
+  if (flags & DEBUG_RTE_EVENTS) {
+    vty_out (vty, "debug isis route-events%s",
+             VTY_NEWLINE);
+    write++;
+  }
+  if (flags & DEBUG_EVENTS) {
+    vty_out (vty, "debug isis events%s",
+             VTY_NEWLINE);
+    write++;
+  }
+
+  return write;
+}
+
 DEFUN (debug_isis_adj,
        debug_isis_adj_cmd,
        "debug isis adj-packets",
@@ -1893,6 +1966,8 @@
   install_element (ENABLE_NODE, &show_database_detail_cmd);
   install_element (ENABLE_NODE, &show_debugging_cmd);
 
+  install_node(&debug_node, config_write_debug);
+
   install_element (ENABLE_NODE, &debug_isis_adj_cmd);
   install_element (ENABLE_NODE, &no_debug_isis_adj_cmd);
   install_element (ENABLE_NODE, &debug_isis_csum_cmd);
@@ -1916,6 +1991,29 @@
   install_element (ENABLE_NODE, &debug_isis_events_cmd);
   install_element (ENABLE_NODE, &no_debug_isis_events_cmd);
 
+  install_element (CONFIG_NODE, &debug_isis_adj_cmd);
+  install_element (CONFIG_NODE, &no_debug_isis_adj_cmd);
+  install_element (CONFIG_NODE, &debug_isis_csum_cmd);
+  install_element (CONFIG_NODE, &no_debug_isis_csum_cmd);
+  install_element (CONFIG_NODE, &debug_isis_lupd_cmd);
+  install_element (CONFIG_NODE, &no_debug_isis_lupd_cmd);
+  install_element (CONFIG_NODE, &debug_isis_err_cmd);
+  install_element (CONFIG_NODE, &no_debug_isis_err_cmd);
+  install_element (CONFIG_NODE, &debug_isis_snp_cmd);
+  install_element (CONFIG_NODE, &no_debug_isis_snp_cmd);
+  install_element (CONFIG_NODE, &debug_isis_upd_cmd);
+  install_element (CONFIG_NODE, &no_debug_isis_upd_cmd);
+  install_element (CONFIG_NODE, &debug_isis_spfevents_cmd);
+  install_element (CONFIG_NODE, &no_debug_isis_spfevents_cmd);
+  install_element (CONFIG_NODE, &debug_isis_spfstats_cmd);
+  install_element (CONFIG_NODE, &no_debug_isis_spfstats_cmd);
+  install_element (CONFIG_NODE, &debug_isis_spftrigg_cmd);
+  install_element (CONFIG_NODE, &no_debug_isis_spftrigg_cmd);
+  install_element (CONFIG_NODE, &debug_isis_rtevents_cmd);
+  install_element (CONFIG_NODE, &no_debug_isis_rtevents_cmd);
+  install_element (CONFIG_NODE, &debug_isis_events_cmd);
+  install_element (CONFIG_NODE, &no_debug_isis_events_cmd);
+
   install_element (CONFIG_NODE, &router_isis_cmd);
   install_element (CONFIG_NODE, &no_router_isis_cmd);
 
diff --git a/isisd/isisd.h b/isisd/isisd.h
index 67bf8d6..3ca421a 100644
--- a/isisd/isisd.h
+++ b/isisd/isisd.h
@@ -24,7 +24,6 @@
 #define ISISD_H
 
 #define ISISD_VERSION "0.0.7"
-#define ISIS_VTYSH_PATH        "/tmp/.isisd"
 
 /* uncomment if you are a developer in bug hunt */
 /* #define EXTREME_DEBUG  */