Added primitives HOSTNAME and FULL-HOSTNAME to get the short host name
authorMark Friedman <edu/mit/csail/zurich/markf>
Mon, 12 Aug 1991 22:16:02 +0000 (22:16 +0000)
committerMark Friedman <edu/mit/csail/zurich/markf>
Mon, 12 Aug 1991 22:16:02 +0000 (22:16 +0000)
and the full host name with domain.

v7/src/microcode/pruxenv.c
v7/src/microcode/ux.h

index 12088e370b795862270ac5a94a82e12f3dd3d21b..f655b7da150a0e4b6b5b1327085ad16109039b91 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/pruxenv.c,v 1.1 1990/06/20 19:38:41 cph Rel $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/pruxenv.c,v 1.2 1991/08/12 22:15:40 markf Exp $
 
 Copyright (c) 1990 Massachusetts Institute of Technology
 
@@ -38,6 +38,13 @@ MIT in each case. */
 #include "prims.h"
 #include "ux.h"
 
+#ifdef HAVE_SOCKETS
+#include "uxsock.h"
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#endif
+
 extern char ** environ;
 \f
 DEFINE_PRIMITIVE ("CURRENT-FILE-TIME", Prim_current_file_time, 0, 0,
@@ -139,3 +146,40 @@ DEFINE_PRIMITIVE ("UNIX-ENVIRONMENT", Prim_unix_environment_alist, 0, 0,
     }
   }
 }
+
+#define HOSTNAMESIZE 1024
+
+DEFINE_PRIMITIVE ("FULL-HOSTNAME", Prim_full_hostname, 0, 0,
+  "Returns the full hostname (including domain if available) as a string.")
+{
+  PRIMITIVE_HEADER (0);
+  {
+    char this_host_name[HOSTNAMESIZE];
+#ifdef HAVE_SOCKETS
+    struct hostent *gethostbyname(char *);
+    struct hostent *this_host_entry;
+#endif
+    STD_VOID_SYSTEM_CALL (syscall_gethostname,
+                         UX_gethostname (this_host_name, HOSTNAMESIZE));
+
+#ifdef HAVE_SOCKETS
+    this_host_entry = gethostbyname (this_host_name);
+    PRIMITIVE_RETURN (char_pointer_to_string (this_host_entry->h_name));
+#else
+    PRIMITIVE_RETURN (char_pointer_to_string (this_host_name));
+#endif
+  }
+}
+
+DEFINE_PRIMITIVE ("HOSTNAME", Prim_hostname, 0, 0,
+  "Returns the hostname of the machine as a string.")
+{
+  PRIMITIVE_HEADER (0);
+  {
+    char this_host_name[HOSTNAMESIZE];
+
+    STD_VOID_SYSTEM_CALL (syscall_gethostname,
+                         UX_gethostname (this_host_name, HOSTNAMESIZE));
+    PRIMITIVE_RETURN (char_pointer_to_string (this_host_name));
+  }
+}
index 0fee63576235ee41ecb029fffac324b6e4e58ba6..6f58a9afdbfe3626e67e54a5ac1ce6c5409f1791 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/ux.h,v 1.23 1991/06/15 00:40:24 cph Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/ux.h,v 1.24 1991/08/12 22:16:02 markf Exp $
 
 Copyright (c) 1988-91 Massachusetts Institute of Technology
 
@@ -74,6 +74,7 @@ enum syscall_names
   syscall_fstat,
   syscall_ftruncate,
   syscall_getcwd,
+  syscall_gethostname,
   syscall_gettimeofday,
   syscall_ioctl_TIOCGPGRP,
   syscall_ioctl_TIOCSIGSEND,
@@ -679,6 +680,7 @@ extern char * EXFUN (getlogin, (void));
 #define UX_getegid getegid
 #define UX_geteuid geteuid
 #define UX_getgrgid getgrgid
+#define UX_gethostname gethostname
 #define UX_getlogin getlogin
 #define UX_getpid getpid
 #define UX_getpwnam getpwnam
@@ -705,6 +707,7 @@ extern char * EXFUN (getlogin, (void));
 extern PTR EXFUN (malloc, (unsigned int size));
 extern PTR EXFUN (realloc, (PTR ptr, unsigned int size));
 extern CONST char * EXFUN (getenv, (CONST char * name));
+extern int EXFUN (gethostname, (char * name, unsigned int size));
 
 #ifdef HAVE_FCNTL
 #define UX_fcntl fcntl