Using TCP/IP Services
This section describes how to use the Open Transport RawIP interface, how to implement IP multicasting, and how to use a variety of Open Transport endpoint and mapper functions with the TCP/IP protocols. TCP/IP options are described in "Options," beginning on page 8-28.Using RawIP
The Open Transport TCP/IP software modules provide a RawIP interface to the IP protocol. The RawIP interface is provided to facilitate the implementation of new protocols that use IP for datagram delivery. Therefore, in order to use a RawIP endpoint, you must specify a value for the Protocol field in the IP datgram header. By default, RawIP fills in the Protocol field with a 1, indicating the packet carries an ICMP message. You can specify a different protocol type for a RawIP endpoint by using the optionXTI_PROTOTYPE, described in the chapter "Option Management" in this book. The option value consists of a longword containing the number of the protocol to be used by the RawIP endpoint.All RawIP endpoints using a specific protocol receive a copy of any inbound packets destined for that protocol. Thus, if several programs were using ICMP on the same host, they would all receive a copy of every inbound ICMP datagram.
The data delivered to a RawIP endpoint includes the full IP header, which is
20 bytes long if it includes no options.
- WARNING
- If you open a RawIP endpoint, you are responsible for implementing the protocol that is a client of IP running over that endpoint. Because an improperly implemented protocol can cause the host to crash or cause the loss of data on the network, you should not attempt to use RawIP unless you are an expert network programmer.
![]()
Using IP Multicasting
Open Transport TCP/IP provides IP multicasting level 2, as described in RFC 1112. To join a multicast group, use theIP_ADD_MEMBERSHIPoption (page 8-35), passing in aTIPAddMulticaststructure to specify the address and network interface of the group you wish to join. For a multihomed system, you can use the valuekOTAnyInetAddressfor the interface address to use the default multicast interface.The time-to-live value for outbound multicast data defaults to 1; you can use the
IP_MULTICAST_TTLoption to set a different value. The time-to-live value is a hop count: Each router that processes the datagram decrements the Time to Live field and discards the datagram if the value reaches 0. Because every router that receives a multicast packet forwards it, a high time-to-live value for a multicast packet can cause the packet to propagate widely through the internet. Therefore, keep this value as low as possible.By default, Open Transport IP loops back multicast datagrams to any
member of the group on the sending machine. Pass a value ofT_NOto
theIP_MULTICAST_LOOPoption to turn off loopbacks.Using the Hosts File
The Open Transport DNR supports use of a Hosts file, which is located in the Preferences folder in the System Folder. The DNR parses the Hosts file when TCP/IP is loaded and uses it to initialize its list of host addresses, aliases, and name servers.
The Hosts file can include lines of data, blank lines, and comments. A comment begins with a semicolon (;) and can be on the same line as data. The comment extends from the semicolon to the end of the line.
- Note
- Because the DNR downloads the information in the Hosts file and keeps it in RAM, a large Hosts files waste memory and degrades the performance of the DNR. Therefore, you should avoid using a Hosts file, or if you must use one, keep the Hosts file as small as possible.
![]()
A data line in the Hosts file has either of the following two formats (the square brackets indicate an optional element):
domain-name [time-to-live
IN] type rdatadomain-name [
INtime-to-live] type rdataThe elements are defined as follows:
- domain-name
- An absolute or fully qualified domain name unless the data type is
CNAME, in which case the name can be an alias. It need not be terminated by a period (.), but must contain at least one period internally.- time-to-live
- The record's configured lifetime, in seconds. If this field is not present, the DNR assumes the entry has an infinite lifetime. You can also specify -1 for the time to live to indicate an infinite lifetime.
IN- The data class; always
INindicating the internet domain.- type
- The type of data. This field can be
Afor a host address,CNAMEfor the canonical name of an alias, orNSfor a
name server. Other DNS types are not supported in the Hosts file.- rdata
- The data. For the
Adata type, this field must be an address in dotted-decimal format. For theCNAMEandNSdata types, this field must be a fully qualified domain name.- Here are some sample data lines:
apple.com A 130.43.2.2 ;address of host apple.com rivers IN CNAME rivers.apple.com;canonical name of the host ; whose local alias is "rivers" mit.edu. 86400 NS achilles.mit.edu;name server for mit.edu ; domain. Entry has a 1-week ; lifetimeQuerying DNS Servers
In addition to the explicit simplified functions that are provided for the most commonly made queries such as name-to-address, address-to-name, system CPU and OS, and mail exchange queries, there is a generic query function, OTInetQuery, that you can use for any DNS query.The OTInetQuery function allows you to use the Domain Name Resolver (DNR) for generic domain name service (DNS) queries. You can ask for any query type and class, and in response, Open Transport returns as many
DNSQueryInfostructures as it can fit in the buffer you provide.There are three types of responses: answers, authority responses, or additional information, and there are typically several of each type. Each response has its own
DNSQueryInfostructure, with all the answers first, then all the authority records, then all the additional information. Authority responses refer you to DNS servers and other sources that may have helpful information for this answer and additional responses provide address data for the servers and sources referred to in the authority records.If, for example, you use the
OTInetQueryfunction to find out the IP addresses for a name, you might get back 13DNSQueryInfostructures in your answer buffer: With, say, 2 IP address structures, 4 authority responses, and 7 additional information responses.To help you parse this huge answer buffer, Open Transport provides two optional parameters for the
OTInetQueryfunction,argvandargvlen, that create an array pointing to the individual responses.Using General Open Transport Functions With TCP/IP
This section describes any special considerations that you must take into account for Open Transport functions when you use them with the Open Transport TCP/IP implementation. You should be familiar with the function descriptions in the chapters "Endpoints" and "Mappers" in this book before reading this section.Obtaining Endpoint Data With TCP/IP
The following values can be returned by theinfoparameter to theOTOpenEndpoint,OTAsyncOpenEndpoint, andOTGetEndpointInfofunctions when used with TCP/IP protocols:
Parameter TCP RawIP and UDP Meaning info->addr T_INVALID
Greater than 0T_INVALID
Greater than 0No access to transport protocol addresses is provided.
Maximum size of a protocol address.info->options T_INVALIDGreater than 0T_INVALIDGreater than 0No options.
Maximum number of bytes needed to hold protocol-
specific options.info->tsdu 0 T_INVALID
Greater than 0TSDUs not supported.
Transfer of normal data not supported.
Maximum size of a TSDU.info->etsdu T_INFINITET_INVALIDNo limit on the size of an ETSDU.
Transfer of expedited data not supported.info->connect T_INVALIDT_INVALIDData cannot be sent with functions that establish connections. info->discon T_INVALIDT_INVALIDData cannot be sent with abortive disconnects. info->servtype T_COTS
T_COTS_ORD
T_CLTSConnection mode supported; orderly disconnects not supported.
Connection mode and orderly disconnects supported.
Connectionless mode supported.info->flags T_SENDZEROT_SENDZEROZero-length TSDUs supported.
These fields and the significance of their values are described in more detail in the document X/Open CAE Specification: X/Open Transport Interface (XTI).
- IMPORTANT
- The preceding table shows only what values are possible for each protocol. Be sure to to use the
OTOpenEndpoint,OTAsyncOpenEndpoint, orOTGetEndpointInfofunction to obtain the current values for these parameters.![]()
Using Endpoint Functions With TCP/IP
This section describes protocol-specific information about functions described in the chapter "Endpoints" in this book. The functions are listed in the same order that they appear in that chapter.OTBind
TheOTBindfunction associates a local protocol address with the endpoint you specify. You must use this function for every protocol.The
addrfield of theTBindstructure refers to the local endpoint and so must specifically include a port number. Use anInetAddressstructure (described in "Internet Address Structure" on page 8-22) to specify this address.Because the architecture of Open Transport TCP/IP provides for multihoming (although this feature has not yet been implemented), you can specify an IP address of
kOTAnyInetAddressto indicate that your application or process will accept packets from any TCP/IP interface that the user has configured in the TCP/IP control panel.If you specify an address of 0 to the
OTBindfunction, then theOTGetProtAddressfunction always returns an IP address of 0. In that case, you must use theOTInetGetInterfaceInfofunction (page 8-50) to determine the IP address of a running IP interface. However, if you pass in a valid address with a port number of 0, the TCP/IP service provider assigns a port for you and theOTGetProtAddressfunction returns the assigned port number.You can use the
OTInetGetInterfaceInfofunction (page 8-50) to get the IP addresses of all currently configured IP interfaces. Then, if you wish to receive packets from only a single interface, you can bind the endpoint to the address for that interface.OTLook
TheOTLookfunction checks for asynchronous events such as incoming data or connecton requests. You can use this function with any protocol.As soon as a segment with the TCP urgent pointer set (that is, expedited data) enters the TCP receive buffer, TCP posts the
T_EXDATAevent. TheT_EXDATAevent remains posted until you have retrieved all data up to the byte pointed to by the TCP urgent pointer.OTGetProtAddress
If you bind an endpoint to an IP address of 0 in order to accept packets from any valid TCP/IP interface, then theOTGetProtAddressfunction always returns an IP address of 0. This is because in a multihomed machine, there is a separate IP address for each interface, and there's no way for open transport to know which one you want. in that case, you must use theOTInetGetInterfaceInfofunction (page 8-50) to determine the IP address of a running IP interface.
On the other hand, if you bind an endpoint to a specific interface, theOTGetProtAddressfunction returns the address of that interface, as expected.OTConnect
TheOTConnectfunction requests a connection to a specified remote endpoint. You can use this function with TCP but not with UDP or IP.The
rcvcall->addrfield returns the sameTNetbufstructure you specify in thesndcall->addrfield.Because TCP does not allow you to send any application-specific data during the connection establishment phase, you must set the
sndcall->udata.lenfield to 0. TCP ignores any data in thesndcall->udata.buffield.Note that TCP, not the receiving application, confirms the connection.
OTRcvConnect
TheOTRcvConnectfunction reads the status of a previously issued connection request. You can use this function with TCP, but not with UDP or IP.Because TCP does not allow you to send any application-specific data during the connection establishment phase, you must set the
call->udata.maxlenfield to 0. TCP ignores any data in thecall->udata.buffield.On return, the
call->addrfield points to the fully qualified internet address of the endpoint that accepted the connection.OTListen
TheOTListenfunction listens for an incoming connection request. You can use this function with TCP, but not with UDP or IP.When the
OTListenfunction successfully completes execution (that is, when you receive theT_LISTENevent), thecallparameter describes a connection
that has already been completed at the TCP level. You use theOTAcceptfunction to complete a connection at the application level. If you wish to reject a connection, you must call theOTSndDisconnectfunction after theOTListenfunction successfully completes execution.Because TCP does not allow you to send any application-specific data during the connection establishment phase, you must set the
call->udata.lenfield to 0. TCP ignores any data in thecall->udata.buffield.OTAccept
TheOTAcceptfunction accepts an incoming connection request. You can use this function with TCP, but not with UDP or IP.Because TCP does not allow you to send any application-specific data during the connection establishment phase, you must set the
call->udata.lenfield to 0. TCP ignores any data in thecall->udata.buffield.If you wish to send either of the association-related options (
IP_OPTIONSorIP_TOS) with the connection confirmation, you must use theOTOptionManagementfunction to set the values of these options before you receive theT_LISTENevent. TCP has already established a connection when you receive theT_LISTENevent, and it is too late for theOTAcceptfunction to negotiate these options.OTSndUData
TheOTSndUDatafunction sends data through a connectionless transactionless endpoint. You can use this function with UDP and IP, but not with TCP.The current value for the maximum size of a RawIP or UDP datagram is returned in the
info->tsduparameter of theOTOpenEndpoint,OTAsyncOpenEndpoint, andOTGetEndpointInfofunctions.OTSnd
TheOTSndfunction sends data through a connection-oriented transactionless endpoint. You can use this function with TCP, but not with UDP or IP.TCP ignores the
OTSndfunction'sT_MOREflag.If you set the
T_EXPEDITEDflag, you must send at least 1 byte of data. If you call theOTSndfunction with more than 1 byte specified and theT_EXPEDITEDflag set, the TCP urgent pointer points to the last byte of the buffer.OTRcv
TheOTRcvfunction receives data through a connection-oriented endpoint. You can use this function with TCP, but not with UDP or IP.Because TCP ignores the
T_MOREflag when it is sending data and does not transmit the flag, you should ignore theT_MOREflag when receiving normal data. However, if a byte in the data stream is pointed to by the TCP urgent pointer, TCP receives this byte and as many bytes as possible preceding the marked byte with theT_EXPEDITEDflag set. If your buffer is too small to receive all of the expedited data, TCP sets theT_MOREflag as well. Note that this situation might result in the number of bytes received as expedited data not being equal to the number of bytes sent by the originator as expedited data.OTSndDisconnect
TheOTSndDisconnectfunction initiates an abortive disconnect or rejects a connection request. You can use this function with TCP, but not with UDP or IP.Because TCP does not allow you to send any application-specific data during a disconnect, you must set the
call->udata.lenfield to 0. TCP ignores any data in thecall->udata.buffield.OTRcvDisconnect
TheOTRcvDisconnectfunction returns information about why a connection attempt failed or an established connection was terminated. You can use this function with TCP, but not with UDP or IP.Because TCP does not allow you to send any application-specific data during a disconnection, you must set the
discon->udata.lenfield to 0. TCP ignores any data in thediscon->udata.buffield.Using Mapper Functions With TCP/IP
This section describes protocol-specific information about functions described in the chapter "Mappers" in this book. The functions are listed in the same order that they appear in that chapter.OTRegisterName
Because the TCP/IP domain name system does not include a method for clients to register their names on the network, the Open Transport domain name resolver (DNR) does not support theOTRegisterNamefunction. If you
call this function for a TCP/IP mapper, it will return thekOTNotSupportedErrresult code.OTDeleteName
This function is not supported by the TCP/IP domain name resolver (DNR).
If you call this function for a TCP/IP mapper, it will return thekOTNotSupportedErrresult code.OTLookupName
You can use theOTLookupNamefunction to resolve a domain name to an internet address. Specify the name as a character string pointed to by therequest->udata.bufparameter. The name can be just a host name (otteam), a partially qualified domain name ("otteam.ssw"), a fully qualified domain name ("otteam.ssw.apple.com."), or an internet address in dotted-decimal format ("17.202.99.99"), and can optionally include the port number ("otteam.ssw.apple.com:25" or "17.202.99.99:25").The function returns a pointer to the address in the
reply->udata.bufparameter. The address is in the format of anInetAddressstructure (page 8-22), which includes the address type, the port number, and the IP address in hexadecimal format. If you don't specify a port number, the returnedInetAddressstructure contains a port number of 0. You can use this address directly in all Open Transport functions that require an internet address, such asOTConnect,OTSndUData, andOTBind.The
OTLookupNamefunction returns only a single address, regardless of how many addresses are known for a single multihomed host. To obtain a list of up to 10 addresses for a multihomed host, use theOTStringToAddressfunction (page 8-40).
Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help