  | 
		
		
			
			
Compaq C
Compaq C Run-Time Library Reference Manual for 
OpenVMS Systems
 
 
 
close
 
Closes a connection and deletes a socket descriptor.
 
 
Format
#include <unixio.h>
int close (s);
 
  
 
Argument
s
A socket descriptor.
 
 
Description
This routine deletes a descriptor from the per-process object reference 
table. If this is the last reference to the underlying object, then it 
will be deactivated.
See also
accept
,
socket
, and
write
 in this section.
  
 
Return Values
  
    | 
      0
     | 
    
      Indicates success.
     | 
   
  
    | 
      --1
     | 
    
      Indicates an error;
      
      errno
      
               is set to EBADF (The socket descriptor is invalid.)
     | 
   
 
 
 
connect
 
Initiates a connection on a socket.
 
 
Format
#include <socket.h>
int connect (int s, struct sockaddr *name, int 
namelen);
 
 (_DECC_V4_SOURCE)
int connect (int s, const struct sockaddr *name, 
size_t namelen);
 
 (NOT _DECC_V4_SOURCE)
  
Routine Variants This socket routine has a variant named
__bsd44_connect
. Enabled by defining
_SOCKADDR_LEN
, this variant implements 4.4BSD-compatible semantics. See 
Section A.7 for more information.
 
Arguments
s
A socket descriptor that has been created with
socket
.
name
The address of a structure that specifies the name of the remote socket 
in the format specific to the address family (AF_INET).
namelen
The size, in bytes, of the structure pointed to by name.
 
 
Description
If s is a socket descriptor of type SOCK_DGRAM, then this call 
permanently specifies the peer to which data is to be sent. If it is of 
type SOCK_STREAM, then this call attempts to make a connection to 
another socket.
Each communications space interprets the name parameter in its 
own way. This argument specifies the socket to which the socket 
specified in s is to be connected.
 
See also
accept
,
select
,
socket
,
getsockname
, and
shutdown
 in this appendix.
  
 
Return Values
  
    | 
      0
     | 
    
      Indicates success.
     | 
   
  
    | 
      --1
     | 
    
      Indicates an error;
      
      errno
      
               is set to one of the following:
      
      - EBADF -- The socket descriptor is invalid.
      
 - ENOTSOCK -- The socket descriptor references a file, not a socket.
      
 - EADDRNOTAVAIL -- specified address is not available from the local 
      machine.
      
 - EAFNOSUPPORT -- Address in the specified address family cannot be 
      used with this socket.
      
 - EISCONN -- The socket is already connected.
      
 - ETIMEOUT -- Connection establishment timed out without establishing 
      a connection.
      
 - ECONNREFUSED -- The attempt to connect was forcefully rejected.
      
 - ENETUNREACH -- The network is not reachable from this host.
      
 - EADDRINUSE -- The specified Internet address and ports are already 
      in use.
      
 - EFAULT -- The
      name parameter is not a valid part of the user address space.
      
 - EWOULDBLOCK -- The socket is nonblocking and the connection cannot 
      be completed immediately. It is possible to
      
      select
      
               the socket while it is connecting by selecting it for writing.
      
  
     | 
   
 
 
 
decc$get_sdc
 
Returns the Socket Device Channel (SDC) associated with a socket 
descriptor for direct use with the TCP/IP Services for  OpenVMS product.
 
 
Format
#include <socket.h>
short int decc$get_sdc (int s);
 
  
 
Argument
s
A socket descriptor.
 
 
Description
This routine returns the SDC associated with a socket. C socket 
descriptors are normally used either as file descriptors or with one of 
the routines that take an explicit socket descriptor as its argument. C 
sockets are implemented using TCP/IP Services for  OpenVMS Socket Device Channels. 
This routine returns the SDC used by a given socket descriptor so that 
you can use the TCP/IP Services for  OpenVMS's facilities directly by means of 
various I/O system services ($QIO).
 
 
Return Values
  
    | 
      0
     | 
    
      Indicates that
      s is not an open socket descriptor.
     | 
   
  
    | 
      x
     | 
    
      The SDC number.
     | 
   
 
 
 
