United States |
Previous | Contents | Index |
Searches the protocols database until a matching protocol name is found or until EOF is encountered.
#include <netdb.h>struct protoent *getprotobyname (char *name);
name
A pointer to a string containing the desired protocol name.
This routine returns a pointer to a protoent structure containing the broken-out fields of the requested line from the protocols database.See the <netdb.h> header file for a description of the protoent structure.
See also getprotoent and getprotobynumber in this section.
NULL Indicates EOF or an error. x A pointer to a protoent structure.
Searches the protocols database until a matching protocol number is found or until an EOF is encountered.
#include <netdb.h>struct protoent *getprotobynumber (int *proto);
proto
A pointer to a string containing the desired protocol number.
This routine returns a pointer to a protoent structure containing the broken-out fields of the requested line from the protocols database.See the <netdb.h> header file for a description of the protoent structure.
See also getprotoent and getprotobyname in this section.
NULL Indicates EOF or an error. x A pointer to a protoent structure.
Gets a protocol database entry from the protocols database file.
#include <netdb.h>struct protoent *getprotoent (void);
The getprotoent routine reads the next entry of the database, opening a connection to the database, if necessary.See the <netdb.h> header file for a description of the protoent structure.
See also getprotobyname , getprotobynumber , setprotoent , and endprotoent in this section.
x A pointer to a protoent structure. NULL Indicates an error or EOF.
Gets information on the named service from the network services database.
#include <netdb.h>struct servent *getservbyname (char *name, char *proto);
name
A pointer to a string containing the name of the service about which information is required.proto
A pointer to a string containing the name of the protocol to search for.
This routine searches sequentially from the beginning of the file until a matching service name is found, or until an EOF is encountered. If a protocol name is also supplied (non-NULL), searches must also match the protocol.This routine returns a pointer to a servent structure containing the broken-out fields of the requested line in the network services database.
See the <netdb.h> header file for a description of the servent structure.
All information is contained in a static area, so it must be copied if it is to be saved.
See also getservbyport in this section.
NULL Indicates EOF or an error. x A pointer to a servent structure.
Gets information on the specified port from the network services database.
#include <netdb.h>struct servent *getservbyport (int port, char *proto);
port
The port number to search for.proto
A pointer to a string containing the name of the protocol to search for.
This routine searches sequentially from the beginning of the file until a matching port is found, or until an EOF is encountered. If a protocol name is also supplied (non-NULL), searches must also match the protocol.This routine returns a pointer to a servent structure containing the broken-out fields of the requested line in the network services database. See the <netdb.h> header file for a description of the servent structure.
All information is contained in a static area, so it must be copied if it is to be saved.
See also getservbyname in this section.
NULL Indicates EOF or an error. x A pointer to a servent structure.
Gets a services file entry from the network services database file.
#include <netdb.h>struct servent *getservent (void);
The getservent routine reads the next line of the network services database file, opening a connection to the database, if necessary.This routine returns a servent structure that contains fields for a line of information from the network services database file. See the <netdb.h> header file for a description of the hostent structure.
This routine uses a common static area for its return values, so subsequent calls to this routine overwrite any existing network entry. You must make a copy of the network services entry, if you wish to save it.
See also setservent , and endservent in this section.
x A pointer to a servent structure. NULL Indicates an error or EOF.
Returns the name associated with a socket.
#include <socket.h>Routine Variants This socket routine has a variant named __bsd44_getsockname . Enabled by defining _SOCKADDR_LEN , this variant implements 4.4BSD-compatible semantics. See Section A.7 for more information.int getsockname (int s, struct sockaddr *name, int *namelen);
(_DECC_V4_SOURCE) int getsockname (int s, struct sockaddr *name, size_t *namelen);
(NOT _DECC_V4_SOURCE)
s
A socket descriptor created with socket and bound to the socket name with bind .name
A pointer to the buffer in which getsockname should return the socket name.namelen
A pointer to an integer specifying the size of the buffer pointed to by name. On return, the integer contains the actual size of the name returned, in bytes.
This routine returns the current name for the specified socket descriptor. The name is a format specific to the address family (AF_INET) assigned to the socket.bind makes the association of the name to the socket, not getsockname .
See also bind and socket in this appendix.
0 Indicates success. --1 Indicates an error; errno is set to one of the following:
- EBADF -- The descriptor is invalid.
- ENOTSOCK -- The socket descriptor references a file, not a socket.
- ENOBUFS -- Resources were insufficient in the system to perform the operation.
- EFAULT -- The name parameter is not a valid part of the user address space.
Returns the options set on a socket.
#include <socket.h>int getsockopt (int s, int level, int optname, char *optval, int *optlen);
(_DECC_V4_SOURCE) int getsockopt (int s, int level, int optname, void *optval, size_t *optlen);
(NOT _DECC_V4_SOURCE)
s
A socket descriptor created by socket .level
The protocol level for which the socket options are desired. It may have one of the following values:
SOL_SOCKET Get the options at the socket level. p Any protocol number. Get the options for protocol level p. See the <in.h> file for the various IPPROTO values. optname
Is interpreted by the protocol that is specified in the level. Options at each protocol level are documented with the protocol. See setsockopt in this section for socket level options.optval
Points to a buffer in which the value of the specified option should be placed by getsockopt .optlen
Points to an integer containing the size of the buffer pointed to by optval. On return, the integer will be modified to contain the actual size of the option value returned.
This routine gets information on socket options. See the appropriate protocol for information on available options at each protocol level.
0 Indicates success. --1 Indicates an error; errno is set to one of the following:
- EBADF -- The descriptor is invalid.
- ENOTSOCK -- The socket descriptor references a file, not a socket.
- ENOPROTOOPT -- The option is unknown or the protocol is unsupported.
Writes a message to standard error explaining h_error .
#include <netdb.h>void herror (const char *string);
string
A user-printable string.
The herror routine maps the error number in the external variable h_errno to a locale-dependent error message.
Returns an error message string.
#include <string.h>char *hstrerror (int errnum);
errnum
An error number specifying a value of h_errno .
The hstrerror routine maps the error number specified by the errnum parameter to a locale-dependent error message string and returns a pointer to the string. The string pointed to by the return value cannot be modified by the program, but could be overwritten by subsequent calls to this routine.
x A pointer to the generated message string. --1 On error, errno might be set, but no return value is reserved to indicate an error.
If the hstrerror routine fails, errno is set to one of the following values:
- EINVAL -- The errnum parameter is an invalid error number.
Searches for host aliases associated with a name.
#include <resolv.h>char *hostalias (const char *name);
name
Points to the name of the host that you want to retrieve aliases from.
The hostalias routine searches for the alias associated with the name parameter. The HOSTALIASES environment variable defines the name of a file where you can find the host aliases, in the form:
host alias
x The host alias. NULL Indicates an error.
Converts longwords from host to network byte order.
#include <in.h>unsigned long int htonl (unsigned long int hostlong);
hostlong
A longword in host (VAX system) byte order. All integers on VAX systems are in host byte order unless otherwise specified.
This routine converts 32-bit unsigned integers from host byte order to network byte order.The network byte order is the format in which data bytes are supposed to be transmitted through a network. All hosts on a network must send data in network byte order. Not all hosts have an internal data representation format that is identical to the network byte order. The host byte order is the format in which bytes are ordered internally on a specific host.
The host byte order on VAX systems differs from the network order.
This routine is most often used with Internet addresses and ports as returned by gethostent and getservent , and when manipulating values in the structures. Network byte-order places the byte with the most significant bits at lower addresses; VAX systems place the most significant bits at the highest address.
x A longword in network byte order.
Converts short integers from host to network byte order.
#include <in.h>unsigned short int htons (unsigned short int hostshort);
hostshort
A short integer in host (VAX system) byte order. All short integers on VAX systems are in host byte order unless otherwise specified.
This routine converts 16-bit unsigned integers from host byte order to network byte order.The network byte order is the format in which data bytes are supposed to be transmitted through a network. All hosts on a network must send data in network byte order. Not all hosts have an internal data representation format that is identical to the network byte order. The host byte order is the format in which bytes are ordered internally on a specific host.
The host byte order on VAX systems differs from the network order.
This routine is most often used with Internet addresses and ports as returned by gethostent and getservent , and when manipulating values in the structures. Network byte order places the byte with the most significant bits at lower addresses; VAX systems place the most significant bits at the highest address.
x A short integer in network byte order. Integers in network byte order cannot be used for arithmetic computation on VAX systems.
Converts Internet addresses in text form into numeric (binary) Internet addresses.
#include <in.h>#include <inet.h>
int inet_addr (char *cp);
cp
A pointer to a null-terminated character string containing an Internet address in the standard Internet "." format.
This routine returns an Internet address in network byte order when given as its argument an ASCIZ (null-terminated) string representing the address in the Internet standard "." notation.Internet addresses specified using the "." notation take one of the following forms:
a.b.c.d a.b.c a.b aWhen four parts are specified, each is interpreted as a byte of data and assigned, from left to right, to the four bytes of an Internet address. Note that when an Internet address is viewed as a 32-bit integer quantity on VAX systems, the bytes previously referred to appear in binary as " d.c.b.a ". That is, VAX bytes are ordered from least significant to most significant.
When only one part is given, the value is stored directly in the network address without any byte rearrangement.
All numbers supplied as "parts" in a "." address expression may be decimal, octal, or hexadecimal, as specified in the C language (that is, a leading 0x or 0X implies hexadecimal; a leading 0 implies octal; otherwise, the number is interpreted as decimal).
--1 Indicates that cp does not point to a proper Internet address. x An Internet address in network byte order.
Returns the local network address portion of an Internet address.
#include <in.h>#include <inet.h>
int inet_lnaof (struct in_addr in);
in
An Internet address.
This routine returns the local network address (LNA) portion of a full Internet address.
x The LNA portion of an Internet address in host byte order.
Returns an Internet address given a network address and a local address on that network.
#include <in.h>#include <inet.h>
struct in_addr inet_makeaddr (int net, int lna);
net
An Internet network address in host byte order.lna
A local network address on network net in host byte order.
This routine combines the net and lna arguments into a single Internet address.
x An Internet address in network byte order.
Previous | Next | Contents | Index |
|