xref: /dflybsd-src/lib/libc/net/sockatmark.3 (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino.\" Copyright (c) 2002 William C. Fenner.  All rights reserved.
286d7f5d3SJohn Marino.\"
386d7f5d3SJohn Marino.\" Redistribution and use in source and binary forms, with or without
486d7f5d3SJohn Marino.\" modification, are permitted provided that the following conditions
586d7f5d3SJohn Marino.\" are met:
686d7f5d3SJohn Marino.\" 1. Redistributions of source code must retain the above copyright
786d7f5d3SJohn Marino.\"    notice, this list of conditions and the following disclaimer.
886d7f5d3SJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright
986d7f5d3SJohn Marino.\"    notice, this list of conditions and the following disclaimer in the
1086d7f5d3SJohn Marino.\"    documentation and/or other materials provided with the distribution.
1186d7f5d3SJohn Marino.\"
1286d7f5d3SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
1386d7f5d3SJohn Marino.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1486d7f5d3SJohn Marino.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1586d7f5d3SJohn Marino.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1686d7f5d3SJohn Marino.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1786d7f5d3SJohn Marino.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1886d7f5d3SJohn Marino.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1986d7f5d3SJohn Marino.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2086d7f5d3SJohn Marino.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2186d7f5d3SJohn Marino.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2286d7f5d3SJohn Marino.\" SUCH DAMAGE.
2386d7f5d3SJohn Marino.\"
2486d7f5d3SJohn Marino.\" $FreeBSD: src/lib/libc/net/sockatmark.3,v 1.4 2002/12/19 09:40:22 ru Exp $
2586d7f5d3SJohn Marino.\"
2686d7f5d3SJohn Marino.Dd October 13, 2002
2786d7f5d3SJohn Marino.Dt SOCKATMARK 3
2886d7f5d3SJohn Marino.Os
2986d7f5d3SJohn Marino.Sh NAME
3086d7f5d3SJohn Marino.Nm sockatmark
3186d7f5d3SJohn Marino.Nd determine whether the read pointer is at the OOB mark
3286d7f5d3SJohn Marino.Sh LIBRARY
3386d7f5d3SJohn Marino.Lb libc
3486d7f5d3SJohn Marino.Sh SYNOPSIS
3586d7f5d3SJohn Marino.In sys/socket.h
3686d7f5d3SJohn Marino.Ft int
3786d7f5d3SJohn Marino.Fn sockatmark "int s"
3886d7f5d3SJohn Marino.Sh DESCRIPTION
3986d7f5d3SJohn MarinoTo find out if the read pointer is currently pointing at
4086d7f5d3SJohn Marinothe mark in the data stream, the
4186d7f5d3SJohn Marino.Fn sockatmark
4286d7f5d3SJohn Marinofunction is provided.
4386d7f5d3SJohn MarinoIf
4486d7f5d3SJohn Marino.Fn sockatmark
4586d7f5d3SJohn Marinoreturns 1, the next read will return data
4686d7f5d3SJohn Marinoafter the mark.
4786d7f5d3SJohn MarinoOtherwise (assuming out of band data has arrived),
4886d7f5d3SJohn Marinothe next read will provide data sent by the client prior
4986d7f5d3SJohn Marinoto transmission of the out of band signal.
5086d7f5d3SJohn MarinoThe routine used
5186d7f5d3SJohn Marinoin the remote login process to flush output on receipt of an
5286d7f5d3SJohn Marinointerrupt or quit signal is shown below.
5386d7f5d3SJohn MarinoIt reads the normal data up to the mark (to discard it),
5486d7f5d3SJohn Marinothen reads the out-of-band byte.
5586d7f5d3SJohn Marino.Bd -literal -offset indent
5686d7f5d3SJohn Marino#include <sys/socket.h>
5786d7f5d3SJohn Marino\&...
5886d7f5d3SJohn Marinovoid
5986d7f5d3SJohn Marinooob(void)
6086d7f5d3SJohn Marino{
6186d7f5d3SJohn Marino	int out = FWRITE, mark;
6286d7f5d3SJohn Marino	char waste[BUFSIZ];
6386d7f5d3SJohn Marino
6486d7f5d3SJohn Marino	/* flush local terminal output */
6586d7f5d3SJohn Marino	ioctl(1, TIOCFLUSH, (char *)&out);
6686d7f5d3SJohn Marino	for (;;) {
6786d7f5d3SJohn Marino		if ((mark = sockatmark(rem)) < 0) {
6886d7f5d3SJohn Marino			perror("sockatmark");
6986d7f5d3SJohn Marino			break;
7086d7f5d3SJohn Marino		}
7186d7f5d3SJohn Marino		if (mark)
7286d7f5d3SJohn Marino			break;
7386d7f5d3SJohn Marino		read(rem, waste, sizeof (waste));
7486d7f5d3SJohn Marino	}
7586d7f5d3SJohn Marino	if (recv(rem, &mark, 1, MSG_OOB) < 0) {
7686d7f5d3SJohn Marino		perror("recv");
7786d7f5d3SJohn Marino		...
7886d7f5d3SJohn Marino	}
7986d7f5d3SJohn Marino	...
8086d7f5d3SJohn Marino}
8186d7f5d3SJohn Marino.Ed
8286d7f5d3SJohn Marino.Sh RETURN VALUES
8386d7f5d3SJohn MarinoUpon successful completion, the
8486d7f5d3SJohn Marino.Fn sockatmark
8586d7f5d3SJohn Marinofunction returns the value 1 if the read pointer is pointing at
8686d7f5d3SJohn Marinothe OOB mark, 0 if it is not.
8786d7f5d3SJohn MarinoOtherwise the value \-1 is returned
8886d7f5d3SJohn Marinoand the global variable
8986d7f5d3SJohn Marino.Va errno
9086d7f5d3SJohn Marinois set to
9186d7f5d3SJohn Marinoindicate the error.
9286d7f5d3SJohn Marino.Sh ERRORS
9386d7f5d3SJohn MarinoThe
9486d7f5d3SJohn Marino.Fn sockatmark
9586d7f5d3SJohn Marinocall fails if:
9686d7f5d3SJohn Marino.Bl -tag -width Er
9786d7f5d3SJohn Marino.It Bq Er EBADF
9886d7f5d3SJohn MarinoThe
9986d7f5d3SJohn Marino.Fa s
10086d7f5d3SJohn Marinoargument
10186d7f5d3SJohn Marinois not a valid descriptor.
10286d7f5d3SJohn Marino.It Bq Er ENOTTY
10386d7f5d3SJohn MarinoThe
10486d7f5d3SJohn Marino.Fa s
10586d7f5d3SJohn Marinoargument
10686d7f5d3SJohn Marinois a descriptor for a file, not a socket.
10786d7f5d3SJohn Marino.El
10886d7f5d3SJohn Marino.Sh SEE ALSO
10986d7f5d3SJohn Marino.Xr recv 2 ,
11086d7f5d3SJohn Marino.Xr send 2
11186d7f5d3SJohn Marino.Sh HISTORY
11286d7f5d3SJohn MarinoThe
11386d7f5d3SJohn Marino.Fn sockatmark
11486d7f5d3SJohn Marinofunction was introduced by
11586d7f5d3SJohn Marino.St -p1003.1-2001 ,
11686d7f5d3SJohn Marinoto standardize the historical
11786d7f5d3SJohn Marino.Dv SIOCATMARK
11886d7f5d3SJohn Marino.Xr ioctl 2 .
11986d7f5d3SJohn MarinoThe
12086d7f5d3SJohn Marino.Er ENOTTY
12186d7f5d3SJohn Marinoerror instead of the usual
12286d7f5d3SJohn Marino.Er ENOTSOCK
12386d7f5d3SJohn Marinois to match the historical behavior of
12486d7f5d3SJohn Marino.Dv SIOCATMARK .
125