1 /* setsockopt functions
2 * Copyright (C) 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 /* Set IPv6 packet info to the socket. */
28 setsockopt_ipv6_pktinfo (int sock
, int val
)
32 #ifdef IPV6_RECVPKTINFO /*2292bis-01*/
33 ret
= setsockopt(sock
, IPPROTO_IPV6
, IPV6_RECVPKTINFO
, &val
, sizeof(val
));
35 zlog_warn ("can't setsockopt IPV6_RECVPKTINFO : %s", strerror (errno
));
37 ret
= setsockopt(sock
, IPPROTO_IPV6
, IPV6_PKTINFO
, &val
, sizeof(val
));
39 zlog_warn ("can't setsockopt IPV6_PKTINFO : %s", strerror (errno
));
40 #endif /* INIA_IPV6 */
44 /* Set multicast hops val to the socket. */
46 setsockopt_ipv6_checksum (int sock
, int val
)
51 ret
= setsockopt(sock
, IPPROTO_RAW
, IPV6_CHECKSUM
, &val
, sizeof(val
));
53 ret
= setsockopt(sock
, IPPROTO_IPV6
, IPV6_CHECKSUM
, &val
, sizeof(val
));
54 #endif /* GNU_LINUX */
56 zlog_warn ("can't setsockopt IPV6_CHECKSUM");
60 /* Set multicast hops val to the socket. */
62 setsockopt_ipv6_multicast_hops (int sock
, int val
)
66 ret
= setsockopt(sock
, IPPROTO_IPV6
, IPV6_MULTICAST_HOPS
, &val
, sizeof(val
));
68 zlog_warn ("can't setsockopt IPV6_MULTICAST_HOPS");
72 /* Set multicast hops val to the socket. */
74 setsockopt_ipv6_unicast_hops (int sock
, int val
)
78 ret
= setsockopt(sock
, IPPROTO_IPV6
, IPV6_UNICAST_HOPS
, &val
, sizeof(val
));
80 zlog_warn ("can't setsockopt IPV6_UNICAST_HOPS");
85 setsockopt_ipv6_hoplimit (int sock
, int val
)
89 #ifdef IPV6_RECVHOPLIMIT /*2292bis-01*/
90 ret
= setsockopt (sock
, IPPROTO_IPV6
, IPV6_RECVHOPLIMIT
, &val
, sizeof(val
));
92 zlog_warn ("can't setsockopt IPV6_RECVHOPLIMIT");
94 ret
= setsockopt (sock
, IPPROTO_IPV6
, IPV6_HOPLIMIT
, &val
, sizeof(val
));
96 zlog_warn ("can't setsockopt IPV6_HOPLIMIT");
101 /* Set multicast loop zero to the socket. */
103 setsockopt_ipv6_multicast_loop (int sock
, int val
)
107 ret
= setsockopt (sock
, IPPROTO_IPV6
, IPV6_MULTICAST_LOOP
, &val
,
110 zlog_warn ("can't setsockopt IPV6_MULTICAST_LOOP");
114 #endif /* HAVE_IPV6 */
117 /* Set up a multicast socket options for IPv4
118 This is here so that people only have to do their OS multicast mess
119 in one place rather than all through zebra, ospfd, and ripd
120 NB: This is a hookpoint for specific OS functionality */
122 setsockopt_multicast_ipv4(int sock
,
124 struct in_addr if_addr
,
125 unsigned int mcast_addr
,
126 unsigned int ifindex
)
129 /* Linux 2.2.0 and up */
130 #if defined(GNU_LINUX) && LINUX_VERSION_CODE > 131584
131 /* This is better because it uses ifindex directly */
132 struct ip_mreqn mreqn
;
136 case IP_MULTICAST_IF
:
137 case IP_ADD_MEMBERSHIP
:
138 case IP_DROP_MEMBERSHIP
:
139 memset (&mreqn
, 0, sizeof(mreqn
));
142 mreqn
.imr_multiaddr
.s_addr
= mcast_addr
;
145 mreqn
.imr_ifindex
= ifindex
;
147 mreqn
.imr_address
= if_addr
;
149 return setsockopt(sock
, IPPROTO_IP
, optname
, (void *)&mreqn
, sizeof(mreqn
));
153 /* Can out and give an understandable error */
159 /* Example defines for another OS, boilerplate off other code in this
160 function, AND handle optname as per other sections for consistency !! */
161 /* #elif defined(BOGON_NIX) && EXAMPLE_VERSION_CODE > -100000 */
162 /* Add your favourite OS here! */
164 #else /* #if OS_TYPE */
165 /* default OS support */
172 case IP_MULTICAST_IF
:
175 return setsockopt (sock
, IPPROTO_IP
, optname
, (void *)&m
, sizeof(m
));
178 case IP_ADD_MEMBERSHIP
:
179 case IP_DROP_MEMBERSHIP
:
180 memset (&mreq
, 0, sizeof(mreq
));
181 mreq
.imr_multiaddr
.s_addr
= mcast_addr
;
182 mreq
.imr_interface
= if_addr
;
184 return setsockopt (sock
,
192 /* Can out and give an understandable error */
197 #endif /* #if OS_TYPE */