summaryrefslogtreecommitdiff
path: root/man/socket_setup.3
blob: 639b28bce98f0097915e4f87b0be7e42b3e78356 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
.TH qlibs: socket_setup 3
.SH NAME
socket_setup \- listen to or accept socket for incoming TCP connections
.SH SYNTAX
.B #include \(dqsocket_if.h\(dq

int \fBsocket_listen\fP(int \fIs\fR,int \fIn\fR);

int \fBsocket_accept\fP(int \fIs\fR,char \fIip\fR[16],
                  uint16 *\fIport\fR,uint32 *\fIscope_id\fR);
                 
int \fBsocket_ipoptionskill\fR(int \fIs\fR);

int \fBsocket_ip6anycast(\fR(int \fIs\fR);

int \fBsocket_dualstack\fR(int \fIs\fR);

int \fBsocket_nodualstack\fR(int \fIs\fR);
.SH DESCRIPTION
.B socket_listen 
prepares TCP socket \fIs\fR to accept TCP connections.  
It allows a backlog of approximately \fIn\fR TCP SYNs. 
(On systems supporting SYN cookies, the backlog is irrelevant.) 

.B 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 
\fIip\fR address and TCP \fIport\fR number
perhaps together with local receiving interface \fIscope_id\fR. 

.B 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.
.B socket_ipoptionskill
uses the 
.BR setsockopt .

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

.B socket_dualstack
and
.B socket_nodualstack
can be used to force or forbid dual-stack behavior
setting the 
.B setsockopt 
variable
.I IPV6_V6ONLY 
appropriately. In the last case, a potential servers
needs two instances to accept incoming IPv6 and IPv6 packets.
.SH "RETURN CODES"
Normally
.BR socket_listen ,
.B socket_accept 
and
.B socket_ipotionskill 
as well as 
.B socket_dualstack
and
.B socket_nodualstack
return
.I 0 
and if anything goes wrong it returns 
.IR -1 , 
setting 
.I errno
appropriately.
.SH EXAMPLE
  #include <socket_if.h>

  int \fIs\fR, \fIt\fR; 
  int \fIr\fR;
  char \fIip\fR[16];
  uint16 \fIp\fR;

  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);  
.SH "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)