TCP/IP Programming Manual
#include <netdb.h>
...
struct sockaddr_in6 sin;
...
/* The code here (not shown) should create a socket fd.
* Then the local address and port number
* in the sin structure are set up. The port number is passed
* as an argument when the program is run.
*/
sin.sin6_family = AF_INET6;
sin.sin6_addr = in6addr_any;
sin.sin6_port = port;
/* Notice that sin is cast as sockaddr as suggested in the Usage Guidelines */
if (bind (fd, (struct sockaddr *)&sin, sizeof (sin)) < 0) {
perror ("SERVER: Bind failed.");
exit (1);
}
/* Bind call succeeded. /*
connect, connect_nw
The connect and connect_nw functions connect the specified socket to a remote socket.
For TCP, these functions request an active connection. For UDP or IP, they permanently specify the
destination address for the socket.
C Synopsis
#include <socket.h>
#include <in.h>
#include <in6.h> /* for IPv6 use */
#include <netdb.h>
error = connect (socket, address_ptr, address_len);
error = connect_nw (socket, address_ptr, address_len, tag);
int error, socket;
struct sockaddr *address_ptr;
int address_len;
long tag;
TAL Synopsis
?NOLIST, SOURCE SOCKDEFT
?NOLIST, SOURCE SOCKPROC
error := connect (socket, address_ptr, address_len);
error := connect_nw (socket, address_ptr, address_len, tag);
INT(32) error;
INT(32) socket;
INT .EXT address_ptr (sockaddr_in);
INT(32) address_len;
INT(32) tag;
error
return value; if the call is successful, a zero is returned. If the call is not successful, —1 is
returned. If the call failed, the external variable errno is set as indicated in Errors (page 103).
Refer to Appendix B (page 243), for more details.
102 Library Routines