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

# socket\_bind6(3)

set the local IP address and port of a socket

## NAME

socket\_bind6 - set the local IP address and port of a socket

## SYNTAX

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

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

## DESCRIPTION

socket\_bind6 sets the local IP address and TCP/UDP port of a TCP/UDP socket *s* to *ip* and *port* respectively.

If the IP address is ::, the operating system chooses a local IP address.  If *port* is 0, the operating system chooses a port.

Normally socket\_bind6 returns 0. If anything goes wrong, socket\_bind6 returns -1, setting errno appropriately.

The *scope\_id* should normally be zero, but for link-local addresses it specifies the interface number on which to bind.  The interface number for a given network interface name can be found with **socket\_getifidx**.

## EXAMPLE

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

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

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

## SEE ALSO

[socket\_bind4(3)](/socket_bind4/3.md), [socket\_getifidx(3)](/socket_getifidx/3.md)
