diff mts/mh/hosts.c @ 0:bce86c4163a3

Initial revision
author kono
date Mon, 18 Apr 2005 23:46:02 +0900
parents
children 441a2190cfae
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mts/mh/hosts.c	Mon Apr 18 23:46:02 2005 +0900
@@ -0,0 +1,64 @@
+/* hosts.c - find out the official name of a host */
+#ifndef	lint
+static char ident[] = "@(#)$Id$";
+#endif	/* lint */
+
+/* LINTLIBRARY */
+
+#undef	NETWORK
+#if	defined(BSD41A) || defined(BSD42) || defined(SOCKETS)
+#define	NETWORK
+#endif	/* not (defined(BSD41A) || defined(BSD42) || defined(SOCKETS)) */
+
+#include "../h/strings.h"
+#include <stdio.h>
+#include "../zotnet/mts.h"
+#include <ctype.h>
+#if	defined(BSD42) || defined(SOCKETS)
+#include <netdb.h>
+#endif	/* BSD42 or SOCKETS */
+
+
+#define	NOTOK	(-1)
+
+/*  */
+
+struct hostent *mh_gethostbyname();
+
+char   *OfficialName (name)
+char   *name;
+{
+    register char  *p;
+    char   *q,
+	    site[BUFSIZ];
+#ifdef	NETWORK
+    static char buffer[BUFSIZ];
+#if	defined(BSD42) || defined(SOCKETS)
+    register struct hostent *hp;
+#endif	/* BSD42 or SOCKETS */
+#endif	/* NETWORK */
+
+    for (p = name, q = site; *p; p++, q++)
+	*q = isupper (*p) ? tolower (*p) : *p;
+    *q = 0;
+    q = site;
+
+    if (uleq (LocalName (), site))
+	return LocalName ();
+
+#ifdef	BSD41A
+    if (rhost (&q) != NOTOK) {
+	(void) strcpy (buffer, q);
+	free (q);
+	return buffer;
+    }
+#endif	/* BSD41A */
+#if	defined(BSD42) || defined(SOCKETS)
+    if (hp = mh_gethostbyname (q)) {
+	(void) strcpy (buffer, hp -> h_name);
+	return buffer;
+    }
+#endif	/* BSD42 or SOCKETS */
+
+    return NULL;
+}