mld6.c (fa7c4b1cb3b6f8b2ec2512ae1f88e4535eb80636) mld6.c (af58a3c6bf09911a4a2092b38ad1b056a83fac50)
1/* $KAME: mld6.c,v 1.15 2003/04/02 11:29:54 suz Exp $ */
2
3/*-
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Copyright (C) 1998 WIDE Project.
7 * All rights reserved.
8 *

--- 189 unchanged lines hidden (view full) ---

198}
199
200void
201make_msg(int index, struct in6_addr *addr, u_int type, struct in6_addr *qaddr)
202{
203 static struct iovec iov[2];
204 static u_char *cmsgbuf;
205 int cmsglen, hbhlen = 0;
1/* $KAME: mld6.c,v 1.15 2003/04/02 11:29:54 suz Exp $ */
2
3/*-
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Copyright (C) 1998 WIDE Project.
7 * All rights reserved.
8 *

--- 189 unchanged lines hidden (view full) ---

198}
199
200void
201make_msg(int index, struct in6_addr *addr, u_int type, struct in6_addr *qaddr)
202{
203 static struct iovec iov[2];
204 static u_char *cmsgbuf;
205 int cmsglen, hbhlen = 0;
206#ifdef USE_RFC2292BIS
207 void *hbhbuf = NULL, *optp = NULL;
208 int currentlen;
206 void *hbhbuf = NULL, *optp = NULL;
207 int currentlen;
209#else
210 u_int8_t raopt[IP6OPT_RTALERT_LEN];
211#endif
212 struct in6_pktinfo *pi;
213 struct cmsghdr *cmsgp;
214 u_short rtalert_code = htons(IP6OPT_RTALERT_MLD);
215 struct ifaddrs *ifa, *ifap;
216 struct in6_addr src;
217
218 dst.sin6_len = sizeof(dst);
219 dst.sin6_family = AF_INET6;

--- 28 unchanged lines hidden (view full) ---

248 memcpy(&src, &((struct sockaddr_in6 *)ifap->ifa_addr)->sin6_addr,
249 sizeof(src));
250 freeifaddrs(ifa);
251#ifdef __KAME__
252 /* remove embedded ifindex */
253 src.s6_addr[2] = src.s6_addr[3] = 0;
254#endif
255
208 struct in6_pktinfo *pi;
209 struct cmsghdr *cmsgp;
210 u_short rtalert_code = htons(IP6OPT_RTALERT_MLD);
211 struct ifaddrs *ifa, *ifap;
212 struct in6_addr src;
213
214 dst.sin6_len = sizeof(dst);
215 dst.sin6_family = AF_INET6;

--- 28 unchanged lines hidden (view full) ---

