United States |
Previous | Contents | Index |
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.
Returns the Internet network address portion of an Internet address.
#include <in.h>#include <inet.h>
int inet_netof (struct in_addr in);
in
An Internet address.
This routine returns the Internet network address (NET) portion of a full Internet address.
x The Internet network portion of an Internet address in host byte order.
Converts a text string representing an Internet network address in the standard Internet "." notation into an Internet network address as machine-format integer values.
#include <in.h>#include <inet.h>
int inet_network (char *cp);
cp
A pointer to an ASCIZ (null-terminated) character string containing a network address in the standard Internet "." format.
This routine returns an Internet network address as machine-format integer values when given as its argument an ASCIZ string representing the address in the Internet standard "." notation.
--1 Indicates that cp does not point to a proper Internet network address. x An Internet network address as machine-format integer values.
Converts an Internet address into a text string representing the address in the standard Internet "." notation.
#include <in.h>#include <inet.h>
char *inet_ntoa (struct in_addr in);
in
An Internet address in network byte order.
This routine converts an Internet address into an ASCIZ (null-terminated) string representing that address in the standard Internet "." notation.
Warning
Arguments should not be passed as integers because of how Compaq C handles struct arguments.Because the string is returned in a static buffer that will be overwritten by successive calls to inet_ntoa , it is recommended to copy the string to a safe place.
x A pointer to a string containing the Internet address in "." notation.
Controls socket operations only.
#include <ioctl.h>int ioctl (int d, unsigned long request, void *arg);
d
Specifies the file descriptor of the requested device.request
Specifies the ioctl command performed on the device.arg
Specifies parameters for this request. The type of arg is dependent on the specific ioctl request and device to which the ioctl is targeted.
The ioctl routine performs a variety of operations on sockets.An ioctl request has encoded in it, whether the parameter is an "in" parameter or "out" parameter, and the size of the arg parameter in bytes. The ioctl request is defined in the <ioctl.h> header file.
0 Indicates success. --1 Indicates an error; further specified in the global errno .
If the ioctl routine fails, errno is set to one of the following values:
- EBADF -- The d parameter is not a valid descriptor.
- ENOTTY -- The d parameter is not associated with a character special device, or the specified request does not apply to the kind of object that the d parameter references.
- EINVAL -- Either the request or the arg parameter is not valid.
Sets the maximum limit of outstanding connection requests for a socket that is connection-oriented.
int listen (int s, int backlog);
s
A socket descriptor of type SOCK_STREAM that has been created using socket .backlog
The maximum number of pending connections that may be queued on the socket at any given time. The maximum cannot exceed 5.
This routine creates a queue for pending connection requests on socket s with a maximum size of backlog. Connections may then be accepted with accept .If a connection request arrives with the queue full (more than backlog connection requests pending), the client will receive a timeout.
See also accept , connect , and socket in this section.
0 Indicates success. --1 Indicates an error; errno is set to one of the following values:
- EBADF -- The socket descriptor is invalid.
- ENOTSOCK -- The socket descriptor references a file, not a socket.
- EOPNOTSUPP -- The socket is not of a type that supports the operation listen .
Converts longwords from network to host byte order.
#include <in.h>unsigned long int ntohl (unsigned long int netlong);
netlong
A longword in network byte order. Integers in network byte order cannot be used for arithmetic computation on VAX systems.
This routine converts 32-bit unsigned integers from network byte order to host 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 host byte order.
Previous | Next | Contents | Index |
|