qlibs:

Section: Misc. Reference Manual Pages (socket_bind)
Updated: 3
Index Return to Main Contents
 

NAME

socket_bind - binding a TCP/UDP socket to a local IP address, port, and perhaps scope_id  

SYNTAX

#include "socket_if.h"

int socket_bind4(int s,char ip[4],uint16 port);
int socket_bind4_reuse(int s,char ip[4],uint16 port);

int socket_bind6(int s,char ip[16],uint16 port,uint32 scope_id);
int socket_bind6_reuse(int s,char ip[16],uint16 port,uint32 scope_id);
                        int socket_bind(int s,char ip[16],uint16 port,uint32 scope_id);
int socket_bind_reuse(int s,char ip[16],uint16 port,uint32 scope_id);  

DESCRIPTION

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

socket_bind4_reuse sets the local IP address and TCP/UDP port of a TCP/UDP socket s to ip and port respectively. Unlike socket_bind4, this function will also tell the operating system that the address is to be reused soon, which turns off the normal pause before this IP and port can be bound again.

socket_bind6 sets the local IP address and TCP/UDP port of a TCP/UDP socket s to ip, port and scope_id respectively.

socket_bind6_reuse sets the local IP address and TCP/UDP port of a TCP/UDP socket s to ip, port and scope_id respectively. Unlike socket_bind6, this function will also tell the operating system that the address is to be reused soon, which turns off the normal pause before this IP and port can be bound again.

socket_bind sets the local IPv4/IPv6 address and TCP/UDP port of a TCP/UDP socket s to ip, port, and scope_id respectively.

For IPv4 and IPv4-mapped IPv6 addresses socket_bind will use socket_bind4 or otherwise socket_bind6.

socket_bind_reuse sets the local IPv4/IPv6 address and TCP/UDP port of a TCP/UDP socket s to ip, port, and scope_id respectively. Unlike socket_bind, this function will also tell the operating system that the address is to be reused soon, which turns off the normal pause before this IP and port can be bound again.

For IPv4 and IPv4-mapped IPv6 addresses socket_bind_reuse will use socket_bind4_reuse or otherwise socket_bind6_reuse.  

AUTOMATIC BINDING

If the IPv4 address is 0 or the IPv6 address is ::, the operating system chooses a local IP address. If port is 0, the operating system chooses a port. scope_id is usually 0, except for IPv6 LLU addresses where socket_getifidx can be used to determine scope_id from the interface name.  

RETURN CODES

Normally, all socket_bind* routines return 0. If anything goes wrong, the return code is -1 and setting errno appropriately.  

EXAMPLE


  #include <socket_if.h>
  #include <ip.h>


  int s;
  char lcoalip[16];
  char remoteip[16];
  uint16 p = 0;
  uint32 scope_id = 0;


  if (ip6_isv4mapped(ip))
    s = socket_tcp4();
  else
    s = socket_tcp6();
  if (s == -1)
    err_tmp(111,"unable to create TCP socket: ");


  socket_connect(s,remoteip,p,scope_id);  

SEE ALSO

socket_if(3), socket_connect(3), socket_info(3), socket_recv(3), socket_send(3), socket_setup(3), socket_tcp(3), socket_udp(3)


 

Index

NAME
SYNTAX
DESCRIPTION
AUTOMATIC BINDING
RETURN CODES
EXAMPLE
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 14:55:39 GMT, December 15, 2024