endhostent
 
Closes host database file.
 
 
Format
#include <netdb.h>
void endhostent (void);
 
  
 
Description
The
endhostent
 routine closes the network host database file, previously opened with 
 the
gethostbyaddr
 or
gethostbyname
 routine.
See also
gethostbyaddr
, and
gethostbyname
 in this section.
  
 
Errors
  
    | 
       
     | 
    
      If the
      
      endhostent
      
               routine does not exist in your TCP/IP library, then
      
      errno
      
               is set to ENOSYS.
     | 
   
 
 
 
endnetent
 
Closes the networks database file.
 
 
Format
#include <netdb.h>
void endnetent (void);
 
  
 
Description
The
endentent
 routine closes the networks database file, previously opened with the
getnetent
,
setnetent
,
getnetbyaddr
 or
getnetbyname
 routine.
See also
getnetent
,
getnetbyaddr
,
getnetbyname
, and
setnetent
 in this section.
  
 
Errors
  
    | 
       
     | 
    
      If the
      
      endnetent
      
               routine does not exist in your TCP/IP library, then
      
      errno
      
               is set to ENOSYS.
     | 
   
 
 
 
endprotoent
 
Closes the protocols database file.
 
 
Format
#include <netdb.h>
void endprotoent (void);
 
  
 
Description
The
endprotoent
 routine closes the network protocols database file, previously opened 
 with the
getprotoent
,
getprotobyname
, or
getprotobynumber
 routine.
See also
getprotobyname
,
getprotoent
 and
getprotobynumber
 in this section.
  
 
Errors
  
    | 
       
     | 
    
      If the
      
      endprotoent
      
               routine does not exist in your TCP/IP library, then
      
      errno
      
               is set to ENOSYS.
     | 
   
 
 
 
endservent
 
Closes the network services database file.
 
 
Format
#include <netdb.h>
void endservent (void);
 
  
 
Description
The
endservent
 routine closes the network services database file, previously opened 
 with the
getservent
,
getservbyname
, or
getservbyport
 routine.
See also
getservent
,
getservbyname
, and
getservbyport
 in this section.
  
 
Errors
  
    | 
       
     | 
    
      If the
      
      endservent
      
               routine does not exist in your TCP/IP library, then
      
      errno
      
               is set to ENOSYS.
     | 
   
 
 
 
gethostaddr
 
Returns the standard host address for the processor.
 
 
Format
#include <socket.h>
int gethostaddr (char *addr);
 
  
 
Arguments
addr
A pointer to the buffer in which the standard host address for the 
current processor is returned.
 
 
Description
This system call returns the standard host address for the current 
processor. The returned address is null-terminated. The addr 
parameter must point to at least 16 bytes of free space.
Host addresses are limited to 16 characters.
  
 
Return Values
  
    | 
      0
     | 
    
      Indicates success.
     | 
   
  
    | 
      --1
     | 
    
      Indicates that an error has occurred and is further specified in the 
      global
      
      errno
      
              .
     | 
   
 
 
 
gethostbyaddr
 
Searches the host database sequentially from the beginning of the 
database for a host record with a given address.
 
 
Format
#include <netdb.h>
struct hostent *gethostbyaddr (char *addr, int len, 
int type);
 
  
Routine Variants This socket routine has a variant named
__bsd44_gethostbyaddr
. Enabled by defining
_SOCKADDR_LEN
, this variant implements 4.4BSD-compatible semantics. See 
Section A.7 for more information.
 
