From cfbc313559d850af891669f6772964ccf2a0c0fb Mon Sep 17 00:00:00 2001 From: Mark Friedman Date: Mon, 12 Aug 1991 22:16:02 +0000 Subject: [PATCH] Added primitives HOSTNAME and FULL-HOSTNAME to get the short host name and the full host name with domain. --- v7/src/microcode/pruxenv.c | 46 +++++++++++++++++++++++++++++++++++++- v7/src/microcode/ux.h | 5 ++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/v7/src/microcode/pruxenv.c b/v7/src/microcode/pruxenv.c index 12088e370..f655b7da1 100644 --- a/v7/src/microcode/pruxenv.c +++ b/v7/src/microcode/pruxenv.c @@ -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 +#include +#include +#endif + extern char ** environ; 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)); + } +} diff --git a/v7/src/microcode/ux.h b/v7/src/microcode/ux.h index 0fee63576..6f58a9afd 100644 --- a/v7/src/microcode/ux.h +++ b/v7/src/microcode/ux.h @@ -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 -- 2.25.1