diff options
author | guenther <> | 2014-08-31 02:27:37 +0000 |
---|---|---|
committer | guenther <> | 2014-08-31 02:27:37 +0000 |
commit | 42e8e4472ac4b00c2a0578f02c0ee682e9feb71a (patch) | |
tree | 67f20a1ba2a6a8bdba30d3421b2eddb4f9be4313 /src | |
parent | 9c7115b7ab2fa3c3ee53653676df013b71fd364d (diff) | |
download | openbsd-42e8e4472ac4b00c2a0578f02c0ee682e9feb71a.tar.gz openbsd-42e8e4472ac4b00c2a0578f02c0ee682e9feb71a.tar.bz2 openbsd-42e8e4472ac4b00c2a0578f02c0ee682e9feb71a.zip |
Add sockatmark()
ok millert@ manpage feedback jmc@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libc/net/Makefile.inc | 13 | ||||
-rw-r--r-- | src/lib/libc/net/sockatmark.3 | 122 | ||||
-rw-r--r-- | src/lib/libc/net/sockatmark.c | 40 |
3 files changed, 170 insertions, 5 deletions
diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc index 6b427174d8..b063c4a1fa 100644 --- a/src/lib/libc/net/Makefile.inc +++ b/src/lib/libc/net/Makefile.inc | |||
@@ -1,20 +1,23 @@ | |||
1 | # $OpenBSD: Makefile.inc,v 1.55 2014/07/13 13:17:16 guenther Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.56 2014/08/31 02:27:37 guenther Exp $ |
2 | 2 | ||
3 | # net sources | 3 | # net sources |
4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net | 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net |
5 | 5 | ||
6 | CFLAGS+=-DRESOLVSORT | 6 | CFLAGS+=-DRESOLVSORT |
7 | 7 | ||
8 | SRCS+= base64.c freeaddrinfo.c gai_strerror.c getaddrinfo.c gethostnamadr.c \ | 8 | SRCS+= base64.c ethers.c freeaddrinfo.c \ |
9 | gai_strerror.c getaddrinfo.c gethostnamadr.c \ | ||
9 | getifaddrs.c getnameinfo.c getnetbyaddr.c getnetbyname.c getnetent.c \ | 10 | getifaddrs.c getnameinfo.c getnetbyaddr.c getnetbyname.c getnetent.c \ |
10 | getnetnamadr.c getpeereid.c getproto.c getprotoent.c getprotoname.c \ | 11 | getnetnamadr.c getpeereid.c getproto.c getprotoent.c getprotoname.c \ |
11 | getservbyname.c getservbyport.c getservent.c getrrsetbyname.c \ | 12 | getservbyname.c getservbyport.c getservent.c getrrsetbyname.c \ |
12 | herror.c if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.c \ | 13 | herror.c if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.c \ |
13 | inet_lnaof.c inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \ | 14 | inet_lnaof.c inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \ |
14 | inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c inet_pton.c \ | 15 | inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c inet_pton.c \ |
15 | linkaddr.c rcmd.c ruserok.c rresvport.c recv.c res_comp.c res_data.c \ | 16 | linkaddr.c rcmd.c rcmdsh.c ruserok.c \ |
17 | rresvport.c recv.c res_comp.c res_data.c \ | ||
16 | res_debug.c res_debug_syms.c res_init.c res_mkquery.c res_query.c \ | 18 | res_debug.c res_debug_syms.c res_init.c res_mkquery.c res_query.c \ |
17 | res_random.c res_send.c send.c sethostent.c ethers.c rcmdsh.c | 19 | res_random.c res_send.c \ |
20 | send.c sethostent.c sockatmark.c | ||
18 | 21 | ||
19 | # IPv6 | 22 | # IPv6 |
20 | SRCS+= ip6opt.c rthdr.c vars6.c | 23 | SRCS+= ip6opt.c rthdr.c vars6.c |
@@ -30,7 +33,7 @@ MAN+= byteorder.3 ethers.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ | |||
30 | getrrsetbyname.3 getservent.3 htonl.3 if_indextoname.3 \ | 33 | getrrsetbyname.3 getservent.3 htonl.3 if_indextoname.3 \ |
31 | inet_addr.3 inet_lnaof.3 inet_net.3 inet_ntop.3 \ | 34 | inet_addr.3 inet_lnaof.3 inet_net.3 inet_ntop.3 \ |
32 | inet6_opt_init.3 inet6_rth_space.3 link_addr.3 \ | 35 | inet6_opt_init.3 inet6_rth_space.3 link_addr.3 \ |
33 | rcmd.3 rcmdsh.3 resolver.3 | 36 | rcmd.3 rcmdsh.3 resolver.3 sockatmark.3 |
34 | 37 | ||
35 | MLINKS+=byteorder.3 htobe16.3 byteorder.3 htobe32.3 byteorder.3 htobe64.3 \ | 38 | MLINKS+=byteorder.3 htobe16.3 byteorder.3 htobe32.3 byteorder.3 htobe64.3 \ |
36 | byteorder.3 be16toh.3 byteorder.3 be32toh.3 byteorder.3 be64toh.3 \ | 39 | byteorder.3 be16toh.3 byteorder.3 be32toh.3 byteorder.3 be64toh.3 \ |
diff --git a/src/lib/libc/net/sockatmark.3 b/src/lib/libc/net/sockatmark.3 new file mode 100644 index 0000000000..6a94b84390 --- /dev/null +++ b/src/lib/libc/net/sockatmark.3 | |||
@@ -0,0 +1,122 @@ | |||
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 | .\" From FreeBSD: r108087 2002-12-19 01:40:28 -0800 | ||
25 | .\" $OpenBSD: sockatmark.3,v 1.1 2014/08/31 02:27:37 guenther Exp $ | ||
26 | .\" | ||
27 | .Dd $Mdocdate: August 31 2014 $ | ||
28 | .Dt SOCKATMARK 3 | ||
29 | .Os | ||
30 | .Sh NAME | ||
31 | .Nm sockatmark | ||
32 | .Nd determine whether the read pointer is at the out-of-band data mark | ||
33 | .Sh SYNOPSIS | ||
34 | .In sys/socket.h | ||
35 | .Ft int | ||
36 | .Fn sockatmark "int s" | ||
37 | .Sh DESCRIPTION | ||
38 | The | ||
39 | .Fn sockatmark | ||
40 | function returns 1 if the read pointer for the socket | ||
41 | .Fa s | ||
42 | is currently at the out-of-band data mark. | ||
43 | Otherwise, it returns 0 if the socket doesn't have an out-of-band | ||
44 | data mark or if there is normal data to be received before the mark. | ||
45 | .Sh RETURN VALUES | ||
46 | Upon successful completion, the | ||
47 | .Fn sockatmark | ||
48 | function returns the value 1 if the read pointer is pointing at | ||
49 | the out-of-band data mark, 0 if it is not. | ||
50 | Otherwise the value \-1 is returned | ||
51 | and the global variable | ||
52 | .Va errno | ||
53 | is set to | ||
54 | indicate the error. | ||
55 | .Sh EXAMPLES | ||
56 | The routine used in the historical remote login process to flush | ||
57 | output on receipt of an interrupt or quit signal is shown below. | ||
58 | It reads the normal data up to the mark (to discard it), | ||
59 | then reads the out-of-band byte. | ||
60 | .Bd -literal -offset indent | ||
61 | #include <sys/socket.h> | ||
62 | \&... | ||
63 | oob() | ||
64 | { | ||
65 | int mark; | ||
66 | char waste[BUFSIZ]; | ||
67 | |||
68 | for (;;) { | ||
69 | if ((mark = sockatmark(rem)) < 0) { | ||
70 | perror("sockatmark"); | ||
71 | break; | ||
72 | } | ||
73 | if (mark) | ||
74 | break; | ||
75 | (void) read(rem, waste, sizeof (waste)); | ||
76 | } | ||
77 | if (recv(rem, &mark, 1, MSG_OOB) < 0) { | ||
78 | perror("recv"); | ||
79 | ... | ||
80 | } | ||
81 | ... | ||
82 | } | ||
83 | .Ed | ||
84 | .Sh ERRORS | ||
85 | The | ||
86 | .Fn sockatmark | ||
87 | call fails if: | ||
88 | .Bl -tag -width Er | ||
89 | .It Bq Er EBADF | ||
90 | .Fa s | ||
91 | is not a valid descriptor. | ||
92 | .It Bq Er ENOTTY | ||
93 | .Fa s | ||
94 | is valid but does not refer to a socket. | ||
95 | .El | ||
96 | .Sh SEE ALSO | ||
97 | .Xr recv 2 , | ||
98 | .Xr send 2 | ||
99 | .Sh STANDARDS | ||
100 | The | ||
101 | .Fn sockatmark | ||
102 | function conforms to | ||
103 | .St -p1003.1-2008 . | ||
104 | .Sh HISTORY | ||
105 | The | ||
106 | .Fn sockatmark | ||
107 | function was introduced by | ||
108 | .St -p1003.1-2001 | ||
109 | to standardize the historical | ||
110 | .Dv SIOCATMARK | ||
111 | .Xr ioctl 2 . | ||
112 | The | ||
113 | .Fn sockatmark | ||
114 | function appeared in | ||
115 | .Ox 5.7 . | ||
116 | .Pp | ||
117 | The | ||
118 | .Er ENOTTY | ||
119 | error is returned instead of the usual | ||
120 | .Er ENOTSOCK | ||
121 | error to match the historical behavior of | ||
122 | .Dv SIOCATMARK . | ||
diff --git a/src/lib/libc/net/sockatmark.c b/src/lib/libc/net/sockatmark.c new file mode 100644 index 0000000000..a43e7af3aa --- /dev/null +++ b/src/lib/libc/net/sockatmark.c | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2002 William C. Fenner. All rights reserved. | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions | ||
6 | * are met: | ||
7 | * 1. Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * 2. Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * | ||
13 | * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND | ||
14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
23 | * SUCH DAMAGE. | ||
24 | * | ||
25 | * $FreeBSD$ | ||
26 | */ | ||
27 | |||
28 | #include <sys/socket.h> | ||
29 | #include <sys/sockio.h> | ||
30 | #include <sys/ioctl.h> | ||
31 | |||
32 | int | ||
33 | sockatmark(int s) | ||
34 | { | ||
35 | int atmark; | ||
36 | |||
37 | if (ioctl(s, SIOCATMARK, &atmark) == -1) | ||
38 | return (-1); | ||
39 | return (atmark); | ||
40 | } | ||