uint32_t sum = 0;
while (len > 1) {
- sum += (uint32_t)addr[0] * 256 + (uint32_t)addr[1];
+ sum += (uint32_t)(addr[0] * 256 + addr[1]);
addr += 2;
len -= 2;
}
if (len == 1)
- sum += (uint32_t)*addr * 256;
+ sum += (uint32_t)(*addr * 256);
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
- return (uint16_t)~htons(sum);
+ return (uint16_t)~htons((uint16_t)sum);
}
static struct udp_dhcp_packet *
udp->uh_sport = htons(DHCP_CLIENT_PORT);
udp->uh_dport = htons(DHCP_SERVER_PORT);
- udp->uh_ulen = htons(sizeof(*udp) + length);
+ udp->uh_ulen = htons((uint16_t)(sizeof(*udp) + length));
ip->ip_len = udp->uh_ulen;
udp->uh_sum = checksum(udpp, sizeof(*udpp));
if (o) {
o->code = htons(D6_OPTION_VENDOR_CLASS);
- o->len = htons(len);
+ o->len = htons((uint16_t)len);
p = D6_OPTION_DATA(o);
u32 = htonl(ifo->vivco_en ? ifo->vivco_en : DHCPCD_IANA_PEN);
memcpy(p, &u32, sizeof(u32));
}
static const struct dhcp6_option *
-dhcp6_findoption(unsigned int code, const uint8_t *d, size_t len)
+dhcp6_findoption(uint16_t code, const uint8_t *d, size_t len)
{
const struct dhcp6_option *o;
size_t ol;
}
static const struct dhcp6_option *
-dhcp6_getmoption(unsigned int code, const struct dhcp6_message *m, size_t len)
+dhcp6_getmoption(uint16_t code, const struct dhcp6_message *m, size_t len)
{
if (len < sizeof(*m)) {
up = uptime() - state->start_uptime;
if (up < 0 || up > (time_t)UINT16_MAX)
up = (time_t)UINT16_MAX;
- u16 = htons(up);
+ u16 = htons((uint16_t)up);
memcpy(D6_OPTION_DATA(o), &u16, sizeof(u16));
return 0;
}
i++, opt++)
{
if (has_option_mask(ifo->requiremask6, opt->option) &&
- dhcp6_getmoption(opt->option, r, len) == NULL)
+ dhcp6_getmoption((uint16_t)opt->option, r, len) == NULL)
{
logger(ifp->ctx, LOG_WARNING,
"%s: reject DHCPv6 (no option %s) from %s",
return;
}
if (has_option_mask(ifo->rejectmask6, opt->option) &&
- dhcp6_getmoption(opt->option, r, len))
+ dhcp6_getmoption((uint16_t)opt->option, r, len))
{
logger(ifp->ctx, LOG_WARNING,
"%s: reject DHCPv6 (option %s) from %s",
const char *if_pfname = "Berkley Packet Filter";
int
-if_openrawsocket(struct interface *ifp, int protocol)
+if_openrawsocket(struct interface *ifp, uint16_t protocol)
{
struct dhcp_state *state;
int fd = -1;
add_attr_l(struct nlmsghdr *n, unsigned short maxlen, unsigned short type,
const void *data, unsigned short alen)
{
- unsigned short len = RTA_LENGTH(alen);
+ unsigned short len = (unsigned short)RTA_LENGTH(alen);
struct rtattr *rta;
if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) {
}
#define NLA_TYPE(nla) ((nla)->nla_type & NLA_TYPE_MASK)
-#define NLA_LEN(nla) ((nla)->nla_len - NLA_HDRLEN)
+#define NLA_LEN(nla) (unsigned int)((nla)->nla_len - NLA_HDRLEN)
#define NLA_OK(nla, rem) \
((rem) >= sizeof(struct nlattr) && \
(nla)->nla_len >= sizeof(struct nlattr) && \
const char *if_pfname = "Packet Socket";
int
-if_openrawsocket(struct interface *ifp, int protocol)
+if_openrawsocket(struct interface *ifp, uint16_t protocol)
{
int s;
union sockunion {
#ifdef INET
extern const char *if_pfname;
-int if_openrawsocket(struct interface *, int);
+int if_openrawsocket(struct interface *, uint16_t);
ssize_t if_sendrawpacket(const struct interface *,
uint16_t, const void *, size_t);
ssize_t if_readrawpacket(struct interface *, uint16_t, void *, size_t, int *);
/* ipi6.ifiindex differes between OS's so have a cast function */
-#ifdef __linux__
+#ifdef __GLIBC__
#define CAST_IPI6_IFINDEX(idx) (int)(idx)
#else
#define CAST_IPI6_IFINDEX(idx) (idx)