[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP TCP/IP Services for OpenVMS
Sockets API and System Services Programming


Previous Contents Index


getservent()

Retrieves an entry from the services database file.

Format

#include <netdb.h>

struct servent *getservent (void);


Description

This function reads the next line of the services database file (TCPIP$ETC:SERVICES.DAT).

An application program can use the getservent() function to retrieve information about a service (such as the protocol or the ports it uses) from the services database.

The getservent() function returns a servent structure that contains information from the services database file. See Section 3.2.11 for a description of the servent structure. The servent structure is defined in the NETDB.H header file.

The ASCII text services database file remains open after a call by the getservent() function. Use the endservent() function to close the services database file. Use the setservent() function to open the services database file and reset the file marker to the beginning of the file.

The getservent function uses a common static area for its return values, so subsequent calls to this function overwrite any existing service entry. To save the services entry, you must make a copy of it.

Related Functions

See also setservent and endservent .


Return Values

x A pointer to a servent structure.
NULL Indicates an error or end of file.

getsockname()

Returns the name associated with a socket.

The $QIO equivalent is the IO$_SENSEMODE function with the p3 argument.


Format

#include <types.h>

#include <socket.h>

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)


Arguments

s

A socket descriptor created with the socket() function and bound to the socket name with the bind() function.

name

A pointer to the buffer in which getsockname() should return the socket name.

namelen

A pointer to an integer containing the size of the buffer pointed to by name. On return, the integer indicates the actual size, in bytes, of the name returned.

Description

This function returns the current name for the specified socket descriptor. The name is in a format specific to the address family assigned to the socket (AF_INET, or AF_INET6 with BSD 4.4 when _SOCKADDR_LEN is defined).

The bind() function, not the getsockname() function, makes the association of the name to the socket.

Related Functions

See also bind() and socket() .


Return Values

0 Successful completion.
-1 Error; errno is set to indicate the error.

Errors

EBADF The descriptor is invalid.
EFAULT The name argument is not a valid part of the user address space.
ENOBUFS The system has insufficient resources to complete the call.
ENOTSOCK The socket descriptor is invalid.
EOPNOTSUPP The operation is not supported for this socket's protocol.

getsockopt()

Returns the options set on a socket.

The $QIO equivalent is the IO$_SENSEMODE function.


Format

#include <types.h>

#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)


Arguments

s

A socket descriptor created by the socket() function.

level

The protocol level for which the socket options are desired. It can 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 specified by p. The IPPROTO values are defined in the IN.H header file (for IPv4), or the IN6.H header file (for IPv6).

optname

Interpreted by the protocol specified in the level. Options at each protocol level are documented with the protocol.

For descriptions of the supported socket level options, see the description of setsockopt() in this chapter.

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 is modified to indicate the actual size of the option value returned.

Description

This function gets information on socket options. See the appropriate protocol for information about available options at each protocol level.

Return Values

0 Successful completion.
-1 Error; errno is set to indicate the error.

Errors

EACCES The calling process does not have appropriate permissions.
EBADF The socket descriptor is invalid.
EDOM The send and receive timeout values are too large to fit in the timeout fields of the socket structure.
EFAULT The address pointed to by the optval argument is not in a valid (writable) part of the process space, or the optlen argument is not in a valid part of the process address space.
EINVAL The optval or optlen argument is invalid; or the socket is shut down.
ENOBUFS The system has insufficient resources to complete the call.
ENOTSOCK The socket descriptor is invalid.
ENOPROTOOPT The option is unknown or the protocol is unsupported.
EOPNOTSUPP The operation is not supported by the socket protocol.
ENOPROTOOPT The option is unknown.
ENOTSOCK The socket descriptor is invalid.

herror()

Writes a message to standard error explaining h_error .

Format

#include <netdb.h>

void herror (const char *string);


Argument

string

A user-printable string.

Description

This function maps the error number in the external variable h_errno to a locale-dependent error message.

hostalias()

Searches for host aliases associated with a name.

Format

#include <resolv.h>

char *hostalias (const char *name);


Argument

name

Points to the name of the host that you want to retrieve aliases from.

Description

This function searches for the alias associated with the name argument. The HOSTALIASES logical name can be used to define the name of a file that lists the host aliases, in the form:


    host    alias

Return Values

x The host alias.
NULL Indicates an error.

hstrerror()

Returns an error message string.

Format

#include <string.h>

char *hstrerror (int errnum);


Arguments

errnum

An error number specifying a value of h_errno .

Description

This function maps the error number specified by the errnum argument to a location-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 function.

Return Values

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.

Errors

  If the hstrerror() function fails, errno is set to EINVAL, indicating the value of the errnum argument is an invalid error number.

htonl()

Converts longwords from host byte order to network byte order.

Format

#include <in.h>

unsigned long int htonl ( unsigned long int hostlong );


Argument

hostlong

A longword in host byte order (OpenVMS systems).

Description

This function converts 32-bit unsigned integers from host byte order to network byte order.

Data bytes transmitted over the network are expected to be in network byte order. Some hosts, like OpenVMS, have an internal data representation format that is different from the network byte order; this is called the host byte order. Network byte order places the byte with the most significant bits at lower addresses, but OpenVMS host byte order places the most significant bits at the highest address.

This function can be used to convert IP addresses from host byte order to network byte order.

Note

The 64-bit return from OpenVMS Alpha and I64 systems has zero-extended bits in the high 32 bits of R0.

Return Value

x A longword in network byte order.

htons()