Arguments
addr
A pointer to a series of bytes in network order specifying the address 
of the host sought. This argument does not point to an ASCII string.
len
The number of bytes in the address pointed to by the addr 
argument.
type
The type of address format being sought. Currently, only AF_INET 
(defined in
<socket.h>
) is supported.)
 
 
Description
This routine finds the first host record in the host database with the 
given address.
The
gethostbyaddr
 routine uses a common static area for its return values. This means 
 that subsequent calls this routine will overwrite any existing host 
 entry. You must make a copy of the host entry if you wish to save it.
  
 
Return Values
  
    | 
      NULL
     | 
    
      Indicates an error.
     | 
   
  
    | 
      x
     | 
    
      A pointer to an object having the
      
      hostent
      
               structure. See
      
      <netdb.h>
      
               for a description of the
      
      hostent
      
               structure.
       Depending on the error condition and the socket implementation 
      selected,
      
      errno
      
               or
      
      h_errno
      
               might be set to further indicate the error. (See sections 
               A.5 and A.6.)
      | 
   
 
 
 
gethostbyname
 
Searches the host database sequentially from the beginning of the 
database for a host record with a given name or alias.
 
 
Format
#include <netdb.h>
struct hostent *gethostbyname (char *name);
 
  
Routine Variants This socket routine has a variant named
__bsd44_gethostbyname
. Enabled by defining
_SOCKADDR_LEN
, this variant implements 4.4BSD-compatible semantics. See 
Section A.7 for more information.
 
Argument
name
A pointer to a null-terminated character string containing the name or 
an alias of the host sought.
 
 
Description
This routine finds the first host in the host database with the given 
name or alias.
The
gethostbyname
 routine uses a common static area for its return values. This means 
 that subsequent calls to this routine will overwrite any existing host 
 entry. You must make a copy of the host entry if you wish to save it.
  
 
Return Values
  
    | 
      NULL
     | 
    
      Indicates an error.
     | 
   
  
    | 
      x
     | 
    
      A pointer to an object having the
      
      hostent
      
               structure. See
      
      <netdb.h>
      
               for a description of the
      
      hostent
      
               structure.
       Depending on the error condition and the socket implementation 
      selected,
      
      errno
      
               or
      
      h_errno
      
               might be set to further indicate the error. (See sections 
               A.5 and A.6.)
      | 
   
 
 
 
gethostent
 
Gets a host file entry from the network host database file.
 
 
Format
#include <netdb.h>
struct hostent *gethostent (void);
 
  
 
Description
The
gethostent
 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
hostent
 structure.
 
This routine uses a common static area for its return values. 
Therefore, 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.
  
 
Return Values
  
    | 
      x
     | 
    
      A pointer to the
      
      hostent
      
               structure.
     | 
   
  
    | 
      NULL
     | 
    
      Indicates an error.
     | 
   
 
 
 
gethostname
 
Returns the name currently associated to the host.
 
 
Format
#include <socket.h>
int gethostname (char *name, int namelen);
 
 (_DECC_V4_SOURCE)
int gethostname (char *name, size_t namelen);
 
 (NOT _DECC_V4_SOURCE)
  
 
Arguments
name
The address of a buffer into which the name should be written. The 
returned name is null-terminated unless sufficient space is not 
provided.
namelen
The size of the buffer pointed to by name.
 
 
Description
This routine returns the hostname maintained by the TCP/IP Services for  OpenVMS or 
compatible TCP/IP product.
 
 
Return Values
  
    | 
      0
     | 
    
      Indicates success.
     | 
   
  
    | 
      --1
     | 
    
      Indicates an error;
      
      errno
      
               is set to one of the following:
      
      - EFAULT -- The buffer decribed by
      name and
      namelen is not a valid, writable part of the user address 
      space.
      
 - EINVAL -- The returned name is an invalid address.
      
  
     | 
   
 
 
 
getnetbyaddr
 
Searches the network database sequentially from the beginning of the 
database for a network record with a given address.
 
 
Format
#include <netdb.h>
struct netent *getnetbyaddr (long net, int type);
 
  
 
