$KAME$ cleanup. address PR 11616 (CMSG_SPACE should be CMSG_LEN).
sync with kame.
This commit is contained in:
parent
8b87a48e0e
commit
a2ca80c86b
|
@ -1,4 +1,5 @@
|
|||
/* $NetBSD: mld6.c,v 1.2 1999/09/03 04:34:34 itojun Exp $ */
|
||||
/* $NetBSD: mld6.c,v 1.3 2000/12/04 07:04:37 itojun Exp $ */
|
||||
/* $KAME: mld6.c,v 1.9 2000/12/04 06:29:37 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1998 WIDE Project.
|
||||
|
@ -77,7 +78,6 @@ main(int argc, char *argv[])
|
|||
struct itimerval itimer;
|
||||
u_int type;
|
||||
int ch;
|
||||
extern int optind;
|
||||
|
||||
type = MLD6_LISTENER_QUERY;
|
||||
while ((ch = getopt(argc, argv, "d")) != EOF) {
|
||||
|
@ -157,8 +157,13 @@ make_msg(int index, struct in6_addr *addr, u_int type)
|
|||
{
|
||||
static struct iovec iov[2];
|
||||
static u_char *cmsgbuf;
|
||||
int cmsglen;
|
||||
int cmsglen, hbhlen = 0;
|
||||
#ifdef USE_RFC2292BIS
|
||||
void *hbhbuf = NULL, *optp = NULL;
|
||||
int currentlen;
|
||||
#else
|
||||
u_int8_t raopt[IP6OPT_RTALERT_LEN];
|
||||
#endif
|
||||
struct in6_pktinfo *pi;
|
||||
struct cmsghdr *cmsgp;
|
||||
u_short rtalert_code = htons(IP6OPT_RTALERT_MLD);
|
||||
|
@ -183,22 +188,51 @@ make_msg(int index, struct in6_addr *addr, u_int type)
|
|||
mldh.mld6_maxdelay = htons(QUERY_RESPONSE_INTERVAL);
|
||||
mldh.mld6_addr = *addr;
|
||||
|
||||
#ifdef USE_RFC2292BIS
|
||||
if ((hbhlen = inet6_opt_init(NULL, 0)) == -1)
|
||||
errx(1, "inet6_opt_init(0) failed");
|
||||
if ((hbhlen = inet6_opt_append(NULL, 0, hbhlen, IP6OPT_ROUTER_ALERT, 2,
|
||||
2, NULL)) == -1)
|
||||
errx(1, "inet6_opt_append(0) failed");
|
||||
if ((hbhlen = inet6_opt_finish(NULL, 0, hbhlen)) == -1)
|
||||
errx(1, "inet6_opt_finish(0) failed");
|
||||
cmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(hbhlen);
|
||||
#else
|
||||
hbhlen = sizeof(raopt);
|
||||
cmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
|
||||
inet6_option_space(sizeof(raopt));
|
||||
inet6_option_space(hbhlen);
|
||||
#endif
|
||||
|
||||
if ((cmsgbuf = malloc(cmsglen)) == NULL)
|
||||
errx(1, "can't allocate enough memory for cmsg");
|
||||
cmsgp = (struct cmsghdr *)cmsgbuf;
|
||||
m.msg_control = (caddr_t)cmsgbuf;
|
||||
m.msg_controllen = cmsglen;
|
||||
/* specify the outgoing interface */
|
||||
cmsgp->cmsg_len = CMSG_SPACE(sizeof(struct in6_pktinfo));
|
||||
cmsgp->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
|
||||
cmsgp->cmsg_level = IPPROTO_IPV6;
|
||||
cmsgp->cmsg_type = IPV6_PKTINFO;
|
||||
pi = (struct in6_pktinfo *)CMSG_DATA(cmsgp);
|
||||
pi->ipi6_ifindex = ifindex;
|
||||
pi->ipi6_ifindex = index;
|
||||
memset(&pi->ipi6_addr, 0, sizeof(pi->ipi6_addr));
|
||||
/* specifiy to insert router alert option in a hop-by-hop opt hdr. */
|
||||
cmsgp = CMSG_NXTHDR(&m, cmsgp);
|
||||
#ifdef USE_RFC2292BIS
|
||||
cmsgp->cmsg_len = CMSG_LEN(hbhlen);
|
||||
cmsgp->cmsg_level = IPPROTO_IPV6;
|
||||
cmsgp->cmsg_type = IPV6_HOPOPTS;
|
||||
hbhbuf = CMSG_DATA(cmsgp);
|
||||
if ((currentlen = inet6_opt_init(hbhbuf, hbhlen)) == -1)
|
||||
errx(1, "inet6_opt_init(len = %d) failed", hbhlen);
|
||||
if ((currentlen = inet6_opt_append(hbhbuf, hbhlen, currentlen,
|
||||
IP6OPT_ROUTER_ALERT, 2,
|
||||
2, &optp)) == -1)
|
||||
errx(1, "inet6_opt_append(currentlen = %d, hbhlen = %d) failed",
|
||||
currentlen, hbhlen);
|
||||
(void)inet6_opt_set_val(optp, 0, &rtalert_code, sizeof(rtalert_code));
|
||||
if ((currentlen = inet6_opt_finish(hbhbuf, hbhlen, currentlen)) == -1)
|
||||
errx(1, "inet6_opt_finish(buf) failed");
|
||||
#else /* old advanced API */
|
||||
if (inet6_option_init((void *)cmsgp, &cmsgp, IPV6_HOPOPTS))
|
||||
errx(1, "inet6_option_init failed\n");
|
||||
raopt[0] = IP6OPT_RTALERT;
|
||||
|
@ -206,6 +240,7 @@ make_msg(int index, struct in6_addr *addr, u_int type)
|
|||
memcpy(&raopt[2], (caddr_t)&rtalert_code, sizeof(u_short));
|
||||
if (inet6_option_append(cmsgp, raopt, 4, 0))
|
||||
errx(1, "inet6_option_append failed\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -250,6 +285,7 @@ dump(int s)
|
|||
fflush(stdout);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
quit(int signum) {
|
||||
mreq.ipv6mr_multiaddr = any;
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
.\" $NetBSD: mld6query.8,v 1.5 2000/12/04 07:04:37 itojun Exp $
|
||||
.\" $KAME: mld6query.8,v 1.5 2000/12/04 06:28:23 itojun Exp $
|
||||
.\"
|
||||
.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
|
@ -25,9 +28,6 @@
|
|||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $NetBSD: mld6query.8,v 1.4 2000/11/07 06:43:37 lukem Exp $
|
||||
.\" KAME Id: mld6query.8,v 1.3 1999/08/20 10:00:06 itojun Exp
|
||||
.\"
|
||||
.Dd May 17, 1998
|
||||
.Dt MLD6QUERY 8
|
||||
.Os
|
||||
|
|
Loading…
Reference in New Issue