From a8f0fc96cc592cd905fa709dd773b5177f2ec882 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Fri, 13 Aug 1999 18:29:38 +0000 Subject: [PATCH] Add new primitive GET-HOST-BY-ADDRESS. --- v7/src/microcode/ntsock.c | 15 ++++++++++++++- v7/src/microcode/os2sock.c | 15 ++++++++++++++- v7/src/microcode/pruxsock.c | 19 ++++++++++++++++++- v7/src/microcode/uxsock.c | 19 ++++++++++++++++--- v7/src/microcode/uxsock.h | 3 ++- 5 files changed, 64 insertions(+), 7 deletions(-) diff --git a/v7/src/microcode/ntsock.c b/v7/src/microcode/ntsock.c index 57652a296..942a8b7e9 100644 --- a/v7/src/microcode/ntsock.c +++ b/v7/src/microcode/ntsock.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntsock.c,v 1.5 1999/01/02 06:11:34 cph Exp $ +$Id: ntsock.c,v 1.6 1999/08/13 18:29:38 cph Exp $ Copyright (c) 1997-1999 Massachusetts Institute of Technology @@ -157,6 +157,19 @@ OS_canonical_host_name (const char * host_name) return (result); } } + +const char * +OS_get_host_by_address (const char * host_addr) +{ + struct hostent * entry = (gethostbyaddr (host_addr)); + if (entry == 0) + return (0); + { + char * result = (OS_malloc ((strlen (entry -> h_name)) + 1)); + strcpy (result, (entry -> h_name)); + return (result); + } +} #ifndef SOCKET_LISTEN_BACKLOG #define SOCKET_LISTEN_BACKLOG 5 diff --git a/v7/src/microcode/os2sock.c b/v7/src/microcode/os2sock.c index c00c82d46..b5ed7f2df 100644 --- a/v7/src/microcode/os2sock.c +++ b/v7/src/microcode/os2sock.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: os2sock.c,v 1.10 1999/04/28 03:27:55 cph Exp $ +$Id: os2sock.c,v 1.11 1999/08/13 18:29:34 cph Exp $ Copyright (c) 1990-1999 Massachusetts Institute of Technology @@ -175,6 +175,19 @@ OS_canonical_host_name (const char * host_name) return (result); } } + +const char * +OS_get_host_by_address (const char * host_addr) +{ + struct hostent * entry = (gethostbyaddr (host_addr)); + if (entry == 0) + return (0); + { + char * result = (OS_malloc ((strlen (entry -> h_name)) + 1)); + strcpy (result, (entry -> h_name)); + return (result); + } +} #ifndef SOCKET_LISTEN_BACKLOG #define SOCKET_LISTEN_BACKLOG 5 diff --git a/v7/src/microcode/pruxsock.c b/v7/src/microcode/pruxsock.c index ecb900cec..48b0f5677 100644 --- a/v7/src/microcode/pruxsock.c +++ b/v7/src/microcode/pruxsock.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: pruxsock.c,v 1.16 1999/01/02 06:11:34 cph Exp $ +$Id: pruxsock.c,v 1.17 1999/08/13 18:29:06 cph Exp $ Copyright (c) 1990-1999 Massachusetts Institute of Technology @@ -156,6 +156,23 @@ DEFINE_PRIMITIVE ("CANONICAL-HOST-NAME", Prim_canonical_host_name, 1, 1, 0) }); } +DEFINE_PRIMITIVE ("GET-HOST-BY-ADDRESS", Prim_get_host_by_address, 1, 1, 0) +{ + PRIMITIVE_HEADER (1); + SOCKET_CODE + ({ + CONST char * host_name = (OS_get_host_by_address (STRING_ARG (1))); + if (host_name == 0) + PRIMITIVE_RETURN (SHARP_F); + { + SCHEME_OBJECT result + = (char_pointer_to_string ((unsigned char *) host_name)); + OS_free ((PTR) host_name); + PRIMITIVE_RETURN (result); + } + }); +} + #ifdef HAVE_SOCKETS static char * diff --git a/v7/src/microcode/uxsock.c b/v7/src/microcode/uxsock.c index 1aae5f5bb..9727bf01f 100644 --- a/v7/src/microcode/uxsock.c +++ b/v7/src/microcode/uxsock.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: uxsock.c,v 1.18 1999/01/02 06:11:34 cph Exp $ +$Id: uxsock.c,v 1.19 1999/08/13 18:29:28 cph Exp $ Copyright (c) 1990-1999 Massachusetts Institute of Technology @@ -35,10 +35,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "prims.h" #include "limits.h" -#ifndef _SUNOS4 +#ifdef 0 extern struct servent * EXFUN (getservbyname, (CONST char *, CONST char *)); -#endif extern struct hostent * EXFUN (gethostbyname, (CONST char *)); +#endif Tchannel DEFUN (OS_open_tcp_stream_socket, (host, port), char * host AND int port) @@ -143,6 +143,19 @@ DEFUN (OS_canonical_host_name, (host_name), CONST char * host_name) } } +CONST char * +DEFUN (OS_get_host_by_address, (host_addr), CONST char * host_addr) +{ + struct hostent * entry = (UX_gethostbyaddr (host_addr, AF_INET)); + if (entry == 0) + return (0); + { + char * result = (OS_malloc ((strlen (entry -> h_name)) + 1)); + strcpy (result, (entry -> h_name)); + return (result); + } +} + Tchannel DEFUN (OS_open_unix_stream_socket, (filename), CONST char * filename) { diff --git a/v7/src/microcode/uxsock.h b/v7/src/microcode/uxsock.h index 9631fa949..1b4f32065 100644 --- a/v7/src/microcode/uxsock.h +++ b/v7/src/microcode/uxsock.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: uxsock.h,v 1.8 1999/01/02 06:11:34 cph Exp $ +$Id: uxsock.h,v 1.9 1999/08/13 18:29:18 cph Exp $ Copyright (c) 1990-1999 Massachusetts Institute of Technology @@ -31,6 +31,7 @@ extern unsigned int EXFUN (OS_host_address_length, (void)); extern char ** EXFUN (OS_get_host_by_name, (CONST char *)); CONST char * EXFUN (OS_get_host_name, (void)); CONST char * EXFUN (OS_canonical_host_name, (CONST char *)); +CONST char * EXFUN (OS_get_host_by_address, (CONST char *)); #ifdef HAVE_UNIX_SOCKETS extern Tchannel EXFUN (OS_open_unix_stream_socket, (CONST char *)); -- 2.25.1