United States    
COMPAQ STORE | PRODUCTS |
SERVICES | SUPPORT | CONTACT US | SEARCH
Compaq C

Compaq C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index

A.3.2 User Datagram Protocol

User Datagram Protocol (UDP) is a simple, unreliable datagram protocol used to support the SOCK_DGRAM abstraction for the Internet protocol family. UDP sockets are connectionless and are normally used with the sendto and recvfrom calls, though the connect call may also be used to fix the destination for future packets (in which case the recv or read or write system calls may be used).

UDP address formats are identical to those used by TCP. In particular, UDP provides a port identifier in addition to the normal Internet address format. Note that the UDP port space is separate from the TCP port space (for example, a UDP port may not be connected to a TCP port). Also, broadcast packets may be sent (assuming the underlying network supports this) by using a reserved broadcast address; this address is network interface dependent. The SO_BROADCAST option must be set on the socket and the process must have the SYSPRV or BYPASS privilege for broadcasting to succeed.

A.4 errno Values

errno is an external variable whose value is set whenever an error occurs during a call to any of the Compaq C RTL routines. You can use this value to obtain a more detailed description of the error. errno is not cleared on successful calls, so its value should be checked only when an error has been indicated.

Most calls to the Compaq C RTL routines have one or more returned values. Any error condition is indicated by an otherwise impossible return value. This is almost always --1; the individual routine descriptions specify the details.

All return codes and values from routines are of type int unless otherwise noted. An error number is also made available in the external variable errno , which is not cleared on successful calls. The errno values may be translated to a message, similar to that found in UNIX systems, by using the perror routine. vaxc$errno may also be returned as an error.

NOTE

The notation [...] is used in this manual to denote an errno error.

Table A-2 lists the errno values.

Table A-2 errno Values
Value Meaning
EINPROGRESS Operation now in progress
  An operation that takes a long time to complete, such as connect , was attempted on a nonblocking object.
EALREADY Operation already in progress
  An operation was attempted on a nonblocking object that already had an operation in progress.
ENOTSOCK Socket operation on a non-socket
EDESTADDRREQ Destination address required
  A required address was omitted from an operation on a socket.
EMSGSIZE Message too long
  A message sent on a socket was larger than the internal message buffer.
EPROTOTYPE Protocol wrong type for socket
  A protocol was specified that does not support the semantics of the socket type requested. For example, you cannot use the ARPA Internet UDP protocol with type SOCK_STREAM.
ENOPROTOOPT Protocol not available
  A bad option was specified in a getsockopt or setsocketopt call.
EPROTONOSUPPORT Protocol not supported
  The protocol has not been configured into the system or no implementation for it exists.
ESOCKTNOSUPPORT Socket type not supported
  The support for the socket type has not been configured into the system or no implementation for it exists.
EOPNOTSUPP Error-operation not supported
  For example, trying to accept a connection on a datagram socket.
EPFNOSUPPORT Protocol family not supported
  The protocol family has not been configured into the system or no implementation for it exists.
EAFNOSUPPORT Address family not supported by protocol family
  An address incompatible with the requested protocol was used.
EADDRINUSE Address already in use
  Each address can be used only once.
EADDRNOTAVAIL Cannot assign requested address
  Normally, results from an attempt to create a socket with an address not on this machine.
ENETDOWN Network is down
  A socket operation encountered a dead network.
ENETUNREACH Network is unreachable
  A socket operation was attempted to an unreachable network.
ENETRESET Network dropped connection on reset
  The host you were connected to crashed and rebooted.
ECONNABORTED Software caused connection abort
  A connection abort was caused internal to your host machine.
ECONNRESET Connection reset by peer
  A connection was forcibly closed by a peer. This usually results from the peer executing a shutdown call.
ENOBUFS No buffer space available
  An operation on a socket or pipe was not performed because the system lacked sufficient buffer space.
EISCONN Socket is already connected
  A connect request was made on an already connected socket; or, a sendto or sendmsg request on a connected socket specified a destination other than the connected party.
ENTOTCONN Socket is not connected
  Request to send or receive data was disallowed because the socket is not connected.
ESHUTDOWN Cannot send after socket shutdown
  A request to send data was disallowed because the socket had already been shut down with a previous shutdown call.
ETOOMANYREFS Too many references: cannot splice
ETIMEDOUT Connection timed out
  A connect request failed because the connected party did not properly respond after a period of time. (The timeout period is dependent on the communication protocol.) A connect request or remote file operation failed because the connected party did not properly respond after a period of time that is dependent on the communication protocol.
ECONNREFUSED Connection refused
  No connection could be made because the target machine actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host.
ELOOP Too many levels of symbolic links
  A path name lookup involved more than eight symbolic links.
ENAMETOOLONG File name too long
  A component of a path name exceeded 255 characters, or an entire path name exceeded 1023 characters.
EHOSTDOWN Host is down
  A socket operation failed because the destination host was down.
EHOSTUNREACH No route to host
  A socket operation was attempted to an unreachable host.
EVMSERR OpenVMS system-specific error code that is nontranslatable

A.5 h_errno Values

The external integer h_errno is available only with OpenVMS Version 7.0, and is set only by a 4.4BSD TCP/IP interface. Specifically, The gethostbyname and gethostbyaddr functions require 4.4BSD semantics to set h_errno . The gethostbyname and gethostbyaddr functions indicate an error condition by returning a null pointer and setting the external integer h_errno to indicate the error return status.

