]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/net/sockatmark.3
libc: only export hesiod symbols when enabled
[FreeBSD/FreeBSD.git] / lib / libc / net / sockatmark.3
1 .\" Copyright (c) 2002 William C. Fenner.  All rights reserved.
2 .\"
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
5 .\" are met:
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\"    notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\"    notice, this list of conditions and the following disclaimer in the
10 .\"    documentation and/or other materials provided with the distribution.
11 .\"
12 .\" THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
13 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
16 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22 .\" SUCH DAMAGE.
23 .\"
24 .Dd July 3, 2022
25 .Dt SOCKATMARK 3
26 .Os
27 .Sh NAME
28 .Nm sockatmark
29 .Nd determine whether the read pointer is at the OOB mark
30 .Sh LIBRARY
31 .Lb libc
32 .Sh SYNOPSIS
33 .In sys/socket.h
34 .Ft int
35 .Fn sockatmark "int s"
36 .Sh DESCRIPTION
37 To find out if the read pointer is currently pointing at
38 the mark in the data stream, the
39 .Fn sockatmark
40 function is provided.
41 If
42 .Fn sockatmark
43 returns 1, the next read will return data
44 after the mark.
45 Otherwise (assuming out of band data has arrived),
46 the next read will provide data sent by the client prior
47 to transmission of the out of band signal.
48 The routine used
49 in the remote login process to flush output on receipt of an
50 interrupt or quit signal is shown below.
51 It reads the normal data up to the mark (to discard it),
52 then reads the out-of-band byte.
53 .Bd -literal -offset indent
54 #include <sys/socket.h>
55 \&...
56 oob()
57 {
58         int out = FWRITE, mark;
59         char waste[BUFSIZ];
60
61         /* flush local terminal output */
62         ioctl(1, TIOCFLUSH, (char *)&out);
63         for (;;) {
64                 if ((mark = sockatmark(rem)) < 0) {
65                         perror("sockatmark");
66                         break;
67                 }
68                 if (mark)
69                         break;
70                 (void) read(rem, waste, sizeof (waste));
71         }
72         if (recv(rem, &mark, 1, MSG_OOB) < 0) {
73                 perror("recv");
74                 ...
75         }
76         ...
77 }
78 .Ed
79 .Sh RETURN VALUES
80 Upon successful completion, the
81 .Fn sockatmark
82 function returns the value 1 if the read pointer is pointing at
83 the OOB mark, 0 if it is not.
84 Otherwise the value \-1 is returned
85 and the global variable
86 .Va errno
87 is set to
88 indicate the error.
89 .Sh ERRORS
90 The
91 .Fn sockatmark
92 call fails if:
93 .Bl -tag -width Er
94 .It Bq Er EBADF
95 The
96 .Fa s
97 argument
98 is not a valid descriptor.
99 .It Bq Er ENOTTY
100 The
101 .Fa s
102 argument
103 is a descriptor for a file, not a socket.
104 .El
105 .Sh SEE ALSO
106 .Xr recv 2 ,
107 .Xr send 2
108 .Rs
109 .%T "An Introductory 4.4BSD Interprocess Communication Tutorial"
110 .%A Stuart Sechrest
111 .Re
112 .%U https://docs.freebsd.org/44doc/psd/20.ipctut/paper.pdf
113 .Rs
114 .%T "An Advanced 4.4BSD Interprocess Communication Tutorial"
115 .%A Samuel J. Leffler
116 .%A Robert S. Fabry
117 .%A William N. Joy
118 .%A Phil Lapsley
119 .%A Steve Miller
120 .%A Chris Torek
121 .%U https://docs.freebsd.org/44doc/psd/21.ipc/paper.pdf
122 .Re
123 .Sh HISTORY
124 The
125 .Fn sockatmark
126 function was introduced by
127 .St -p1003.1-2001 ,
128 to standardize the historical
129 .Dv SIOCATMARK
130 .Xr ioctl 2 .
131 The
132 .Er ENOTTY
133 error instead of the usual
134 .Er ENOTSOCK
135 is to match the historical behavior of
136 .Dv SIOCATMARK .