don't assume CMSG_xx are constant (sync with latest kame)

This commit is contained in:
itojun 2000-02-28 07:14:05 +00:00
parent 970a04ff88
commit bdb384fe26
2 changed files with 36 additions and 20 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: mld6.c,v 1.2 2000/02/03 06:59:35 itojun Exp $ */
/* $NetBSD: mld6.c,v 1.3 2000/02/28 07:14:05 itojun Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@ -118,8 +118,9 @@ static struct msghdr sndmh,
static struct iovec sndiov[2];
static struct iovec rcviov[2];
static struct sockaddr_in6 from;
static u_char rcvcmsgbuf[CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_SPACE(sizeof(int))];
static u_char *rcvcmsgbuf = NULL;
static int rcvcmsglen;
#ifndef USE_RFC2292BIS
u_int8_t raopt[IP6OPT_RTALERT_LEN];
#endif
@ -149,9 +150,14 @@ init_mld6()
rtalert_code = htons(IP6OPT_RTALERT_MLD);
if (!mld6_recv_buf && (mld6_recv_buf = malloc(RECV_BUF_SIZE)) == NULL)
log(LOG_ERR, 0, "malloca failed");
log(LOG_ERR, 0, "malloc failed");
if (!mld6_send_buf && (mld6_send_buf = malloc(RECV_BUF_SIZE)) == NULL)
log(LOG_ERR, 0, "malloca failed");
log(LOG_ERR, 0, "malloc failed");
rcvcmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_SPACE(sizeof(int));
if (rcvcmsgbuf == NULL && (rcvcmsgbuf = malloc(rcvcmsglen)) == NULL)
log(LOG_ERR, 0,"malloc failed");
IF_DEBUG(DEBUG_KERN)
log(LOG_DEBUG,0,"%d octets allocated for the emit/recept buffer mld6",RECV_BUF_SIZE);
@ -213,7 +219,7 @@ init_mld6()
rcvmh.msg_iov = rcviov;
rcvmh.msg_iovlen = 1;
rcvmh.msg_control = (caddr_t) rcvcmsgbuf;
rcvmh.msg_controllen = sizeof(rcvcmsgbuf);
rcvmh.msg_controllen = rcvcmsglen;
/* initialize msghdr for sending packets */
sndiov[0].iov_base = (caddr_t)mld6_send_buf;
@ -277,7 +283,7 @@ int recvlen;
*/
if (rcvmh.msg_controllen == 0) {
/* XXX: msg_controllen must be reset in this case. */
rcvmh.msg_controllen = sizeof(rcvcmsgbuf);
rcvmh.msg_controllen = rcvcmsglen;
process_kernel_call();
return;

View File

@ -1,4 +1,4 @@
/* $NetBSD: pim6.c,v 1.1 2000/01/28 19:32:49 itojun Exp $ */
/* $NetBSD: pim6.c,v 1.2 2000/02/28 07:14:05 itojun Exp $ */
/*
* Copyright (C) 1999 LSIIT Laboratory.
@ -106,8 +106,10 @@ static struct iovec sndiovpim[2];
static struct iovec rcviovpim[2];
static struct msghdr sndmhpim,
rcvmhpim;
static u_char sndcmsgbufpim[CMSG_SPACE(sizeof(struct in6_pktinfo))];
static u_char rcvcmsgbufpim[CMSG_SPACE(sizeof(struct in6_pktinfo))];
static u_char *sndcmsgbufpim = NULL;
static int sndcmsglen;
static u_char *rcvcmsgbufpim = NULL;
static int rcvcmsglen;
/*
@ -120,7 +122,8 @@ static int pim6_cksum __P((u_short *, struct in6_addr *,
void init_pim6()
void
init_pim6()
{
struct cmsghdr *cmsgp;
int on;
@ -171,17 +174,24 @@ void init_pim6()
rcvmhpim.msg_namelen = sizeof (from);
rcvmhpim.msg_iov = rcviovpim;
rcvmhpim.msg_iovlen = 1;
rcvcmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo));
if (rcvcmsgbufpim == NULL &&
(rcvcmsgbufpim = malloc(rcvcmsglen)) == NULL)
log(LOG_ERR, 0, "malloc failed");
rcvmhpim.msg_control = (caddr_t ) rcvcmsgbufpim;
rcvmhpim.msg_controllen = sizeof (rcvcmsgbufpim);
rcvmhpim.msg_controllen = rcvcmsglen;
sndmhpim.msg_namelen=sizeof(struct sockaddr_in6);
sndmhpim.msg_iov=sndiovpim;
sndmhpim.msg_iovlen=1;
sndcmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo));
if (sndcmsgbufpim == NULL &&
(sndcmsgbufpim = malloc(sndcmsglen)) == NULL)
log(LOG_ERR, 0, "malloc failed");
sndmhpim.msg_control = (caddr_t)sndcmsgbufpim;
sndmhpim.msg_controllen=sizeof(sndcmsgbufpim);
sndmhpim.msg_controllen = sndcmsglen;
cmsgp=(struct cmsghdr *)sndcmsgbufpim;
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;
@ -406,7 +416,7 @@ send_pim6(char *buf, struct sockaddr_in6 *src,
else
{
sndmhpim.msg_control = (caddr_t)sndcmsgbufpim;
sndmhpim.msg_controllen=sizeof(sndcmsgbufpim);
sndmhpim.msg_controllen = sndcmsglen;
sndpktinfo->ipi6_ifindex=src->sin6_scope_id;
memcpy(&sndpktinfo->ipi6_addr, &src->sin6_addr,
sizeof(sndpktinfo->ipi6_addr));