When gethostbyname or gethostbyaddr returns an error status, h_errno , which is very similar to errno , can be checked to determine whether the error is the result of a temporary failure or an invalid or unknown host.

Use the herror routine to print the error message describing the failure. If the argument string to herror is not NULL, it is printed, followed by a colon (:) and a space. The error message is printed with a trailing new-line character.

Note

The h_errno error codes are not available with the errno variable.

The <netdb.h> header file declares h_errno on a per-thread basis as:


#define h_errno   (*decc$h_errno_get_addr()) 

The <netdb.h> header file also symbolically defines the error code values that h_errno can accept, as follows:
HOST_NOT_FOUND No such host is known.
TRY_AGAIN Usually a temporary error that means the local server did not receive a response from an authoritative server. A retry at some later time can succeed.
NO_RECOVERY An unexpected server failure is encountered. This is a nonrecoverable error.
NO_DATA The requested name is valid but does not have an IP address; this is not a temporary error. The name is known to the name server but there is no address associated with this name. Another type of request to the name server using this domain name results in an answer; for example, a mail-forwarder registered for this domain.
NO_ADDRESS No address; look for MX record

Like errno , the value of h_errno is zero at program startup. Checking h_errno is valid only when a failure status is returned by a Compaq C RTL routine that is defined to set it.

A.6 Relationship Between errno and h_errno

Since the routines that set h_errno can also set errno , this section explains the relationship between the two variables.

A given routine failure does not set both h_errno and errno for the same failure. A routine failure sets either h_errno or errno depending on which is appropriate for the failing condition.

For example, consider the following program:


/* Demonstrate relationship between errno and h_errno   */ 
/* from Appendix A of the reference manual              */ 
 
#include   <errno.h> 
#include   <stdio.h> 
#include   <netdb.h> 
 
main() 
{ 
    static char hostname[256]; 
    struct hostent *hostentptr; 
 
    errno = 0; 
    h_errno = 0; 
    if ((hostentptr = gethostbyname("hndy")) == NULL) { 
        printf("unknown host name errno is: %d h_errno is: %d\n", errno, h_errn 
        perror("p_gethostbyname"); 
        herror("h_gethostbyname"); 
    } 
 
    errno = 0; 
    h_errno = 0; 
    if ((hostentptr = gethostbyname(0)) == NULL) { 
        printf("illegal host name errno is: %d h_errno is: %d\n", errno, h_errn 
        perror("p_gethostbyname"); 
        herror("h_gethostbyname"); 
    } 
}       

In the first call to gethostbyname , the host name parameter "hndy" does not represent a known host. In this case, gethostbyname sets h_errno to host_not_found , but does not set errno .

The call to perror in this example would output:


    p_gethostbyname: Error 0 

The call to herror in this example would print a message describing the failure:


    h_gethostbyname: Unknown 

In the second call to gethostbyname , the host name parameter is 0 (zero), an invalid argument. In this case, gethostbyname sets errno to einval , but does not set h_errno .

A call to perror would print a message describing the failure:


    p_gethostbyname: Invalid 

A call to herror would print:


    h_gethostbyname: Error 0 

A.7 TCP/IP Interface Enhancements

The Compaq C RTL provides the language bindings for a 4.4BSD-compatible TCP/IP implementation. The underlying 4.4BSD semantics for the specific TCP/IP routines are the responsibility of the TCP/IP back-end vendors.

With 4.4BSD semantics, gethostbyname and gethostbyaddr set the external variable h_errno . Other routines (see Table A-3) deal with 4.4BSD versions of the sockaddr and msghdr data structures. See the <socket.h> header file for a description of these structures.

The TCP/IP backend routines need to know the following:

This information is controlled by the _sockaddr_len feature-test macro (see Section 1.5).

Compiling with _sockaddr_len defined will enable the entry points that have 4.4BSD semantics. See Table A-3. Otherwise, entry points expecting pre-4.4BSD semantics are enabled.

Table A-3 4.4BSD Entry Points
__bsd44_accept __bsd44_gethostbyaddr __bsd44_recvfrom
__bsd44_bind __bsd44_gethostbyname __bsd44_recvmsg
__bsd44_connect __bsd44_getpeername __bsd44_sendto
  __bsd44_getsockname __bsd44_sendmsg

A.8 Summary of Socket Routines

This section groups and briefly describes the socket routines. For complete descriptions, see the routine reference section that follows in this appendix.

A.8.1 Basic Communication Routines

Table A-4 lists the basic communication routines that make up the building blocks of Internet programs.

Table A-4 Basic Communication Routines
Routine Description
accept Accepts a connection on a socket.
bind Binds a name to a socket.
close Closes a connection and deletes a socket descriptor.
connect Initiates a connection on a socket.
ioctl Controls socket operations only.
listen Sets the maximum limit of outstanding connection requests for a socket.
read Reads bytes from a file or socket and places them into a buffer.
readv Not implemented.
recv Receives bytes from a socket and places them into a buffer.
recvfrom Receives bytes for a socket from any source.
recvmsg Receives bytes from a socket and places them into scattered buffers.
select Allows the polling or checking of a group of sockets.
send Sends bytes through a socket to a connected peer.
sendmsg Sends gathered bytes through a socket to any other socket.
sendto Sends bytes through a socket to any other socket.
shutdown Shuts down all or part of a bidirectional socket.
socket Creates an endpoint for communication by returning a socket descriptor.
write Writes bytes from a buffer to a file or socket.
writev Not implemented.


Previous Next Contents Index
  

1.800.AT.COMPAQ

privacy and legal statement