2 * Check decoding of ICMP_FILTER.
4 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/socket.h>
33 #include <linux/icmp.h>
38 getsockopt(-1, SOL_RAW, ICMP_FILTER, 0, 0);
39 printf("getsockopt(-1, SOL_RAW, ICMP_FILTER, NULL, NULL) = -1 %s (%m)\n",
42 setsockopt(-1, SOL_RAW, ICMP_FILTER, NULL, 0);
43 printf("setsockopt(-1, SOL_RAW, ICMP_FILTER, NULL, 0) = -1 %s (%m)\n",
46 TAIL_ALLOC_OBJECT_CONST_PTR(socklen_t, plen);
47 void *const efault = plen + 1;
48 TAIL_ALLOC_OBJECT_CONST_PTR(struct icmp_filter, f);
50 getsockopt(-1, SOL_RAW, ICMP_FILTER, f, plen);
51 printf("getsockopt(-1, SOL_RAW, ICMP_FILTER, %p, %p) = -1 %s (%m)\n",
52 f, plen, errno2name());
54 setsockopt(-1, SOL_RAW, ICMP_FILTER, efault, sizeof(*f));
55 printf("setsockopt(-1, SOL_RAW, ICMP_FILTER, %p, %u) = -1 %s (%m)\n",
56 efault, (unsigned) sizeof(*f), errno2name());
60 1<<ICMP_DEST_UNREACH |
61 1<<ICMP_SOURCE_QUENCH |
63 1<<ICMP_TIME_EXCEEDED |
64 1<<ICMP_PARAMETERPROB);
66 setsockopt(-1, SOL_RAW, ICMP_FILTER, f, -2);
67 printf("setsockopt(-1, SOL_RAW, ICMP_FILTER, %p, -2) = -1 %s (%m)\n",
70 setsockopt(-1, SOL_RAW, ICMP_FILTER, f, sizeof(*f));
71 printf("setsockopt(-1, SOL_RAW, ICMP_FILTER, %s, %u) = -1 %s (%m)\n",
72 "~(1<<ICMP_ECHOREPLY|1<<ICMP_DEST_UNREACH|1<<ICMP_SOURCE_QUENCH"
73 "|1<<ICMP_REDIRECT|1<<ICMP_TIME_EXCEEDED|1<<ICMP_PARAMETERPROB)",
74 (unsigned) sizeof(*f), errno2name());
76 setsockopt(-1, SOL_RAW, ICMP_FILTER, f, sizeof(*f) * 2);
77 printf("setsockopt(-1, SOL_RAW, ICMP_FILTER, %s, %u) = -1 %s (%m)\n",
78 "~(1<<ICMP_ECHOREPLY|1<<ICMP_DEST_UNREACH|1<<ICMP_SOURCE_QUENCH"
79 "|1<<ICMP_REDIRECT|1<<ICMP_TIME_EXCEEDED|1<<ICMP_PARAMETERPROB)",
80 (unsigned) sizeof(*f) * 2, errno2name());
82 puts("+++ exited with 0 +++");