12.07.2015 Views

z/VM: TCP/IP Programmer's Reference - z/VM - IBM

z/VM: TCP/IP Programmer's Reference - z/VM - IBM

z/VM: TCP/IP Programmer's Reference - z/VM - IBM

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

connect()#include #include int connect(s, name, namelen)int s;struct sockaddr *name;int namelen;ParametersnamenamelenDescriptionSpecifies the socket descriptor.Points to a socket address structure containing the address of thesocket to which a connection is attempted.Specifies the size of the socket address pointed to by name in bytes.Description: For stream sockets, the connect() call attempts to establish aconnection between two sockets. For UDP sockets, the connect() call specifies thepeer for a socket. The s parameter is the socket used to originate the connectionrequest. The connect() call performs two tasks when called for a stream socket.First, it completes the binding necessary for a stream socket (in case it has not beenpreviously bound using the bind() call). Second, it attempts to make a connectionto another socket.The connect() call on a stream socket is used by the client application to establish aconnection to a server. The server must have a passive open pending. If the serveris using sockets, this means the server must successfully call bind() and listen()before a connection can be accepted by the server with accept(). Otherwise,connect() returns −1 and errno is set to ECONNREFUSED.If s is in blocking mode, the connect() call blocks the caller until the connection isset up, or until an error is received. If the socket is in nonblocking mode thenconnect() returns −1 with errno set to EINPROGRESS if the connection can beinitiated (no other errors occurred). The caller can test the completion of theconnection setup by calling select() and testing for the ability to write to the socket.When called for a datagram or raw socket, connect() specifies the peer with whichthis socket is associated. This gives the application the ability to use data transfercalls reserved for sockets that are in the connected state. In this case, read(), write(),readv(), writev(), send(), recv() are then available in addition to sendto(),recvfrom(), sendmsg(), recvmsg(). Stream sockets can call connect() only once,however, datagram sockets can call connect() multiple times to change theirassociation. Datagram sockets can dissolve their association by connecting to aninvalid address such as the NULL address (all fields zeroed).The name parameter is a pointer to a buffer containing the name of the peer towhich the application needs to connect. The namelen parameter is the size, in bytes,of the buffer pointed to by name.Servers in the AF_INET Domain: If the server is in the AF_INET domain, theformat of the name buffer is expected to be sockaddr_in, as defined in the headerfile IN.H.struct in_addr{unsigned long s_addr;};struct sockaddr_in{28 z/<strong>VM</strong>: <strong>TCP</strong>/<strong>IP</strong> Programmer’s <strong>Reference</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!