qlibs:

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

NAME

socket_setup - listen to or accept socket for incoming TCP connections  

SYNTAX

#include "socket_if.h"

int socket_listen(int s,int n);

int socket_accept(int s,char ip[16],
                  uint16 *port,uint32 *scope_id);
                  int socket_ipoptionskill(int s);

int socket_ip6anycast((int s);

int socket_dualstack(int s);

int socket_nodualstack(int s);  

DESCRIPTION

socket_listen prepares TCP socket s to accept TCP connections. It allows a backlog of approximately n TCP SYNs. (On systems supporting SYN cookies, the backlog is irrelevant.)

socket_accept accepts the connection. It creates a new socket for the connection and returns a file descriptor pointing to the new socket; you can use the read and write system calls to transmit data through that file descriptor. Further, it provides information about client's ip address and TCP port number perhaps together with local receiving interface scope_id.

socket_ipoptionskill is used to disable previously defined options in IPv4 or IPv6 packets like Source Routing prior of using this socket for data exchange. socket_ipoptionskill uses the setsockopt.

socket_ip6anycast enables unspecified reversed anycasting on the listening socket s with IPv6 address ::. Upon receiving IPv6 packets, the socket records the incoming IPv6 address and the receiving scope_id in order provide additional routing information.

socket_dualstack and socket_nodualstack can be used to force or forbid dual-stack behavior setting the setsockopt variable IPV6_V6ONLY appropriately. In the last case, a potential servers needs two instances to accept incoming IPv6 and IPv6 packets.  

RETURN CODES

Normally socket_listen, socket_accept and socket_ipotionskill as well as socket_dualstack and socket_nodualstack return 0 and if anything goes wrong it returns -1, setting errno appropriately.  

EXAMPLE


  #include <socket_if.h>


  int st
  int r;
  char ip[16];
  uint16 p;


  if ((s = socket_tcp()) == -1)
    err_tmp("",111,"unable to create TCP socket: ");
  r = socket_ipoptionskill(s);
  if (socket_bind_reuse(s,(char *)V6localnet,8002,0) == -1)
    err_tmp("",111,"unable to bind: ");
  if (socket_listen(s,1) == -1)
    err_tmp("",111,"unable to listen: ");
    
  t = socket_tcp();
  socket_bind(t,ip,p,0);
  socket_listen(s,16);
  socket_accept(t,ip,&p,&scope_id);    

SEE ALSO

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


 

Index

NAME
SYNTAX
DESCRIPTION
RETURN CODES
EXAMPLE
SEE ALSO

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