From dfb3292cc027bddba1309ff653f322e2e4da62ca Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Mon, 31 Aug 1998 04:00:26 +0000 Subject: [PATCH] Implement primitive to map socket port numbers from host to network order. --- v7/src/microcode/ntsock.c | 8 +++++++- v7/src/microcode/os2sock.c | 8 ++++---- v7/src/microcode/pruxsock.c | 15 +++++++++++++-- v7/src/microcode/uxsock.c | 11 +++++++++-- v7/src/microcode/uxsock.h | 21 +++++++++------------ 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/v7/src/microcode/ntsock.c b/v7/src/microcode/ntsock.c index 5287c2c14..1189d7915 100644 --- a/v7/src/microcode/ntsock.c +++ b/v7/src/microcode/ntsock.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntsock.c,v 1.3 1998/04/14 05:13:37 cph Exp $ +$Id: ntsock.c,v 1.4 1998/08/31 04:00:08 cph Exp $ Copyright (c) 1997-98 Massachusetts Institute of Technology @@ -116,6 +116,12 @@ OS_get_service_by_name (const char * service_name, const char * protocol_name) return ((entry == 0) ? (-1) : (entry -> s_port)); } +unsigned long +OS_get_service_by_number (const unsigned long port_number) +{ + return ((unsigned long) (htons ((unsigned short) port_number))); +} + unsigned int OS_host_address_length (void) { diff --git a/v7/src/microcode/os2sock.c b/v7/src/microcode/os2sock.c index a133884e6..e947a4eb7 100644 --- a/v7/src/microcode/os2sock.c +++ b/v7/src/microcode/os2sock.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: os2sock.c,v 1.7 1998/08/31 03:57:49 cph Exp $ +$Id: os2sock.c,v 1.8 1998/08/31 04:00:04 cph Exp $ Copyright (c) 1990-98 Massachusetts Institute of Technology @@ -137,10 +137,10 @@ OS_get_service_by_name (const char * service_name, const char * protocol_name) return ((entry == 0) ? (-1) : (entry -> s_port)); } -unsigned short -OS_get_service_by_number (const unsigned short port_number) +unsigned long +OS_get_service_by_number (const unsigned long port_number) { - return (htons (port_number)); + return ((unsigned long) (htons ((unsigned short) port_number))); } unsigned int diff --git a/v7/src/microcode/pruxsock.c b/v7/src/microcode/pruxsock.c index 6d772ca24..ae98fac55 100644 --- a/v7/src/microcode/pruxsock.c +++ b/v7/src/microcode/pruxsock.c @@ -1,8 +1,8 @@ /* -*-C-*- -$Id: pruxsock.c,v 1.14 1997/11/01 07:27:36 cph Exp $ +$Id: pruxsock.c,v 1.15 1998/08/31 04:00:22 cph Exp $ -Copyright (c) 1990-97 Massachusetts Institute of Technology +Copyright (c) 1990-98 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -86,6 +86,17 @@ The result is a nonnegative integer, or #F if no such service exists.") }); } +DEFINE_PRIMITIVE ("GET-SERVICE-BY-NUMBER", Prim_get_service_by_number, 1, 1, + "Given PORT-NUMBER, return it in the network encoding.") +{ + PRIMITIVE_HEADER (1); + SOCKET_CODE + ({ + PRIMITIVE_RETURN + (ulong_to_integer (OS_get_service_by_number (arg_ulong_integer (1)))); + }); +} + DEFINE_PRIMITIVE ("HOST-ADDRESS-LENGTH", Prim_host_address_length, 0, 0, "The length of a host address string, in characters.") { diff --git a/v7/src/microcode/uxsock.c b/v7/src/microcode/uxsock.c index 34f8ef7f7..cbf624523 100644 --- a/v7/src/microcode/uxsock.c +++ b/v7/src/microcode/uxsock.c @@ -1,8 +1,8 @@ /* -*-C-*- -$Id: uxsock.c,v 1.16 1997/11/01 07:26:30 cph Exp $ +$Id: uxsock.c,v 1.17 1998/08/31 04:00:13 cph Exp $ -Copyright (c) 1990-97 Massachusetts Institute of Technology +Copyright (c) 1990-98 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -97,6 +97,13 @@ DEFUN (OS_get_service_by_name, (service_name, protocol_name), return ((entry == 0) ? (-1) : (entry -> s_port)); } +unsigned long +DEFUN (OS_get_service_by_number, (port_number), + CONST unsigned long port_number) +{ + return ((unsigned long) (htons ((unsigned short) port_number))); +} + unsigned int DEFUN_VOID (OS_host_address_length) { diff --git a/v7/src/microcode/uxsock.h b/v7/src/microcode/uxsock.h index 451f3f54f..735123578 100644 --- a/v7/src/microcode/uxsock.h +++ b/v7/src/microcode/uxsock.h @@ -1,8 +1,8 @@ /* -*-C-*- -$Id: uxsock.h,v 1.6 1997/11/01 07:19:26 cph Exp $ +$Id: uxsock.h,v 1.7 1998/08/31 04:00:26 cph Exp $ -Copyright (c) 1990-97 Massachusetts Institute of Technology +Copyright (c) 1990-98 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -37,22 +37,19 @@ MIT in each case. */ #include "osio.h" -extern Tchannel EXFUN (OS_open_tcp_stream_socket, (char * host, int port)); -extern int EXFUN - (OS_get_service_by_name, - (CONST char * service_name, CONST char * protocol_name)); +extern Tchannel EXFUN (OS_open_tcp_stream_socket, (char *, int)); +extern int EXFUN (OS_get_service_by_name, (CONST char *, CONST char *)); +extern unsigned long EXFUN (OS_get_service_by_number, (CONST unsigned long)); extern unsigned int EXFUN (OS_host_address_length, (void)); -extern char ** EXFUN (OS_get_host_by_name, (CONST char * host_name)); +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 *)); #ifdef HAVE_UNIX_SOCKETS -extern Tchannel EXFUN (OS_open_unix_stream_socket, (CONST char * filename)); +extern Tchannel EXFUN (OS_open_unix_stream_socket, (CONST char *)); #endif -extern Tchannel EXFUN (OS_open_server_socket, (unsigned int port, int ArgNo)); -extern Tchannel EXFUN - (OS_server_connection_accept, - (Tchannel channel, char * peer_host, int * peer_port)); +extern Tchannel EXFUN (OS_open_server_socket, (unsigned int, int)); +extern Tchannel EXFUN (OS_server_connection_accept, (Tchannel, char *, int *)); #endif /* SCM_UXSOCK_H */ -- 2.25.1