diff options
| author | Yoshinobu Inoue <shin@FreeBSD.org> | 2000-03-03 11:13:12 +0000 |
|---|---|---|
| committer | Yoshinobu Inoue <shin@FreeBSD.org> | 2000-03-03 11:13:12 +0000 |
| commit | 7d0d8dc306e60c69f94c996787428aeae04c40f1 (patch) | |
| tree | 17dfd3f7d1ac380054dc5c2d2d4d226a3371686c | |
| parent | e84d092b810ab1a2b3175d18fbd6d026e2981c98 (diff) | |
Notes
| -rw-r--r-- | lib/libc/net/rthdr.c | 24 | ||||
| -rw-r--r-- | sbin/ping/ping.c | 2 | ||||
| -rw-r--r-- | sys/kern/uipc_sockbuf.c | 7 | ||||
| -rw-r--r-- | sys/kern/uipc_socket2.c | 7 | ||||
| -rw-r--r-- | sys/netinet6/ip6_output.c | 4 | ||||
| -rw-r--r-- | sys/sys/socket.h | 19 | ||||
| -rw-r--r-- | usr.bin/telnet/commands.c | 26 |
7 files changed, 46 insertions, 43 deletions
diff --git a/lib/libc/net/rthdr.c b/lib/libc/net/rthdr.c index ce2a33ce7a74..1f9d10228476 100644 --- a/lib/libc/net/rthdr.c +++ b/lib/libc/net/rthdr.c @@ -63,7 +63,9 @@ inet6_rthdr_init(bp, type) int type; { register struct cmsghdr *ch = (struct cmsghdr *)bp; - register struct ip6_rthdr *rthdr = (struct ip6_rthdr *)(ch + 1); + register struct ip6_rthdr *rthdr; + + rthdr = (struct ip6_rthdr *)CMSG_DATA(ch); ch->cmsg_level = IPPROTO_IPV6; ch->cmsg_type = IPV6_RTHDR; @@ -88,7 +90,9 @@ inet6_rthdr_add(cmsg, addr, flags) const struct in6_addr *addr; u_int flags; { - register struct ip6_rthdr *rthdr = (struct ip6_rthdr *)(cmsg + 1); + register struct ip6_rthdr *rthdr; + + rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg); switch(rthdr->ip6r_type) { case IPV6_RTHDR_TYPE_0: @@ -135,7 +139,9 @@ inet6_rthdr_lasthop(cmsg, flags) struct cmsghdr *cmsg; unsigned int flags; { - register struct ip6_rthdr *rthdr = (struct ip6_rthdr *)(cmsg + 1); + register struct ip6_rthdr *rthdr; + + rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg); switch(rthdr->ip6r_type) { case IPV6_RTHDR_TYPE_0: @@ -189,7 +195,9 @@ int inet6_rthdr_segments(cmsg) const struct cmsghdr *cmsg; { - register struct ip6_rthdr *rthdr = (struct ip6_rthdr *)(cmsg + 1); + register struct ip6_rthdr *rthdr; + + rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg); switch(rthdr->ip6r_type) { case IPV6_RTHDR_TYPE_0: @@ -221,7 +229,9 @@ inet6_rthdr_getaddr(cmsg, index) struct cmsghdr *cmsg; int index; { - register struct ip6_rthdr *rthdr = (struct ip6_rthdr *)(cmsg + 1); + register struct ip6_rthdr *rthdr; + + rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg); switch(rthdr->ip6r_type) { case IPV6_RTHDR_TYPE_0: @@ -260,7 +270,9 @@ inet6_rthdr_getflags(cmsg, index) const struct cmsghdr *cmsg; int index; { - register struct ip6_rthdr *rthdr = (struct ip6_rthdr *)(cmsg + 1); + register struct ip6_rthdr *rthdr; + + rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg); switch(rthdr->ip6r_type) { case IPV6_RTHDR_TYPE_0: diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index b08acaf0970c..9c42f93d0f91 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -213,7 +213,7 @@ main(argc, argv) struct iovec iov; struct msghdr msg; struct sockaddr_in from; - char ctrl[sizeof(struct cmsghdr) + sizeof(struct timeval)]; + char ctrl[CMSG_SPACE(sizeof(struct timeval))]; #ifdef IPSEC_POLICY_IPSEC char *policy_in = NULL; char *policy_out = NULL; diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c index c1072b7eeaa1..93d1fdacec5a 100644 --- a/sys/kern/uipc_sockbuf.c +++ b/sys/kern/uipc_sockbuf.c @@ -839,16 +839,15 @@ sbcreatecontrol(p, size, type, level) register struct cmsghdr *cp; struct mbuf *m; - if ((u_int)size > MLEN) + if (CMSG_SPACE((u_int)size) > MLEN) return ((struct mbuf *) NULL); if ((m = m_get(M_DONTWAIT, MT_CONTROL)) == NULL) return ((struct mbuf *) NULL); cp = mtod(m, struct cmsghdr *); /* XXX check size? */ (void)memcpy(CMSG_DATA(cp), p, size); - size += sizeof(*cp); - m->m_len = size; - cp->cmsg_len = size; + m->m_len = CMSG_SPACE(size); + cp->cmsg_len = CMSG_LEN(size); cp->cmsg_level = level; cp->cmsg_type = type; return (m); diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index c1072b7eeaa1..93d1fdacec5a 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -839,16 +839,15 @@ sbcreatecontrol(p, size, type, level) register struct cmsghdr *cp; struct mbuf *m; - if ((u_int)size > MLEN) + if (CMSG_SPACE((u_int)size) > MLEN) return ((struct mbuf *) NULL); if ((m = m_get(M_DONTWAIT, MT_CONTROL)) == NULL) return ((struct mbuf *) NULL); cp = mtod(m, struct cmsghdr *); /* XXX check size? */ (void)memcpy(CMSG_DATA(cp), p, size); - size += sizeof(*cp); - m->m_len = size; - cp->cmsg_len = size; + m->m_len = CMSG_SPACE(size); + cp->cmsg_len = CMSG_LEN(size); cp->cmsg_level = level; cp->cmsg_type = type; return (m); diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index b901751fa0dc..fb8545418fb6 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1980,8 +1980,8 @@ ip6_setpktoptions(control, opt, priv) opt->ip6po_m = control; - for (; control->m_len; control->m_data += CMSG_ALIGN(cm->cmsg_len), - control->m_len -= CMSG_ALIGN(cm->cmsg_len)) { + for (; control->m_len; control->m_data += ALIGN(cm->cmsg_len), + control->m_len -= ALIGN(cm->cmsg_len)) { cm = mtod(control, struct cmsghdr *); if (cm->cmsg_len == 0 || cm->cmsg_len > control->m_len) return(EINVAL); diff --git a/sys/sys/socket.h b/sys/sys/socket.h index 1025a940d511..3a59bdc37a82 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -351,26 +351,21 @@ struct cmsgcred { }; /* given pointer to struct cmsghdr, return pointer to data */ -#define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1)) - -/* - * Alignment requirement for CMSG struct manipulation. - * This is different from ALIGN() defined in ARCH/include/param.h. - * XXX think again carefully about architecture dependencies. - */ -#define CMSG_ALIGN(n) (((n) + 3) & ~3) +#define CMSG_DATA(cmsg) ((u_char *)(cmsg) + \ + ALIGN(sizeof(struct cmsghdr))) /* given pointer to struct cmsghdr, return pointer to next cmsghdr */ #define CMSG_NXTHDR(mhdr, cmsg) \ - (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \ + (((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len) + \ + ALIGN(sizeof(struct cmsghdr)) > \ (caddr_t)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \ (struct cmsghdr *)NULL : \ - (struct cmsghdr *)((caddr_t)(cmsg) + CMSG_ALIGN((cmsg)->cmsg_len))) + (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len))) #define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control) -#define CMSG_SPACE(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(l)) -#define CMSG_LEN(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (l)) +#define CMSG_SPACE(l) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(l)) +#define CMSG_LEN(l) (ALIGN(sizeof(struct cmsghdr)) + (l)) /* "Socket"-level control message types: */ #define SCM_RIGHTS 0x01 /* access rights (array of int) */ diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c index 0beb90640884..c0c6b2cb4a53 100644 --- a/usr.bin/telnet/commands.c +++ b/usr.bin/telnet/commands.c @@ -2879,19 +2879,18 @@ sourceroute(ai, arg, cpp, lenp, protop, optp) * at least 7 bytes for the option. */ if (cpp == NULL || lenp == NULL) - return((unsigned long)-1); + return -1; if (*cpp != NULL) { switch (res->ai_family) { case AF_INET: if (*lenp < 7) - return((unsigned long)-1); + return -1; break; #ifdef INET6 case AF_INET6: - if (*lenp < (sizeof(struct cmsghdr) + - sizeof(struct ip6_rthdr) + - sizeof(struct in6_addr))) - return((unsigned long)-1); + if (*lenp < CMSG_SPACE(sizeof(struct ip6_rthdr) + + sizeof(struct in6_addr))) + return -1; break; #endif } @@ -2904,7 +2903,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp) lsrp = *cpp; ep = lsrp + *lenp; } else { - *cpp = lsrp = buf; + *cpp = lsrp = ALIGN(buf); ep = lsrp + 1024; } @@ -2940,7 +2939,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp) #endif if (*cp != '@') - return((unsigned long)-1); + return -1; #ifndef sysV88 lsrp++; /* skip over length, we'll fill it in later */ @@ -3016,16 +3015,15 @@ sourceroute(ai, arg, cpp, lenp, protop, optp) */ #ifdef INET6 if (res->ai_family == AF_INET6) { - if (((char *)cmsg + - sizeof(struct cmsghdr) + + if (((char *)CMSG_DATA(cmsg) + sizeof(struct ip6_rthdr) + ((inet6_rthdr_segments(cmsg) + 1) * sizeof(struct in6_addr))) > ep) - return((unsigned long)-1); + return -1; } else #endif if (lsrp + 4 > ep) - return((unsigned long)-1); + return -1; freeaddrinfo(res); } #ifdef INET6 @@ -3039,7 +3037,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp) if ((*(*cpp+IPOPT_OLEN) = lsrp - *cpp) <= 7) { *cpp = 0; *lenp = 0; - return((unsigned long)-1); + return -1; } *lsrp++ = IPOPT_NOP; /* 32 bit word align it */ *lenp = lsrp - *cpp; @@ -3048,7 +3046,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp) if (ipopt.io_len <= 5) { /* Is 3 better ? */ *cpp = 0; *lenp = 0; - return((unsigned long)-1); + return -1; } *lenp = sizeof(ipopt); *cpp = (char *) &ipopt; |
