Socket: 3 Addresses

Up: GEOS SDK TechDocs| Up | Down | Prev: 2 Simple Example | Next: 4 Making a Connection

In the example above, the application queried the user for a connection address. This is a fairly common case. However, some programs need to use hard-wired addresses. Perhaps you want to allow connections over all available domains. Thus, a few words about addresses may be in order.

Addresses are usually represented via the SocketAddress structure:

typedef struct {
	SocketPort 		SA_port;
	word 		SA_domainSize;
	char *		SA_domain;
	word 		SA_addressSize;
} SocketAddress;
/* domain-specific address data here */
SA_port
Port numbers identify a particular line of communication within a machine. Port numbers may be 32-bit or 16-bit, depending on the domain. They are specified via the SocketPort structure, made up of a 16-bit ManufacturerID and 16-bit arbitrarily-chosen token number. If the domain uses 16-bit socket numbers, then use MANUFACTURER_ID_SOCKET_16BIT_PORT as the ManufacturerID . If the domain allows 32-bit socket numbers, then you may use MANUFACTURER_ID_SOCKET_16BIT_PORT or some other ManufacturerID , probably your own ID or that of some standard service provider. This numbering scheme helps to avoid overlapping port numbers.
SA_domain , SA_domainSize
The domain identifies the protocol of the network by which the addressed machine may be reached. The domain is specified by a string. In a SocketAddress structure, SA_domain is a pointer to the null-terminated domain name string and SA_domainSize is the size of the buffer containing the domain name string.
Many communications protocols are hard-wired to work with a particular domain. To find out all domains available to the user's device, call SocketGetDomain(). (See Letting the User Choose an Address.)
SA_addressSize , Address Data
The format of the address data used to identify a machine within a domain depends on that domain. The SA_addressSize field of the SocketAddress structure contains the size of the address data. The buffer containing the address data should fall immediately after the SocketAddress structure. Read the documentation for a given domain to find out the format for its addresses.
You'll want to make sure that space for this data is, in fact, allocated at the end of the structure. If you declare a socket address, you will define a struct, probably based on SocketAddress , that has the fields of SocketAddress , but also has a buffer to hold the resolved address data. More likely than not, you won't need to declare or define such a structure -- you're more likely to use SocketCreateResolvedAddress() or bypass the creation of this structure altogether.

Before using an address, make sure that it is in its primitive form. For instance, an IP address like "geoworks.com" is not in its primitive form -- the IP address must be translated into a four-byte number before it can be used. Use SocketResolve() (described below) to transform an address into its primitive form. Note that the address passed to SocketResolve() is not in a SocketAddress structure.


Up: GEOS SDK TechDocs| Up | Down | Prev: 2 Simple Example | Next: 4 Making a Connection