summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/net/Makefile.inc13
-rw-r--r--lib/libc/net/sockatmark.3122
-rw-r--r--lib/libc/net/sockatmark.c40
3 files changed, 170 insertions, 5 deletions
diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc
index 6b427174d8d..b063c4a1fad 100644
--- a/lib/libc/net/Makefile.inc
+++ b/lib/libc/net/Makefile.inc
@@ -1,20 +1,23 @@
-# $OpenBSD: Makefile.inc,v 1.55 2014/07/13 13:17:16 guenther Exp $
+# $OpenBSD: Makefile.inc,v 1.56 2014/08/31 02:27:37 guenther Exp $
# net sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net
CFLAGS+=-DRESOLVSORT
-SRCS+= base64.c freeaddrinfo.c gai_strerror.c getaddrinfo.c gethostnamadr.c \
+SRCS+= base64.c ethers.c freeaddrinfo.c \
+ gai_strerror.c getaddrinfo.c gethostnamadr.c \
getifaddrs.c getnameinfo.c getnetbyaddr.c getnetbyname.c getnetent.c \
getnetnamadr.c getpeereid.c getproto.c getprotoent.c getprotoname.c \
getservbyname.c getservbyport.c getservent.c getrrsetbyname.c \
herror.c if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.c \
inet_lnaof.c inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \
inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c inet_pton.c \
- linkaddr.c rcmd.c ruserok.c rresvport.c recv.c res_comp.c res_data.c \
+ linkaddr.c rcmd.c rcmdsh.c ruserok.c \
+ rresvport.c recv.c res_comp.c res_data.c \
res_debug.c res_debug_syms.c res_init.c res_mkquery.c res_query.c \
- res_random.c res_send.c send.c sethostent.c ethers.c rcmdsh.c
+ res_random.c res_send.c \
+ send.c sethostent.c sockatmark.c
# IPv6
SRCS+= ip6opt.c rthdr.c vars6.c
@@ -30,7 +33,7 @@ MAN+= byteorder.3 ethers.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \
getrrsetbyname.3 getservent.3 htonl.3 if_indextoname.3 \
inet_addr.3 inet_lnaof.3 inet_net.3 inet_ntop.3 \
inet6_opt_init.3 inet6_rth_space.3 link_addr.3 \
- rcmd.3 rcmdsh.3 resolver.3
+ rcmd.3 rcmdsh.3 resolver.3 sockatmark.3
MLINKS+=byteorder.3 htobe16.3 byteorder.3 htobe32.3 byteorder.3 htobe64.3 \
byteorder.3 be16toh.3 byteorder.3 be32toh.3 byteorder.3 be64toh.3 \
diff --git a/lib/libc/net/sockatmark.3 b/lib/libc/net/sockatmark.3
new file mode 100644
index 00000000000..6a94b843906
--- /dev/null
+++ b/lib/libc/net/sockatmark.3
@@ -0,0 +1,122 @@
+.\" Copyright (c) 2002 William C. Fenner. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" From FreeBSD: r108087 2002-12-19 01:40:28 -0800
+.\" $OpenBSD: sockatmark.3,v 1.1 2014/08/31 02:27:37 guenther Exp $
+.\"
+.Dd $Mdocdate: August 31 2014 $
+.Dt SOCKATMARK 3
+.Os
+.Sh NAME
+.Nm sockatmark
+.Nd determine whether the read pointer is at the out-of-band data mark
+.Sh SYNOPSIS
+.In sys/socket.h
+.Ft int
+.Fn sockatmark "int s"
+.Sh DESCRIPTION
+The
+.Fn sockatmark
+function returns 1 if the read pointer for the socket
+.Fa s
+is currently at the out-of-band data mark.
+Otherwise, it returns 0 if the socket doesn't have an out-of-band
+data mark or if there is normal data to be received before the mark.
+.Sh RETURN VALUES
+Upon successful completion, the
+.Fn sockatmark
+function returns the value 1 if the read pointer is pointing at
+the out-of-band data mark, 0 if it is not.
+Otherwise the value \-1 is returned
+and the global variable
+.Va errno
+is set to
+indicate the error.
+.Sh EXAMPLES
+The routine used in the historical remote login process to flush
+output on receipt of an interrupt or quit signal is shown below.
+It reads the normal data up to the mark (to discard it),
+then reads the out-of-band byte.
+.Bd -literal -offset indent
+#include <sys/socket.h>
+\&...
+oob()
+{
+ int mark;
+ char waste[BUFSIZ];
+
+ for (;;) {
+ if ((mark = sockatmark(rem)) < 0) {
+ perror("sockatmark");
+ break;
+ }
+ if (mark)
+ break;
+ (void) read(rem, waste, sizeof (waste));
+ }
+ if (recv(rem, &mark, 1, MSG_OOB) < 0) {
+ perror("recv");
+ ...
+ }
+ ...
+}
+.Ed
+.Sh ERRORS
+The
+.Fn sockatmark
+call fails if:
+.Bl -tag -width Er
+.It Bq Er EBADF
+.Fa s
+is not a valid descriptor.
+.It Bq Er ENOTTY
+.Fa s
+is valid but does not refer to a socket.
+.El
+.Sh SEE ALSO
+.Xr recv 2 ,
+.Xr send 2
+.Sh STANDARDS
+The
+.Fn sockatmark
+function conforms to
+.St -p1003.1-2008 .
+.Sh HISTORY
+The
+.Fn sockatmark
+function was introduced by
+.St -p1003.1-2001
+to standardize the historical
+.Dv SIOCATMARK
+.Xr ioctl 2 .
+The
+.Fn sockatmark
+function appeared in
+.Ox 5.7 .
+.Pp
+The
+.Er ENOTTY
+error is returned instead of the usual
+.Er ENOTSOCK
+error to match the historical behavior of
+.Dv SIOCATMARK .
diff --git a/lib/libc/net/sockatmark.c b/lib/libc/net/sockatmark.c
new file mode 100644
index 00000000000..a43e7af3aaa
--- /dev/null
+++ b/lib/libc/net/sockatmark.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2002 William C. Fenner. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/socket.h>
+#include <sys/sockio.h>
+#include <sys/ioctl.h>
+
+int
+sockatmark(int s)
+{
+ int atmark;
+
+ if (ioctl(s, SIOCATMARK, &atmark) == -1)
+ return (-1);
+ return (atmark);
+}