2004-03-29 03:37:46 +00:00
|
|
|
/* Include for communications with GNUstep Distributed Objects name server.
|
1997-09-01 21:59:51 +00:00
|
|
|
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
1997-05-03 19:18:21 +00:00
|
|
|
|
|
|
|
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
Created: October 1996
|
|
|
|
|
2008-06-08 10:38:33 +00:00
|
|
|
This file is part of the GNUstep Project.
|
1997-05-03 19:18:21 +00:00
|
|
|
|
2008-06-08 10:38:33 +00:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
1997-05-03 19:18:21 +00:00
|
|
|
|
2008-06-08 10:38:33 +00:00
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with this program; see the file COPYING.
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1997-05-03 19:18:21 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* About the GNU Distributed Objects name-server
|
|
|
|
*
|
|
|
|
* The name server is intended to work with both the UDP and the TCP
|
|
|
|
* protocols. It is intended that the TCP interface be used by
|
|
|
|
* GNUstep programs, while the UDP interface is intended primarily
|
|
|
|
* for communication between name servers on different machines.
|
|
|
|
*
|
|
|
|
* The communications protocol is identical for both TCP and UDP and
|
|
|
|
* consists of a simple request-response sequence.
|
|
|
|
*
|
1997-10-28 14:34:49 +00:00
|
|
|
* Each request is a single message consisting of -
|
1997-05-03 19:18:21 +00:00
|
|
|
* a single byte request type,
|
|
|
|
* a single byte giving name length,
|
1997-09-01 21:59:51 +00:00
|
|
|
* a single byte specifying the type of port being registered
|
|
|
|
* or looked up, or a nul byte for probe operations.
|
|
|
|
* a single nul byte.
|
|
|
|
* a four byte port number in network byte order must be
|
1997-05-03 19:18:21 +00:00
|
|
|
* present for register operations, otherwise this is zero.
|
1998-02-26 17:55:42 +00:00
|
|
|
* a service name of 0 to GDO_NAME_MAX_LEN bytes (or two IP
|
|
|
|
* addresses in network byte order and an optional list of
|
|
|
|
* additional addresseso for probe operations)
|
1997-10-28 14:34:49 +00:00
|
|
|
* 0 to GDO_NAME_MAX_LEN nul bytes padding the service name to its
|
|
|
|
* full size.
|
1997-09-01 21:59:51 +00:00
|
|
|
* a terminating nul byte.
|
1997-10-28 14:34:49 +00:00
|
|
|
* The total is always sent in a packet with everything after the
|
|
|
|
* service name (except the final byte) cleared to nul bytes.
|
1997-05-03 19:18:21 +00:00
|
|
|
*
|
1997-09-01 21:59:51 +00:00
|
|
|
* Each response consists of at least 4 bytes and depends on the
|
1997-05-03 19:18:21 +00:00
|
|
|
* corresponding request type and where it came from as follows -
|
|
|
|
*
|
|
|
|
* Request type Effect
|
|
|
|
*
|
|
|
|
* GDO_LOOKUP Looks up the server name and returns its port number.
|
|
|
|
* Response is the port number in network byte order,
|
|
|
|
* or zero if the named server was not registered.
|
|
|
|
*
|
1997-09-01 21:59:51 +00:00
|
|
|
* GDO_REGISTER Registers the given server name with a port number.
|
1997-05-03 19:18:21 +00:00
|
|
|
* This service is only available to processes on the
|
|
|
|
* same host as the name server.
|
|
|
|
* Response is the port number in network byte order,
|
1997-09-01 21:59:51 +00:00
|
|
|
* or zero if the named server was already registered.
|
1997-05-03 19:18:21 +00:00
|
|
|
*
|
|
|
|
* GDO_UNREG Un-register the server name and return old port number.
|
1998-11-02 11:48:42 +00:00
|
|
|
* If the server name is of length zero, and the port is
|
|
|
|
* non-zero then all names for the port are unregistered.
|
1997-05-03 19:18:21 +00:00
|
|
|
* This service is only available to a process on the
|
1997-10-28 14:34:49 +00:00
|
|
|
* same host as this name server.
|
1997-05-03 19:18:21 +00:00
|
|
|
* Response is the old port number in network byte order,
|
|
|
|
* or zero if the name could not be un-registered.
|
1998-11-02 11:48:42 +00:00
|
|
|
* If multiple names were unregistered the response is
|
|
|
|
* the port for those names.
|
1997-05-03 19:18:21 +00:00
|
|
|
*
|
|
|
|
* GDO_SERVERS Return a list of the known servers on the local net.
|
1997-09-01 21:59:51 +00:00
|
|
|
* Response is an unsigned long (in network byte order)
|
1997-05-03 19:18:21 +00:00
|
|
|
* saying how many servers the name server knows about,
|
|
|
|
* followed by a list of their IP addresses in network
|
|
|
|
* byte order.
|
|
|
|
* NB. This response may not be possible over UDP as the
|
|
|
|
* response length may exceed the maximum UDP packet size.
|
|
|
|
*
|
2000-07-18 15:50:36 +00:00
|
|
|
* GDO_NAMES Return a list of registered names known to the server.
|
|
|
|
* Response is an unsigned long (in network byte order)
|
|
|
|
* saying how many bytes of data are to follow,
|
2005-11-06 13:53:40 +00:00
|
|
|
* followed by a list of the names each preceded by the
|
2000-07-18 15:50:36 +00:00
|
|
|
* name length (a single byte) and port type (a byte).
|
|
|
|
* NB. This response may not be possible over UDP as the
|
|
|
|
* response length may exceed the maximum UDP packet size.
|
|
|
|
*
|
1997-05-03 19:18:21 +00:00
|
|
|
* The following are used for communications between name servers -
|
|
|
|
*
|
|
|
|
* GDO_PROBE Requests a response
|
1998-02-26 17:55:42 +00:00
|
|
|
* Passes two IP addresses in the name field - first the
|
|
|
|
* address of the sender, next that of the recipient.
|
|
|
|
* The packet may (optionally) include a variable number
|
|
|
|
* of addresses (as specified by the name length minus the
|
|
|
|
* size of the two addresses), each of which is an internet
|
|
|
|
* address on which the sender is also listening.
|
1997-05-03 19:18:21 +00:00
|
|
|
* For a request from a name server via UDP there is no
|
|
|
|
* response, but a GDO_REPLY request is sent.
|
|
|
|
* For a request from a non-name-server, or a TCP
|
|
|
|
* connect, the response is the port number of this
|
|
|
|
* server in network byte order.
|
|
|
|
*
|
|
|
|
* GDO_PREPLY Replies to a GDO_PROBE via UDP from a name server.
|
1998-02-26 17:55:42 +00:00
|
|
|
* The format of the message is as for GDO_PROBE.
|
1997-05-03 19:18:21 +00:00
|
|
|
* No response is sent.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* HOW IT WORKS AND WHY (implementation notes)
|
|
|
|
*
|
|
|
|
* 1. The fixed size of a request packet was chosen for maximum
|
|
|
|
* ease and speed of implementation of a non-blocking name server.
|
|
|
|
* The server knows how much it needs to read and can therefore
|
|
|
|
* usually do a read as a single operation since it doesn't have
|
|
|
|
* to read a little, figure out request length, allocate a buffer,
|
|
|
|
* and read the rest.
|
|
|
|
*
|
|
|
|
* The server name length (bytes) is specified - no assumptions
|
|
|
|
* should be made about whether the name contains nul characters
|
|
|
|
* or indeed about the name at all. This is future-proofing.
|
|
|
|
*
|
|
|
|
* 2. Why UDP as well as TCP?
|
|
|
|
* The OpenStep specification says that a connection may be
|
|
|
|
* established to any host on the local network which supplys a
|
|
|
|
* named service if the host name is specified as '*'
|
|
|
|
*
|
|
|
|
* This means that the application must poll to see if it can
|
|
|
|
* find a server with the name it wants. The polling could take
|
|
|
|
* a huge amount of time!
|
|
|
|
*
|
|
|
|
* To make this all easier - the server is capable of supplying
|
|
|
|
* a list of those hosts on the local network which it knows to
|
|
|
|
* have (or have had) a name server running on them.
|
|
|
|
*
|
|
|
|
* The application then need only poll those name servers to find
|
|
|
|
* the service it wants.
|
|
|
|
*
|
|
|
|
* However - to give the application a list of hosts, the name
|
|
|
|
* server must have got the information from somewhere.
|
|
|
|
* To gather the information the server has to poll the machines
|
|
|
|
* on the net which would take ages using TCP since attempts to
|
|
|
|
* talk to machines which are down or do not exist will take a
|
|
|
|
* while to time out.
|
|
|
|
*
|
|
|
|
* To make things speedy, the server sends out GDO_PROBE requests
|
|
|
|
* on UDP to all the machines on the net when it starts up.
|
|
|
|
* Each machine which has a name server notes that the new name
|
|
|
|
* server has started up and sends back a GDOPREPLY packet so
|
|
|
|
* that the new name server will know about it.
|
|
|
|
*
|
|
|
|
* Things are never perfect though - if a name server dies, the
|
|
|
|
* other name servers won't know, and will continute to tell
|
|
|
|
* applications that it is there.
|
1997-10-28 14:34:49 +00:00
|
|
|
*
|
|
|
|
* 3. Port type codes - these are used to say what the port is for so
|
|
|
|
* that clients can look up only the names that are relevant to them.
|
|
|
|
* This is to permit the name server to be used for multiple
|
|
|
|
* communications protocols (at the moment, tcp or udp) and for
|
|
|
|
* different systems (distributed objects or others).
|
|
|
|
* This guarantees that if one app is using DO over UDP, its services
|
|
|
|
* will not be found by an app which is using DO over TCP.
|
1997-05-03 19:18:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define GDOMAP_PORT (538) /* The well-known port for name server. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Request type codes
|
|
|
|
*/
|
|
|
|
#define GDO_REGISTER 'R'
|
|
|
|
#define GDO_LOOKUP 'L'
|
|
|
|
#define GDO_UNREG 'U'
|
|
|
|
#define GDO_SERVERS 'S'
|
|
|
|
#define GDO_PROBE 'P'
|
|
|
|
#define GDO_PREPLY 'p'
|
2000-07-18 15:50:36 +00:00
|
|
|
#define GDO_NAMES 'N'
|
1997-05-03 19:18:21 +00:00
|
|
|
|
|
|
|
/*
|
1997-09-01 21:59:51 +00:00
|
|
|
* Port type codes
|
1997-05-03 19:18:21 +00:00
|
|
|
*/
|
1997-10-28 14:34:49 +00:00
|
|
|
#define GDO_NET_MASK 0x70 /* Network protocol of port. */
|
|
|
|
#define GDO_NET_TCP 0x10
|
2007-11-30 18:03:28 +00:00
|
|
|
#define GDO_NET_UDP 0x20
|
1997-10-28 14:34:49 +00:00
|
|
|
#define GDO_SVC_MASK 0x0f /* High level protocol of port. */
|
|
|
|
#define GDO_SVC_GDO 0x01
|
|
|
|
#define GDO_SVC_FOREIGN 0x02
|
|
|
|
|
|
|
|
/* tcp/ip distributed object server. */
|
|
|
|
#define GDO_TCP_GDO (GDO_NET_TCP|GDO_SVC_GDO)
|
|
|
|
|
|
|
|
/* udp/ip distributed object server. */
|
|
|
|
#define GDO_UDP_GDO (GDO_NET_UDP|GDO_SVC_GDO)
|
|
|
|
|
|
|
|
/* tcp/ip simple socket connection. */
|
|
|
|
#define GDO_TCP_FOREIGN (GDO_NET_TCP|GDO_SVC_FOREIGN)
|
|
|
|
|
|
|
|
/* udp/ip simple socket connection. */
|
|
|
|
#define GDO_UDP_FOREIGN (GDO_NET_UDP|GDO_SVC_FOREIGN)
|
|
|
|
|
|
|
|
|
|
|
|
#define GDO_NAME_MAX_LEN 255 /* Max length registered name. */
|
1997-05-03 19:18:21 +00:00
|
|
|
|
|
|
|
/*
|
1997-09-01 21:59:51 +00:00
|
|
|
* Structure to hold a request.
|
1997-05-03 19:18:21 +00:00
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
typedef struct {
|
1997-10-28 14:34:49 +00:00
|
|
|
unsigned char rtype; /* Type of request being made. */
|
|
|
|
unsigned char nsize; /* Length of the name to use. */
|
|
|
|
unsigned char ptype; /* Type of port registered. */
|
1997-09-01 21:59:51 +00:00
|
|
|
unsigned char dummy;
|
|
|
|
unsigned int port;
|
2005-07-08 11:48:37 +00:00
|
|
|
unsigned char name[GDO_NAME_MAX_LEN+1];
|
1997-09-01 21:59:51 +00:00
|
|
|
} gdo_req;
|
|
|
|
|
1997-10-28 14:34:49 +00:00
|
|
|
#define GDO_REQ_SIZE sizeof(gdo_req) /* Size of a request packet. */
|
1997-05-03 19:18:21 +00:00
|
|
|
|
1998-03-10 19:01:24 +00:00
|
|
|
/*
|
1999-10-04 09:48:57 +00:00
|
|
|
* If you have a fascist sysadmin who will not let you run gdomap
|
1998-03-10 19:01:24 +00:00
|
|
|
* as root and will not even let you modify /etc/services to point
|
|
|
|
* gdomap to another port, you can uncomment the next #define to
|
|
|
|
* run gdomap on port 6006 (or modify this to a port of your choice).
|
2002-03-20 12:03:30 +00:00
|
|
|
* Whatever port you choose, you should make sure that no other
|
|
|
|
* processes running on your network use that number!
|
1998-03-10 19:01:24 +00:00
|
|
|
*
|
1998-11-27 20:39:08 +00:00
|
|
|
* When you have done this you must recompile gdomap.c and
|
|
|
|
* NSPortNameServer.m and re-install the base library with
|
|
|
|
* the new NSPortNameServer.o
|
2002-03-20 12:03:30 +00:00
|
|
|
*
|
|
|
|
* NB. Doing this will render your system unable to communicate with
|
|
|
|
* other systems which have not performed the same remapping. You
|
|
|
|
* should not do it unless you have no choice.
|
1998-03-10 19:01:24 +00:00
|
|
|
*/
|
2000-09-26 11:45:32 +00:00
|
|
|
/* #define GDOMAP_PORT_OVERRIDE 6006 */
|
1998-03-10 19:01:24 +00:00
|
|
|
|