Arguments
net
The network number, in host byte order, of the network database entry 
required.
type
The type of network sought. Currently, only AF_INET (defined in
<socket.h>
) is supported.
 
 
Description
This routine finds the first network record in the network database 
with the given address.
The
getnetent
,
getnetbyaddr
, and
getnetbyname
 routines all use a common static area for their return values. This 
 means that subsequent calls to any of these routines will overwrite any 
 existing network entry. You must make a copy of the network entry if 
 you wish to save it.
  
 
Return Values
  
    | 
      NULL
     | 
    
      Indicates EOF or an error.
     | 
   
  
    | 
      x
     | 
    
      A pointer to an object having the
      
      netent
      
               structure. See the
      
      <netdb.h>
      
               header file for a description of the
      
      netent
      
               structure.
     | 
   
 
 
 
getnetbyname
 
Searches the network database sequentially from the beginning of the 
database for a network record with a given name or alias.
 
 
Format
#include <netdb.h>
struct netent *getnetbyname (char *name);
 
  
 
Argument
name
A pointer to a null-terminated character string of the name or an alias 
of the network sought.
 
 
Description
This routine finds the first host in the network database with the 
given name or alias.
The
getnetent
,
getnetbyaddr
, and
getnetbyname
 routines all use a common static area for their return values. This 
 means that subsequent calls to any of these routines will overwrite any 
 existing network entry. You must make a copy of the network entry if 
 you wish to save it.
  
 
Return Values
  
    | 
      NULL
     | 
    
      Indicates EOF or an error;
      
      errno
      
               is set to EFAULT (The buffer described by
      name is not a valid, writable part of the user address space.)
     | 
   
  
    | 
      x
     | 
    
      A pointer to an object having the
      
      netent
      
               structure. See the
      
      <netdb.h>
      
               header file for a description of the
      
      netent
      
               structure.
       Depending on the error condition and the socket implementation 
      selected,
      
      errno
      
               or
      
      h_errno
      
               might be set to further indicate the error. (See sections 
               A.5 and A.6.)
      | 
   
 
 
 
getnetent
 
Gets a network file entry from the networks database file.
 
 
Format
#include <netdb.h>
struct netent *getnetnet (void);
 
  
 
Description
The
getnetent
 routine opens and sequentially reads the networks database file to 
 retrieve network information.
See the
<netdb.h>
 header file for a description of the
netent
 structure.
 
The
getnetent
 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
setnetent
, and
endnetent
in this section.
  
 
Return Values
  
    | 
      x
     | 
    
      A pointer to a
      
      netent
      
               structure.
     | 
   
  
    | 
      0
     | 
    
      Indicates an error or EOF.
     | 
   
 
 
 
getpeername
 
Returns the name of the connected peer.
 
 
Format
#include <socket.h>
int getpeername (int s, struct sockaddr *name, int 
*namelen);
 
 (_DECC_V4_SOURCE)
int getpeername (int s, struct sockaddr *name, size_t 
*namelen);
 
 (NOT _DECC_V4_SOURCE)
  
Routine Variants This socket routine has a variant named
__bsd44_getpeername
. Enabled by defining
_SOCKADDR_LEN
, this variant implements 4.4BSD-compatible semantics. See 
Section A.7 for more information.
 
Arguments
s
A socket descriptor that has been created using
socket
.
name
A pointer to a buffer within which the peer name is to be returned.
namelen
An address of an integer that specifies the size of the name 
buffer. On return, it will be modified to reflect the actual length, in 
bytes, of the name returned.
 
 
Description
This routine returns the name of the peer connected to the socket 
descriptor specified.
See also
bind
,
getsockname
, and
socket
 in this appendix.
  
 
Return Values
  
    | 
      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.
      
 - ENOTCONN -- The socket is not connected.
      
 - 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.
      
  
     | 
   
 
 
  
         | 
	 
	  | 
	 
		 
		 |