Berkeley Sockets/iX Reference Manual ABCDE Printed in USA Edition 3 E0294 02/94
Notice Hewlett-Packard makes no warranty of any kind with regard to this material, including, but not limited to, the implied warranties of merchantability and tness for a particular purpose. Hewlett-Packard shall not be liable for errors contained herein or for incidental or consequential damages in connection with the furnishing, performance, or use of this material. This document contains proprietary information which is protected by copyright. All rights are reserved.
Printing History New editions are complete revisions of the manual. Updates, which are issued between editions, contain additional and replacement pages to be merged into the manual. The dates on the title page change only when a new edition or a new update is published. Edition 1 . . . . . . . . . . . . . . . . . . . . . . . . . . June 1992 Edition 2 . . . . . . . . . . . . . . . . . . . . . . . . . . October 1992 Edition 3 . . . . . . . . . . . . . . . . . . . . . . . . . .
Preface MPE/iX, Multiprogramming Executive with Integrated POSIX, is the latest in a series of forward-compatible operating systems for the HP 3000 line of computers. In HP documentation and in talking with HP 3000 users, you will encounter references to MPE XL, the direct predecessor of MPE/iX. MPE/iX is a superset of MPE XL. All programs written for MPE XL will run without change under MPE/iX.
Contents 1. Introduction References Used . . . . . . . . . . . . . . . . Include Files Used . . . . . . . . . . . . . . . POSIX Function Support . . . . . . . . . . . . 2. Socket System Calls SOCKET . . . . . C Interface . . . Description . . . Return Value . . Errors . . . . . . MPE/iX Speci c . Author . . . . . BIND . . . . . . . C Interface . . . Description . . . Examples . . . . Return Value . . Errors . . . . . . MPE/iX Speci c . Author . . . . . See Also . . . . . LISTEN . . . . . . C Interface . . .
Errors . . . . . . . . . . . MPE/iX Speci c . . . . . . Author . . . . . . . . . . See Also . . . . . . . . . . SOCKETPAIR . . . . . . . . C Interface . . . . . . . . Description . . . . . . . . Return Value . . . . . . . Errors . . . . . . . . . . . See Also . . . . . . . . . . SEND . . . . . . . . . . . . C Interface . . . . . . . . Description . . . . . . . . Return Value . . . . . . . Errors . . . . . . . . . . . MPE/iX Speci c . . . . . . Author . . . . . . . . . . See Also . . . . . . . . . . RECV . .
GETSOCKNAME . . . . . . C Interface . . . . . . . . Description . . . . . . . . Return Value . . . . . . . Errors . . . . . . . . . . . Author . . . . . . . . . . See Also . . . . . . . . . . GETHOSTNAME . . . . . . C Interface . . . . . . . . Description . . . . . . . . Return Value . . . . . . . Errors . . . . . . . . . . . MPE/iX Speci c . . . . . . Author . . . . . . . . . . Signals and Sockets . . . . . . What is a Signal? . . . . .
C Interface . Description . Return Value See Also . . . SELECT . . . C Interface . Description . Examples . . Example 1 . Example 2 . Return Value Errors . . . . Author . . . WRITE . . . . C Interface . Description . Return Value MPE/iX Speci See Also . . . . . . . . . . . . . . . . . . . . c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
MPE/iX Speci Author . . . Files . . . . See Also . . . GETSERVENT C Interface . Description . Restrictions . Return Value MPE/iX Speci Author . . . Files . . . . See Also . . . c . . . . . . . . c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Tables 1-1. Include Files Used for HP-UX and MPE/iX Applications . . . . . . . . . . . . . . .
1 Introduction References Used Several items referenced here are HP-UX man pages, listed in the format \name(#)", as per the UNIX convention. The number given indicates the chapter of the HP-UX man pages where that given page can be found.
Include Files Used The following table shows the include les used for HP-UX and MPE/iX applications. Table 1-1. Include Files Used for HP-UX and MPE/iX Applications HP-UX Name MPE/iX Name types.h.sys socket.h.sys un.h.sys le.h.sys errno.h.sys ioctl.h.sys in.h.sys tcp.h.sys unistd.h.sys fcntl.h.sys time.h.sys uio.h.sys netdb.h.
POSIX Function Support The following POSIX functions are supported as of MPE/iX release 4.5: * close() * dup() * exec() * fork() * read() * write() These functions are located in relocatable libraries available through the purchase of the MPE/iX Developer's Kit. For more information about these functions, refer to the MPE/iX Developer's Kit Reference Manual, Volume 1 .
2 Socket System Calls This section describes the socket system calls available on MPE/iX. Di erences from UNIX 4.3 BSD and limitations are noted.
SOCKET C Interface #include #include int socket(af, type, protocol) int af, type, protocol; Description The socket call creates an endpoint for communication and returns a descriptor. The socket descriptor returned is used in all subsequent socket-related system calls.he af parameter speci es an address family to be used to interpret addresses in later operations that specify the socket. These address families are de ned in the include le .
The communications protocol (TCP) used to implement SOCK_STREAM for AF_INET sockets, ensures that data is not lost or duplicated. If a peer has bu er space for data and the data cannot be successfully transmitted within a reasonable length of time, the connection is considered broken and the next recv call indicates an error with errno set to ETIMEDOUT. An end-of- le condition (zero bytes read) is returned if a process tries to read on a broken stream.
BIND C Interface AF_UNIX only: #include #include #include bind(s, addr, addrlen) int s; struct sockaddr_un *addr; int addrlen; AF_INET only: #include #include #include bind(s, addr, addrlen) int s; struct sockaddr_in *addr; int addrlen; Description 2-4 Socket System Calls The bind system call assigns an address to an unbound socket.
Here is the socket address structure for AF_INET, extracted from the IN.H.SYS le: struct in_addr { union { struct { u_char s_b1,s_b2,s_b3,s_b4; } s_un_b; struct { u_short s_w1,s_w2; } S_un_w; u_long S_addr; } S_un; #define s_addr S_un.S_addr /* can be used for most tcp & ip code */ #define s_host S_un.S_un_b.s_b2 /* host on imp */ #define s_net S_un.S_un_b.s_b1 /* network */ #define s_imp S_un.S_un_w.s_w2 /* imp */ #define s_impno S_un.S_un_b.s_b4 /* imp # */ #define s_lh S_un.S_un_b.
addr.sun_family = AF_UNIX; strcpy (addr.sun_path,"tmp/socket"); addrlen = 110; bind (s,addr, addrlen); } Return Value Errors 2-6 Socket System Calls If the bind is successful, a 0 value is returned. If it fails, -1 is returned, and an error code is stored in errno . The following errors are returned by bind: [EBADF] The argument s is not a valid descriptor. [ENOTSOCK] The argument s is not a socket. [EADDRNOTAVAIL] The speci ed address is bad or is not available from the local machine.
MPE/iX Specific On HP-UX, when binding an AF_UNIX socket to a path name (such as /tmp/mysocket), an open le having that name is created in the le system. When the bound socket is closed, that le still exists unless it is removed or unlinked. This does not occur on MPE/iX (that is, no le is created). On HP-UX, you are allowed to specify a speci c network while binding. MPE/iX does not. The IP address portion of sockaddr for AF_INET must be zero.
LISTEN C Interface Description listen(s, backlog) int s, backlog; To accept connections, a socket is rst created with socket, a queue for incoming connections is speci ed with listen, and then connections are accepted with accept. The listen call applies only to unconnected sockets of type SOCK_STREAM. Note that you cannot call listen after accept has been called.
MPE/iX Specific Author See Also The backlog limit on MPE/iX is 128 as opposed to the backlog limit of 20 on HP-UX. When an HP-UX socket has performed a listen, the incoming connection requests are completed as they are received (up to the backlog limit). When using MPE/iX, connections are completed by the call to accept.
ACCEPT C Interface AF_UNIX only: #include #include #include int ns; ns=accept(s, addr, addrlen) int s; struct sockaddr_un *addr; int *addrlen; AF_INET only: #include #include #include int ns; ns=accept(s, addr, addrlen) int s; struct sockaddr_in *addr; int *addrlen; Description This call is used with connection-based socket types, such as SOCK_STREAM .
contains the actual length (in bytes) of the address returned. If the memory pointed to by addr is not large enough to contain the entire address, only the rst addrlen bytes of the address are returned. AF_UNIX only: The addr parameter to accept() is ignored. Return Value Errors If the call is successful, a non-negative integer is returned, which is a descriptor for the accepted socket. If the call fails, a -1 is returned and an error code is stored in errno .
MPE/iX Specific Author See Also 2-12 Socket System Calls Connections are completely established in the accept call. The addr returned from accept when a connection is made in loopback is the loopback address (127.0.0.1). On HP-UX, the local host's IP address would be returned in this case.
CONNECT C Interface AF_UNIX sockets only: #include #include #include connect(s, addr, addrlen) int s; struct sockaddr_un *addr; int addrlen; AF_INET sockets only: #include #include #include connect(s, addr, addrlen) int s; struct sockaddr_in *addr; int addrlen; Description The parameter s is a socket descriptor. The addr parameter is a pointer to a socket address structure.
If the AF_INET socket does not already have a local address bound to it (refer to the bind call), the connect call also binds the socket to a local address chosen by the system. Stream sockets may successfully connect only once. Return Value Errors If the call is successful, a 0 is returned. If it fails, a -1 is returned, and an error code is stored in errno . The following errors are returned by connect: [EBADF] The argument s is not a valid le descriptor.
MPE/iX Specific Author See Also The connect call is not supported for SOCK_DGRAM sockets on the current release.
SOCKETPAIR C Interface #include #include socketpair(d, type, protocol, sv) int d, type, protocol; int sv[2]; Description The socketpair call creates an unnamed pair of connected sockets in the speci ed domain d , of the speci ed type , and using the optionally speci ed protocol . The descriptors used in referencing the new sockets are returned in sv[0] and sv[1] . The two sockets are indistinguishable. This intrinsic is implemented for AF_UNIX sockets only.
SEND C Interface #include #include send(s, msg, len, flags) int s; char *msg; int len, flags; sendmsg(s, msg, flags) int s; struct msghdr msg[]; int flags; AF_UNIX only: #include #include #include sendto(s, msg, len, flags, to, tolen) int s; char *msg; int len, flags; struct sockaddr_un *to; int tolen; AF_INET only: #include #include #include
Description The send, sendto, and sendmsg calls are used to transmit a message to another socket. The argument s is a socket descriptor that speci es the socket on which the message is sent. The msg parameter points to the bu er that contains the message. If the socket uses connection-based communications (for example, a SOCK_STREAM socket), then these calls can be used only after the connection has been established. (Refer to connect.) In this case, any destination speci ed by the to parameter is ignored.
If there is no space in the system to bu er any of the data, the send completes successfully, having written no data, and returns a -1 with errno set to EAGAIN. If O_NDELAY is set using fcntl (de ned in and explained in the fcntl section), non-blocking I/O is enabled.
[EMSGSIZE] [EWOULDBLOCK] [ENOBUFS] [EINVAL] [EDESTADDRREQ] [ENOTCONN] [EAFNOSUPPORT] [EPIPE] [EOPNOTSUPP] [EINTR] MPE/iX Specific The socket requires that messages be sent atomically, and the size of the message to be sent made this impossible. The socket is in non-blocking mode, and the requested operation would block. Insu cient resources were available in the system to perform the operation. The len or tolen parameter contains a bad value.
RECV C Interface #include #include recv(s, buf, len, flags) int s; char *buf; int len, flags; recvmsg(s, msg, flags) int s; struct msghdr msg[]; int flags; AF_UNIX only: #include #include #include recvfrom(s, buf, len, flags, from, fromlen) int s; char *buf; int len, flags; struct sockaddr_un *from; int *fromlen; AF_INET only: #include #include #include
Description The recv, recvfrom, and recvmsg calls are used to receive messages from a socket. The argument s is a socket descriptor from which the message is received. The buf parameter is a pointer to the bu er into which the messages are placed. The len parameter is the maximum number of bytes that will t into the bu er referenced by buf . If the socket uses connection-based communications (for example, a SOCK_STREAM socket), then these calls can be used only after the connection has been established.
If O_NDELAY is set using sfcntl (de ned in and explained in the fcntl section), non-blocking I/O is enabled. In this case, the recv request completes in one of three ways: If there is enough data available to satisfy the entire request, recv completes successfully, having read all of the data, and returns the number of bytes read.
Return Value Errors MPE/iX Specific If the call is successful, it returns the number of bytes received. If the call fails, a -1 is returned, and an error code is stored in errno . A zero is returned if the socket is blocking and the transport connection to the remote node fails. The following errors are returned by recv, recvfrom, or recvmsg: [EBADF] The argument s is an invalid descriptor. [ENOTSOCK] The argument s is not a socket.
SHUTDOWN C Interface Description shutdown(s, how) int s, how; The shutdown system call is used to shut down a socket. The s parameter is the socket descriptor of the socket to be shut down. In the case of a full-duplex connection, shutdown can be used to either partially or fully shut down the socket, depending on the value of how . If how=0 , the socket can still send data, but it cannot receive data.
Return Value Errors Author See Also 2-26 Socket System Calls If the call is successful, a 0 is returned. If it fails, a -1 is returned, and an error code is stored in errno . The following errors are returned by shutdown: [EBADF] The arguments is not a valid descriptor. [ENOTSOCK] The arguments is a le, not a socket. [EINVAL] The speci ed socket is not connected.
GETSOCKOPT, SETSOCKOPT C Interface #include int getsockopt( int s, int level, int optname, void *optval, int *optlen); int setsockopt( int s, int level, int optname, const void *optval, int optlen); Description getsockopt and setsockopt manipulate options associated with a socket. The socket is identi ed by the socket descriptor s . Options can exist at multiple protocol levels. Options are described below under the appropriate option.
the maximum number of bytes of option information to be passed. If optval is not (char *) NULL, optlen is set on return to the actual number of bytes of option information passed. If the getsockopt call fails, no option information is passed. optname and any speci ed options are passed uninterpreted to the appropriate protocol module for interpretation. The include le contains de nitions for \socket" level options. Options at other protocol levels vary in format and name.
blocks the process on the close attempt until it is able to transmit the data or until it decides it is unable to deliver the information. If SO_LINGER is toggled on with a linger interval of zero, the connection is immediately terminated on the close of the socket, and any unsent data queued on the connection is lost. If SO_LINGER is toggled o (default upon socket creation) and a close is issued, the call returns immediately.
[EINVAL] [EFAULT] [ESOCKTNOSUPPORT] Author See Also 2-30 Socket System Calls The option is unknown at the socket level or the socket has been shut down. The optval or, in the case of getsockopt, optlen parameters are not valid pointers. The socket is a NetIPC socket.
GETPEERNAME C Interface #include #include #include getpeername(s, addr, addrlen) int s; struct sockaddr_in *addr; int *addrlen; Description S is a socket descriptor. The getpeername system call returns the address of the peer socket connected to the socket indicated by s . The addr parameter points to a socket address structure in which this address is returned.
GETSOCKNAME C Interface #include #include #include getsockname(s, addr, addrlen) int s; struct sockaddr_in *addr; int *addrlen; Description The argument s is a socket descriptor. The getsockname system call returns the address of the socket indicated by s . The addr parameter points to a socket address structure in which this address is returned.
GETHOSTNAME C Interface #include int gethostname(hostname, size); char *hostname; size_t size; Description Return Value Errors MPE/iX Specific Author The gethostname system call returns the standard host name for the current processor as set by sethostname. The size parameter speci es the length of the hostname array. The hostname is null-terminated unless insu cient space is provided. If the call is successful, a 0 is returned.
For the purposes of illustration, we will use the signal() system call, which is the simplest of the system calls dealing with sockets, to describe signal handling. There are several default actions possible that may be performed upon receipt of a signal. Some of them are: ignore the signal, terminate the process, suspend (stop) the process, and resume (continue) the process. Of the signals generated by sockets, only the ignore and terminate defaults are available.
sets the target process group. A target process group is either a process (speci ed by a positive process id) or a process group (speci ed by a negative process id). A SIGIO signal is generated whenever new IO can complete on a socket. Examples of when a SIGIO signal is generated are when new data arrives at the socket, when data can again be sent on the socket, when the socket is either partially or completely shutdown or when a listen socket has a connection request posted on it.
3 File System Intrinsics Unix 4.3 BSD provides an interface to make IPC similar to le I/O. You can open, read, write, or close a le that is type socket.
CLOSE, SCLOSE This routine is called sclose for non-POSIX users, and is called close for POSIX users. Note C Interface int close (s) int s; int sclose (s) int s; Description Closes the socket descriptor indicated by s . If this le descriptor is the last reference to the socket, then it is deactivated. For example, on the last close of a socket, associated naming information and queued data are discarded.
DUP int dup (s) int s; C Interface Description This function returns a socket descriptor that refers to the same socket as speci ed by s . Both descriptors can be used to reference the socket. The new socket descriptor is the lowest numbered available socket descriptor. For more information about dup or any other POSIX function, refer to the MPE/iX Developer's Kit Reference Manual, Volume 1 .
FCNTL, SFCNTL Only sfcntl is currently available. Note C Interface #include #include #include int sfcntl (s, cmd, arg) int s, cmd, arg; Description The sfcntl routine provides control over open sockets. The s parameter is an open socket. The following are possible values of the arg parameter. They are also referred to as le status ags. O NDELAY Non-blocking I/O. O NONBLOCK POSIX-style non-blocking I/O.
MPE/iX Specific Author See Also The sfcntl call is used instead of fcntl on MPE/iX. The fcntl intrinsic was developed by Hewlett-Packard, AT&T, and the University of California, Berkeley.
IOCTL C Interface #include int ioctl (s, request, arg) int s; int request; void *arg; Description The ioctl function provides an interface for setting di erent characteristics for a socket, and retrieving information on a socket. The parameter s is a socket descriptor. The request parameter speci es which command to perform on the socket. The commands are de ned in . The di erent commands that are available are described below.
If there is not enough data available to satisfy the entire request, the read completes successfully, having read as much data as possible, and returns the number of bytes it was able to read; If there is no data available, the read fails and errno is set to EWOULDBLOCK. For writes, non-blocking I/O prevents all write requests to that socket from blocking, whether the requests succeed or fail.
SIOCSPGRP SIOCGPGRP FIOASYNC sockets other than SOCK STREAM TCP sockets, on return the integer with the address arg is always zero. This request sets the process group or process ID associated with the socket to be the value of the integer with the address arg . A process group or process ID associated with the socket in this manner is signaled when the state of the socket changes: SIGIO is delivered if the socket is asynchronous, as described in FIOASYNC below.
or O NDELAY ag has been set, recv and send requests behave accordingly, regardless of any FIOSNBIO requests. If neither the O NONBLOCK ag nor the O NDELAY ag has been set, FIOSNBIO requests control of the behavior of recv and send. Return Value Errors MPE/iX Specific Author See Also If the call is successful, a 0 is returned. If an error has occurred, a value of -1 is returned and errno is set to indicate the error.
READ int read (s, buf, len) int s; char *buf; int len; C Interface Description The read function is similar to the recv call except there is no ags parameter. It behaves the same way as a recv call with ags set to zero. For more information about read or any other POSIX function, refer to the MPE/iX Developer's Kit Reference Manual, Volume 1 . Return Value See Also 3-10 File System Intrinsics If the call is successful, it returns the number of bytes received.
SELECT C Interface #include int select(nfds, readfds, writefds, exceptfds,timeout) int nfds, *readfds, *writefds, *exceptfds; struc timeval *timeout; Description The select intrinsic examines the le descriptors speci ed by the bit masks readfds , writefds , and exceptfds . The bits from 0 through nfds -1 are examined. File descriptor f is represented by the bit 1
#define MASK(f) (1 << (f)) #define NSDS 4int sd[NSDS]; int sdmask[NSDS]; int readmask = 0; int readfds; int nfound, i; struct timeval timeout; /* First open each socket for reading and put the */ /* file descriptors into array sd[NSDS]. The code */ /* for opening the sockets is not shown here. */ for (i=0; i < NSDS; i++) { sdmask[i] = MASK(sd[i]); readmask |= sdmask[i]; } timeout.tv_sec = 5; timeout.
#include #include #include #include #define TRUE 0 #define FALSE 1 main () { int maxfds; int sock, sock2, peer1; int struc_len; int fret; int done = FALSE; char data[256]; char data_to_send = 'D'; char *datptr; int dlen; int readfds; int writefds; struc timeval timeout; struc sockaddr_in sockaddr; sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP; peer1 = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); sockaddr.sin_family = AF_INET; sockaddr.sin_addr.
/* sock2 and peer1 are now connected */ daptr = data; done = FALSE; while (done == FALSE) { /* */ /* */ /* /* /* This code example shows how to use select() to wait on multiple sockets. Note that first you have to find the maximum descriptor number being used. The appropriate bit(s) must be set for the */ select masks and then they must be checked after the call. In */ this example, sock2 is waiting to receive data from peer1.
{ printf ("error3\n"); } } } };/* end else */ };/* end while */ Return Value Errors The select intrinsic returns the number of descriptors contained in the bit masks. If an error occurs, -1 is returned and an error code is stored in errno . If the time limit expires, then select returns 0, and all of the masks are cleared. The select intrinsic returns the following errors: [EBADF] One or more of the bit masks speci ed an invalid descriptor. [EFAULT] One or more of the pointers was invalid.
WRITE int write (s, msg, len); int s; char *msg; int len C Interface Description The write function is similar to the send call except there is no ags parameter. It behaves the same way as a send call with ags set to zero. For more information about write or any other POSIX function, refer to the MPE/iX Developer's Kit Reference Manual, Volume 1 . Return Value MPE/iX Specific See Also 3-16 File System Intrinsics If successful, the call returns the number of characters sent.
4 Name Service Routines This section describes several library routines that can best be described as name service routines, since they return information based on names, addresses, and numbers.
INET ADDR, INET NETWORK, INET NTOA C Interface #include #include #include unsigned long inet_addr(cp); const char *cp; unsigned long inet_network(cp); const char *cp; char *inet_ntoa(in); struc in_addr in; Description The routines inet_addr and inet_network each interpret character strings representing numbers expressed in the internet standard \dot" notation, returning numbers suitable for use as internet addresses and internet network numbers, respectively.
format convenient for specifying Class B network addresses as in 128.net.host. When a two-part address is supplied, the last part is interpreted as a 24-bit quantity and placed in the right-most three bytes of the network address. This makes the two-part address format convenient for specifying Class A network addresses as in net.host. 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 dot (.
GETHOSTENT C Interface #include #include #include #include extern int h_errno; struct hostent *gethostent() struct hostent *gethostbyname(name) char *name; struct hostent *gethostbyaddr(addr, len, type) char *addr; int len, type; sethostent(stayopen) int stayopen; endhostent() Description The gethostent, gethostbyname, and gethostbyaddr subroutines return a pointer to a structure de ned as follows in netdb.
h addr The rst address in h addr list; this is for compatibility with previous HP-UX implementations, where a struct hostent contains only one network address per host. If the local system is con gured to use the name server, then: The gethostent subroutine always returns a null pointer. The sethostent subroutine, if the stayopen ag is non-zero, requests the use of a connected stream socket for queries to the name server. The connection is retained after each call to gethostbyname or gethostbyaddr.
The parameter len must be the number of bytes in an Internet address, that is, sizeof (struct in addr ). The parameter type must be the constant AF_INET. Return Value If successful, gethostbyname, gethostbyaddr, and gethostent return a pointer to the requested hostent struct. The gethostbyname and gethostbyaddr subroutines return NULL if their host or addr parameters, respectively, cannot be found in the database. If hosts.net.sys is being used, they also return NULL if they are unable to open hosts.net.
GETNETENT C Interface #include #include #include struct netent *getnetent() struct netent *getnetbyname(name) char *name; struct netent *getnetbyaddr(net, type) long net; int type; setnetent(stayopen) int stayopen; endnetent() Description The getnetent, getnetbyname , and getnetbyaddr subroutines each return a pointer to an object with the following structure. This structure contains elds found in the network protocol database, /etc/networks .
The endnetent subroutine closes the le. The getnetbyname subroutine sequentially searches from the beginning of the le until a network name (among either the o cial names or the aliases) matching its parameter name is found, or until EOF is encountered. The getnetbyaddr subroutine sequentially searches from the beginning of the le until a network number matching its parameter net is found, or until EOF is encountered. The parameter net must be in network order.
GETPROTOENT C Interface #include struct protoent *getprotoent() struct protoent *getprotobyname(name) char *name; struct protoent *getprotobynumber(proto) int proto; setprotoent(stayopen) int stayopen; endprotoent() Description The getprotoent, getprotobyname, and getprotobynumber subroutines each return a pointer to an object with the following structure. This structure contains elds found in the network protocol database, /etc/protocols.
Restrictions Return Value MPE/iX Specific Author Files See Also 4-10 Name Service Routines All information is contained in a static area, so it must be copied if it is to be saved. Only the Internet protocols are currently understood. The getprotoent, getprotobyname, and getprotobynumber subroutines return a null pointer (0) on EOF or when they are unable to open PROTOCOL.NET.SYS. The name of the protocols le on MPE/iX is PROTOCOL.NET.SYS, as opposed to /etc/protocols on HP-UX.
GETSERVENT C Interface #include struct servent *getservent() struct servent *getservbyname(name, proto) char *name, *proto; struct servent *getservbyport(port, proto) int port; char *proto; setservent(stayopen) int stayopen; endservent() Description The getservent, getservbyname , and getservbyport subroutines each return a pointer to an object with the following structure containing the broken-out elds of a line in the network services database, /etc/services.
The getservbyname and getservbyport subroutines sequentially search from the beginning of the le until a service name (among either the o cial names or the aliases) matching the parameter name or a port number matching the parameter port is found, or until EOF is encountered. If a non-NULL protocol name is also supplied (for example, tcp or udp), searches must also match the protocol.
5 Programming Example This section contains an example source program, describes how it was compiled and linked, and lists the output generated from it. Source Program The following program was broken into steps to show how a connection is established between two sockets. 1. Establish the connection in loopback, using a single process: #include #include #include #include #include #include #include #include
sockaddr.sin_port = 4444; struc_len = 16; if (bind (sock, (struct sockaddr *) &sockaddr, sizeof (sockaddr)) < 0 ) printf ("Bind failed\n); listen (sock,10); 4. Set the socket initiating the connection to be nonblocking. This allows the connect to return to the user without blocking and waiting for accept: The sfcntl function should be used until the fcntl is provided by the operating system.
Linking The following example shows how to link the program: :link from=obj;rl=^rllist;to=prog The following RLLIST le was used in linking the above program: socketrl.net.sys libcinit.lib.sys Note: Ensure that you link with the POSIX library (/lib/libc.a) instead of libcinit.lib.sys for POSIX programs. If you are using fork(), you need to link with PH capabilities.