nmh-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nmh-commits] [SCM] The nmh Mail Handling System branch, master, updated


From: David Levine
Subject: [Nmh-commits] [SCM] The nmh Mail Handling System branch, master, updated. 8fcc5d7f43931e3ec9053b20f5e050b7a4008bc9
Date: Wed, 14 Mar 2012 02:28:45 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The nmh Mail Handling System".

The branch, master has been updated
       via  8fcc5d7f43931e3ec9053b20f5e050b7a4008bc9 (commit)
      from  deceb473fdbaf526c46ff696a8d7afc3a81e4d90 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/nmh.git/commit/?id=8fcc5d7f43931e3ec9053b20f5e050b7a4008bc9


commit 8fcc5d7f43931e3ec9053b20f5e050b7a4008bc9
Author: David Levine <address@hidden>
Date:   Tue Mar 13 21:20:47 2012 -0500

    Added test/getfqnd.c, a replacement for "hostname" that always
    tries to provide the fully qualified domainname of the host, even
    on Cygwin.  It uses the code that LocalName in sbr/mts.c uses.

diff --git a/.gitignore b/.gitignore
index 87e31cb..d1dd750 100644
--- a/.gitignore
+++ b/.gitignore
@@ -45,7 +45,7 @@ a.out.DSYM/
 /mts/libmts.a
 /sbr/*.a
 /sbr/sigmsg.h
-/test/testdir
+/test/testdir/
 /uip/ali
 /uip/anno
 /uip/ap
@@ -97,6 +97,7 @@ a.out.DSYM/
 /uip/whom
 /uip/*.exe
 /test/getfullname
+/test/getfqdn
 
 # Removed by mostlyclean:
 *.o
diff --git a/Makefile.am b/Makefile.am
index c87160c..9ca7740 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -65,7 +65,7 @@ TESTS = test/bad-input/test-header \
        test/cleanup ## The "cleanup" test should always be last.
 
 check_SCRIPTS = test/common.sh
-check_PROGRAMS = test/getfullname
+check_PROGRAMS = test/getfullname test/getfqdn
 
 ##
 ## Stuff that should be cleaned via "make clean"
@@ -363,6 +363,9 @@ uip_viamail_SOURCES = uip/viamail.c uip/mhmisc.c 
uip/mhoutsbr.c uip/sendsbr.c \
 test_getfullname_SOURCES = test/getfullname.c
 test_getfullname_LDADD =
 
+test_getfqdn_SOURCES = test/getfqdn.c
+test_getfqdn_LDADD =
+
 ##
 ## Our rebuild rules for files that aren't built via the normal mechanisms
 ##
diff --git a/test/format/test-myhost b/test/format/test-myhost
index 27069af..635f35f 100755
--- a/test/format/test-myhost
+++ b/test/format/test-myhost
@@ -13,7 +13,8 @@ fi
 
 setup_test
 
-run_test "${MH_LIB_DIR}/ap -format %(myhost) ignore" "`hostname`" \
+host=`${MH_OBJ_DIR}/test/getfqdn`
+run_test "${MH_LIB_DIR}/ap -format %(myhost) ignore" "$host" \
          "local hostname test"
 
 cp ${MHMTSCONF} ${MH_TEST_DIR}/Mail/mts.conf || exit 1
diff --git a/test/format/test-mymbox b/test/format/test-mymbox
index e3decd9..c154a8b 100755
--- a/test/format/test-mymbox
+++ b/test/format/test-mymbox
@@ -14,7 +14,7 @@ fi
 setup_test
 
 user="`id -un`"
-host="`hostname`"
+host=`${MH_OBJ_DIR}/test/getfqdn`
 
 run_test "${MH_LIB_DIR}/ap -format %(mymbox{text}) ${user}" \
          1 "Basic user test"
diff --git a/test/getfqdn.c b/test/getfqdn.c
new file mode 100644
index 0000000..23685da
--- /dev/null
+++ b/test/getfqdn.c
@@ -0,0 +1,51 @@
+/*
+ * getfqdn.c - Print the FQDN of a host, default to localhost.
+ *
+ * This code is Copyright (c) 2012, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
+ */
+
+#include <netdb.h>   /* for getaddrinfo */
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>  /* for gethostname */
+#include <limits.h>  /* for _POSIX_HOST_NAME_MAX */
+#include <string.h>  /* for memset */
+#include <stdio.h>
+
+
+int
+main(int argc, char *argv[])
+{
+  char buf[_POSIX_HOST_NAME_MAX + 1];
+  const char *hostname = buf;
+  struct addrinfo hints, *res;
+  int status = 0;
+
+  /* Borrowed the important code below from LocalName() in sbr/mts.c. */
+
+  if (argc < 2) {
+    /* First get our local name. */
+    status = gethostname(buf, sizeof buf);
+  } else if (argc == 2) {
+    hostname = argv[1];
+  } else if (argc > 2) {
+    fprintf (stderr, "usage: %s [hostname]\n", argv[0]);
+    return 1;
+  }
+
+  if (status == 0) {
+    /* Now fully qualify the hostname. */
+    memset(&hints, 0, sizeof hints);
+    hints.ai_flags = AI_CANONNAME;
+    hints.ai_family = AF_UNSPEC;
+
+    if ((status = getaddrinfo(hostname, NULL, &hints, &res)) == 0) {
+      printf ("%s\n", res->ai_canonname);
+      freeaddrinfo(res);
+    }
+  }
+
+  return status;
+}

-----------------------------------------------------------------------

Summary of changes:
 .gitignore              |    3 +-
 Makefile.am             |    5 +++-
 test/format/test-myhost |    3 +-
 test/format/test-mymbox |    2 +-
 test/getfqdn.c          |   51 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 60 insertions(+), 4 deletions(-)
 create mode 100644 test/getfqdn.c


hooks/post-receive
-- 
The nmh Mail Handling System



reply via email to

[Prev in Thread] Current Thread [Next in Thread]