244 memcpy(&src, &((struct sockaddr_in6 *)ifap->ifa_addr)->sin6_addr,
245 sizeof(src));
246 freeifaddrs(ifa);
247#ifdef __KAME__
248 /* remove embedded ifindex */
249 src.s6_addr[2] = src.s6_addr[3] = 0;
250#endif
251
256#ifdef USE_RFC2292BIS
257 if ((hbhlen = inet6_opt_init(NULL, 0)) == -1)
258 errx(1, "inet6_opt_init(0) failed");
259 if ((hbhlen = inet6_opt_append(NULL, 0, hbhlen, IP6OPT_ROUTER_ALERT, 2,
260 2, NULL)) == -1)
261 errx(1, "inet6_opt_append(0) failed");
262 if ((hbhlen = inet6_opt_finish(NULL, 0, hbhlen)) == -1)
263 errx(1, "inet6_opt_finish(0) failed");
264 cmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(hbhlen);
252 if ((hbhlen = inet6_opt_init(NULL, 0)) == -1)
253 errx(1, "inet6_opt_init(0) failed");
254 if ((hbhlen = inet6_opt_append(NULL, 0, hbhlen, IP6OPT_ROUTER_ALERT, 2,
255 2, NULL)) == -1)
256 errx(1, "inet6_opt_append(0) failed");
257 if ((hbhlen = inet6_opt_finish(NULL, 0, hbhlen)) == -1)
258 errx(1, "inet6_opt_finish(0) failed");
259 cmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(hbhlen);
265#else
266 hbhlen = sizeof(raopt);
267 cmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
268 inet6_option_space(hbhlen);
269#endif
270
271 if ((cmsgbuf = malloc(cmsglen)) == NULL)
272 errx(1, "can't allocate enough memory for cmsg");
273 cmsgp = (struct cmsghdr *)cmsgbuf;
274 m.msg_control = (caddr_t)cmsgbuf;
275 m.msg_controllen = cmsglen;
276 /* specify the outgoing interface */
277 cmsgp->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
278 cmsgp->cmsg_level = IPPROTO_IPV6;
279 cmsgp->cmsg_type = IPV6_PKTINFO;
280 pi = (struct in6_pktinfo *)CMSG_DATA(cmsgp);
281 pi->ipi6_ifindex = index;
282 memcpy(&pi->ipi6_addr, &src, sizeof(pi->ipi6_addr));
283 /* specifiy to insert router alert option in a hop-by-hop opt hdr. */
284 cmsgp = CMSG_NXTHDR(&m, cmsgp);
260
261 if ((cmsgbuf = malloc(cmsglen)) == NULL)
262 errx(1, "can't allocate enough memory for cmsg");
263 cmsgp = (struct cmsghdr *)cmsgbuf;
264 m.msg_control = (caddr_t)cmsgbuf;
265 m.msg_controllen = cmsglen;
266 /* specify the outgoing interface */
267 cmsgp->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
268 cmsgp->cmsg_level = IPPROTO_IPV6;
269 cmsgp->cmsg_type = IPV6_PKTINFO;
270 pi = (struct in6_pktinfo *)CMSG_DATA(cmsgp);
271 pi->ipi6_ifindex = index;
272 memcpy(&pi->ipi6_addr, &src, sizeof(pi->ipi6_addr));
273 /* specifiy to insert router alert option in a hop-by-hop opt hdr. */
274 cmsgp = CMSG_NXTHDR(&m, cmsgp);
285#ifdef USE_RFC2292BIS
286 cmsgp->cmsg_len = CMSG_LEN(hbhlen);
287 cmsgp->cmsg_level = IPPROTO_IPV6;
288 cmsgp->cmsg_type = IPV6_HOPOPTS;
289 hbhbuf = CMSG_DATA(cmsgp);
290 if ((currentlen = inet6_opt_init(hbhbuf, hbhlen)) == -1)
291 errx(1, "inet6_opt_init(len = %d) failed", hbhlen);
292 if ((currentlen = inet6_opt_append(hbhbuf, hbhlen, currentlen,
293 IP6OPT_ROUTER_ALERT, 2,
294 2, &optp)) == -1)
295 errx(1, "inet6_opt_append(currentlen = %d, hbhlen = %d) failed",
296 currentlen, hbhlen);
297 (void)inet6_opt_set_val(optp, 0, &rtalert_code, sizeof(rtalert_code));
298 if ((currentlen = inet6_opt_finish(hbhbuf, hbhlen, currentlen)) == -1)
299 errx(1, "inet6_opt_finish(buf) failed");
275 cmsgp->cmsg_len = CMSG_LEN(hbhlen);
276 cmsgp->cmsg_level = IPPROTO_IPV6;
277 cmsgp->cmsg_type = IPV6_HOPOPTS;
278 hbhbuf = CMSG_DATA(cmsgp);
279 if ((currentlen = inet6_opt_init(hbhbuf, hbhlen)) == -1)
280 errx(1, "inet6_opt_init(len = %d) failed", hbhlen);
281 if ((currentlen = inet6_opt_append(hbhbuf, hbhlen, currentlen,
282 IP6OPT_ROUTER_ALERT, 2,
283 2, &optp)) == -1)
284 errx(1, "inet6_opt_append(currentlen = %d, hbhlen = %d) failed",
285 currentlen, hbhlen);
286 (void)inet6_opt_set_val(optp, 0, &rtalert_code, sizeof(rtalert_code));
287 if ((currentlen = inet6_opt_finish(hbhbuf, hbhlen, currentlen)) == -1)
288 errx(1, "inet6_opt_finish(buf) failed");
300#else /* old advanced API */
301 if (inet6_option_init((void *)cmsgp, &cmsgp, IPV6_HOPOPTS))
302 errx(1, "inet6_option_init failed\n");
303 raopt[0] = IP6OPT_ROUTER_ALERT;
304 raopt[1] = IP6OPT_RTALERT_LEN - 2;
305 memcpy(&raopt[2], (caddr_t)&rtalert_code, sizeof(u_short));
306 if (inet6_option_append(cmsgp, raopt, 4, 0))
307 errx(1, "inet6_option_append failed\n");
308#endif
309}
310
311void
312dump(int s)
313{
314 int i;
315 struct mld_hdr *mld;
316 u_char buf[1024];

--- 54 unchanged lines hidden ---
289}
290
291void
292dump(int s)
293{
294 int i;
295 struct mld_hdr *mld;
296 u_char buf[1024];

--- 54 unchanged lines hidden ---