Converts short integers from host byte order to network byte order.

Format

#include <in.h>

unsigned short int htons ( unsigned short int hostshort );


Argument

hostshort

A short integer in host byte order (OpenVMS systems). All short integers on OpenVMS systems are in host byte order unless otherwise specified.

Description

This function converts 16-bit unsigned integers from host byte order to network byte order.

Data bytes transmitted over the network are expected to be in network byte order. Some hosts, like OpenVMS, have an internal data representation format that is different from the network byte order; this is called the host byte order. Network byte order places the byte with the most significant bits at lower addresses, but OpenVMS host byte order places the most significant bits at the highest address.

This function is most often used with ports returned by the getservent() function. To convert port numbers from OpenVMS host byte order to network byte order, use the htons() function.

Note

The 64-bit return from OpenVMS Alpha and I64 systems has zero-extended bits in the high 32 bits of R0.

Return Value

x A short integer in network byte order. Integers in network byte order cannot be used for arithmetic computation on OpenVMS systems.

if_freenameindex()

Frees dynamic memory allocated by if_nameindex() to the array of interface names and indexes

Format

#include <if.h>

void if_freenameindex ( struct if_nameindex *ptr );


Arguments

ptr

Points to an array of structures returned by the if_nameindex() function.

Description

The if_freenameindex() function frees dynamic memory allocated to the array of interface names and indexes that the if_nameindex() function returned.

if_indextoname()

Maps an interface index to its corresponding name.


Format

#include <if.h>

char *if_indextoname ( unsigned int ifindex, char *ifname );


Arguments

ifindex

The interface index.

ifname

Points to a buffer that is IFNAMSIZ bytes in length. (IFNAMSIZ is defined in the IF.H header file.) If an interface name is found, it is returned in the buffer.

Description

This function maps an interface index to its corresponding name.

Return Values

Interface name If interface name is found, it is returned to the buffer.
NULL If no interface name corresponds to the specified index, the function returns NULL and sets errno to ENXIO.

Errors

ENXIO No interface name corresponds to the specified index.
System error A system error.

if_nameindex()

Returns an array of all interface names and indexes.


Format

#include <if.h>

struct if_nameindex *if_nameindex ( void );


Description

This function dynamically allocates memory for an array of if_nameindex structures, one structure for each interface. A structure with an if_index value of 0 and a NULL if_name value indicates the end of the array.

The following if_nameindex structure must also be defined by including the IF.H header file prior to the call to if_nameindex() :



struct if_nameindex {
   unsigned int   if_index;
   char           *if_name;
};

To free the memory allocated by this function, use the if_freenameindex() function. If an error occurs, the function returns a NULL pointer and sets errno to an appropriate value.


Return Values

NULL Indicates an error; errno is set to an appropriate value.

if_nametoindex()

Maps an interface name to its corresponding index.

Format

#include <if.h>

unsigned int if_nametoindex ( const char *ifname );


Arguments

ifname

Points to a buffer that contains the interface name.

Description

This function maps an interface name to its corresponding interface index number.

Return Values

0 (zero) Interface does not exist.
x Upon successful conversion, the if_nametoindex() function returns an interface index number.

inet6_opt_append()

Returns the length of an IPv6 extension header with a new option and appends the option.


Format

#include <in6.h>

int inet6_opt_append ( void *extbuf, size_t extlen, int offset, uint8_t type, size_t len, uint_t align, void **databufp );


Arguments

extbuf

Points to a buffer that contains an extension header. This is either a valid pointer or a NULL pointer.

extlen

Specifies the length of the extension header to initialize. Valid values are 0 if extbuf equals 0, a value returned by inet6_opt_finish() , or any number that is a multiple of 8.

offset

Specifies the length of the existing extension header. Obtain this value from a prior call to inet6_opt_init() or inet6_opt_append() .

type

Specifies the type of option. Specify a value from 2 to 255, inclusive, excluding 194.

len

Specifies the length of the option data, excluding the option type and option length fields. Specify a value from 0 to 255, inclusive.

align

Specifies the alignment of the option. Specify one of the following values: 1, 2, 4, or 8.

databufp

Points to a buffer that contains the option data.

Description

This function, when called with extbuf as a NULL pointer and extlen as 0, returns the updated number of bytes in an extension header.

If you specify extbuf as a valid pointer and valid extlen and align arguments, the function returns the same information as in the previous case, but also inserts the pad option, initializes the type and len fields, and returns a pointer to the location for the option content.

After you call inet6_opt_append() , you can then use the data buffer directly or call inet6_opt_set_val() to specify the option contents.


Return Values

x Upon successful completion, the inet6_opt_append() function returns the updated number of bytes in an extension header.
-1 Failure

Errors

EBADF The socket descriptor is invalid.
ECONNABORTED A connection has been aborted.
EFAULT The addr argument is not in a writable part of the user address space.
EINTR The accept() function was interrupted by a signal before a valid connection arrived.
EINVAL The socket is not accepting connections.
EMFILE There are too many open file descriptors.
ENFILE The maximum number of file descriptors in the system is already open.
ENETDOWN TCP/IP Services was not started.
ENOBUFS The system has insufficient resources to complete the call.
ENOMEM The system was unable to allocate kernel memory.
ENOTSOCK The socket descriptor is invalid.
EOPNOTSUPP The reference socket is not of type SOCK_STREAM .
EPROTO A protocol error occurred.
EWOULDBLOCK The socket is marked nonblocking, and no connections are present to be accepted.


Previous Next Contents Index