---
name: "socket_connect6"
section: "3"
platform: "linux"
package: "libowfat-dev"
version: "0.32-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/socket_connect6"
---

# socket\_connect6(3)

attempt to make a TCP connection

## NAME

socket\_connect6 - attempt to make a TCP connection

## SYNTAX

**#include \<libowfat/socket.h\>**

int **socket\_connect6**(int *s*, const char *ip*\[16\],\
                     uint16 *port*,uint32 *scope\_id*);

## DESCRIPTION

socket\_connect6 attempts to make a connection from TCP socket *s* to TCP port *port* on IP address *ip*.

The meaning of *scope\_id* is dependent on the implementation and IPv6 IP.  On link-local IPv6 addresses it specifies the outgoing interface index.  The name (e.g. "eth0") for a given interface index can be queried with getifname.  *scope\_id* should normally be set to 0.

socket\_connect6 may return

- •

  0, to indicate that the connection succeeded (and succeeded immediately, if the socket is non-blocking)

- •

  \-1, setting errno to error\_inprogress or error\_wouldblock, to indicate that the socket is non-blocking

- •

  \-1, setting errno to something else, to indicate that the connection failed (and failed immediately, if the socket is non-blocking).

When a background connection succeeds or fails, *s* becomes writable; you can use socket\_connected to see whether the connection succeeded.  If the connection failed, socket\_connected returns 0, setting errno appropriately.

Once a TCP socket is connected, you can use the read and write system calls to transmit data.

You can call socket\_connect6 without calling socket\_bind6.  This has the effect as first calling socket\_bind6 with IP address :: and port 0.

## EXAMPLE

  \#include \<libowfat/socket.h\>

  int *s*;\
   char *ip*\[16\];\
   uint16 *p*;

  *s* = socket\_tcp6();\
   socket\_bind6(s,ip,p);\
   socket\_connect6(s,ip,p,0);

## SEE ALSO

[socket\_connect4(3)](/socket_connect4/3.md), [socket\_fastopen\_connect6(3)](/socket_fastopen_connect6/3.md), [socket\_getifname(3)](/socket_getifname/3.md)
