home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-03-15 | 3.7 KB | 95 lines | [TEXT/CWIE] |
- =head1 Internet sockets
-
- These are the real thing for real programmers. Out-of-band
- data only works for sending. Both stream (TCP) and datagram (UDP) sockets are
- supported. Internet sockets are also suited for interapplication communication
- on a single machine, provided it runs MacTCP.
-
- =head2 Differences to generic behavior
-
-
- Internet socket addresses have the following format:
-
- struct in_addr {
- u_long s_addr;
- };
-
- struct sockaddr_in {
- u_char sin_len; /* Ignored */
- u_char sin_family; /* Always C<AF_INET> */
- u_short sin_port; /* Port number */
- struct in_addr sin_addr; /* Host ID */
- char sin_zero[8];
- };
-
- =head2 Routines specific to TCP/IP sockets
-
- There are several routines to convert
- between numeric and symbolic addresses.
-
- Hosts are represented by the following structure:
-
- struct hostent {
- char *h_name; /* Official name of the host */
- char **h_aliases; /* A zero terminated array of alternate names for the host */
- int h_addrtype; /* Always AF_INET */
- int h_length; /* The length, in bytes, of the address */
- char **h_addr_list; /* A zero terminated array of network addresses for the host */
- };
-
- C<struct hostent * gethostbyname(char *name)> returns an entry for the host
- with the given C<name> or C<NULL> if a host with this name can't be found.
-
- C<struct hostent * gethostbyaddr(const char *addrP, int, int)> returns an
- entry for the host with the given address or C<NULL> if a host with this name
- can't be found. C<addrP> in fact has to be a C<struct in_addr *>. The last two
- parameters are ignored.
-
- C<char * inet_ntoa(struct in_addr inaddr)> converts an internet address into
- the usual numeric string representation (e.g., 0x8184023C is converted to
- "129.132.2.60")
-
- C<struct in_addr inet_addr(char *address)> converts a numeric string into an
- internet address (If C<x> is a valid address, C<inet_addr(inet_ntoa(x)) == x>).
-
- C<int gethostname(char *machname, long buflen)> gets our name into C<buffer>.
-
- Services are represented by the following data structure:
-
- struct servent {
- char *s_name; /* official service name */
- char **s_aliases; /* alias list */
- int s_port; /* port number */
- char *s_proto; /* protocol to use ("tcp" or "udp") */
- };
-
- C<void setservent(int stayopen)> rewinds the file of services. If C<stayopen> is
- set, the file will remain open until C<endservent()> is called, else it will be
- closed after the next call to C<getservbyname()> or C<getservbyport()>.
-
- C<void endservent()> closes the file of services.
-
- C<struct servent * getservent()> returns the next service from the file of services,
- opening the file first if necessary. If the file is not found (C</etc/services> in
- the preferences folder), a small built-in list is consulted. If there are no more services,
- C<getservent()> returns C<NULL>.
-
- C<struct servent * getservbyname (const char * name, const char * proto)> finds a named
- service by calling C<getservent()> until the protocol matches C<proto> and either the name or
- one of the aliases matches C<name>.
-
- C<struct servent * getservbyport (int port, const char * proto)> finds a
- service by calling C<getservent()> until the protocol matches C<proto> and the
- port matches C<port>.
-
- Protocols are represented by the following data structure:
-
- struct protoent {
- char *p_name; /* official protocol name */
- char **p_aliases; /* alias list (always NULL for GUSI)*/
- int p_proto; /* protocol number */
- };
-
- C<struct protoent * getprotobyname(char * name)> finds a named protocol. This
- call is rather unexciting.
-