diff --git a/arping.c b/arping.c index 8c08dd3a..b23405cb 100644 --- a/arping.c +++ b/arping.c @@ -398,7 +398,7 @@ void print_hex(unsigned char *p, int len) } } -int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM, +int recv_pack(unsigned char *buf, ssize_t len, struct sockaddr_ll *FROM, struct in_addr src, struct in_addr dst) { struct timespec ts; @@ -431,7 +431,7 @@ int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM, return 0; if (ah->ar_hln != ((struct sockaddr_ll *)&me)->sll_halen) return 0; - if (len < sizeof(*ah) + 2*(4 + ah->ar_hln)) + if (len < (ssize_t) sizeof(*ah) + 2*(4 + ah->ar_hln)) return 0; memcpy(&src_ip, p+ah->ar_hln, 4); memcpy(&dst_ip, p+ah->ar_hln+4+ah->ar_hln, 4); @@ -704,7 +704,7 @@ static int sysfs_devattr_ulong_hex(char *ptr, struct sysfs_devattr_values *v, un static int sysfs_devattr_macaddr(char *ptr, struct sysfs_devattr_values *v, unsigned int idx) { unsigned char *m; - int i; + unsigned int i; unsigned int addrlen; if (!ptr || !v) @@ -1210,7 +1210,7 @@ main(int argc, char **argv) unsigned char packet[4096]; struct sockaddr_storage from; socklen_t alen = sizeof(from); - int cc; + ssize_t cc; sigemptyset(&sset); sigaddset(&sset, SIGALRM); diff --git a/ninfod/ni_ifaddrs.c b/ninfod/ni_ifaddrs.c index 990cf06b..58b0668a 100644 --- a/ninfod/ni_ifaddrs.c +++ b/ninfod/ni_ifaddrs.c @@ -110,7 +110,7 @@ struct rtmaddr_ifamap { #endif /* ====================================================================== */ -static int nl_sendreq(int sd, int request, int flags, int *seq) +static int nl_sendreq(int sd, int request, int flags, uint32_t *seq) { char reqbuf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) + NLMSG_ALIGN(sizeof(struct rtgenmsg))]; struct sockaddr_nl nladdr; @@ -160,7 +160,7 @@ static int nl_recvmsg(int sd, int request, int seq, void *buf, size_t buflen, in return read_len; } -static int nl_getmsg(int sd, int request, int seq, struct nlmsghdr **nlhp, int *done) +static int nl_getmsg(int sd, int request, uint32_t seq, struct nlmsghdr **nlhp, int *done) { struct nlmsghdr *nh; size_t bufsize = 65536, lastbufsize = 0; @@ -186,7 +186,7 @@ static int nl_getmsg(int sd, int request, int seq, struct nlmsghdr **nlhp, int * break; nh = (struct nlmsghdr *) buff; for (nh = (struct nlmsghdr *) buff; NLMSG_OK(nh, read_size); nh = (struct nlmsghdr *) NLMSG_NEXT(nh, read_size)) { - if (nh->nlmsg_pid != pid || nh->nlmsg_seq != seq) + if ((pid_t) nh->nlmsg_pid != pid || nh->nlmsg_seq != seq) continue; if (nh->nlmsg_type == NLMSG_DONE) { (*done)++; @@ -215,7 +215,7 @@ static int nl_getmsg(int sd, int request, int seq, struct nlmsghdr **nlhp, int * return result; } -static int nl_getlist(int sd, int seq, int request, struct nlmsg_list **nlm_list, struct nlmsg_list **nlm_end) +static int nl_getlist(int sd, uint32_t seq, int request, struct nlmsg_list **nlm_list, struct nlmsg_list **nlm_end) { struct nlmsghdr *nlh = NULL; int status; @@ -252,7 +252,7 @@ static int nl_getlist(int sd, int seq, int request, struct nlmsg_list **nlm_list } } } - return status >= 0 ? seq : status; + return status >= 0 ? (int) seq : status; } /* ---------------------------------------------------------------------- */ @@ -392,7 +392,7 @@ int ni_ifaddrs(struct ni_ifaddrs **ifap, sa_family_t family) #endif /* check if the message is what we want */ - if (nlh->nlmsg_pid != pid || nlh->nlmsg_seq != nlm->seq) + if ((pid_t) nlh->nlmsg_pid != pid || nlh->nlmsg_seq != nlm->seq) continue; if (nlh->nlmsg_type == NLMSG_DONE) { break; /* ok */ diff --git a/ninfod/ninfod.h b/ninfod/ninfod.h index 6c88f133..a84a43b3 100644 --- a/ninfod/ninfod.h +++ b/ninfod/ninfod.h @@ -62,7 +62,7 @@ struct packetcontext { socklen_t addrlen; struct in6_pktinfo pktinfo; char query[MAX_QUERY_SIZE]; - int querylen; + size_t querylen; /* reply info */ struct icmp6_nodeinfo reply; /* common */ diff --git a/ninfod/ninfod_core.c b/ninfod/ninfod_core.c index 647b138d..59bfa0b6 100644 --- a/ninfod/ninfod_core.c +++ b/ninfod/ninfod_core.c @@ -158,7 +158,7 @@ static struct subjinfo subjinfo_null = { .checksubj = pr_nodeinfo_noop, }; -static __inline__ struct subjinfo *subjinfo_lookup(int code) +static __inline__ struct subjinfo *subjinfo_lookup(size_t code) { if (code >= ARRAY_SIZE(subjinfo_table)) return NULL; @@ -224,7 +224,7 @@ static struct qtypeinfo qtypeinfo_refused = { .flags = QTYPEINFO_F_RATELIMIT, }; -static __inline__ struct qtypeinfo *qtypeinfo_lookup(int qtype) +static __inline__ struct qtypeinfo *qtypeinfo_lookup(size_t qtype) { if (qtype >= ARRAY_SIZE(qtypeinfo_table)) return &qtypeinfo_unknown; @@ -387,7 +387,7 @@ static int ni_policy(struct packetcontext *p) /* ---------- */ void init_core(int forced) { - int i; + size_t i; DEBUG(LOG_DEBUG, "%s()\n", __func__); diff --git a/ninfod/ninfod_name.c b/ninfod/ninfod_name.c index fa89c454..7f02953a 100644 --- a/ninfod/ninfod_name.c +++ b/ninfod/ninfod_name.c @@ -156,7 +156,7 @@ static int encode_dnsname(const char *name, int fqdn) { size_t namelen; - int i; + size_t i; namelen = strlen(name); if (namelen == 0) diff --git a/ping.c b/ping.c index 10237700..637f2e1b 100644 --- a/ping.c +++ b/ping.c @@ -865,7 +865,7 @@ int ping4_run(int argc, char **argv, struct addrinfo *ai, socket_st *sock) exit(2); } - if (datalen >= sizeof(struct timeval)) /* can we time transfer */ + if (datalen >= (int) sizeof(struct timeval)) /* can we time transfer */ timing = 1; packlen = datalen + MAXIPLEN + MAXICMPLEN; if (!(packet = (unsigned char *)malloc((unsigned int)packlen))) { @@ -886,7 +886,7 @@ int ping4_run(int argc, char **argv, struct addrinfo *ai, socket_st *sock) int ping4_receive_error_msg(socket_st *sock) { - int res; + ssize_t res; char cbuf[512]; struct iovec iov; struct msghdr msg; @@ -936,7 +936,7 @@ int ping4_receive_error_msg(socket_st *sock) } else if (e->ee_origin == SO_EE_ORIGIN_ICMP) { struct sockaddr_in *sin = (struct sockaddr_in*)(e+1); - if (res < sizeof(icmph) || + if (res < (ssize_t) sizeof(icmph) || target.sin_addr.s_addr != whereto.sin_addr.s_addr || icmph.type != ICMP_ECHO || !is_ours(sock, icmph.un.echo.id)) { @@ -1110,7 +1110,7 @@ ping4_parse_reply(struct socket_st *sock, struct msghdr *msg, int cc, void *addr struct iphdr * iph = (struct iphdr *)(&icp[1]); struct icmphdr *icp1 = (struct icmphdr*)((unsigned char *)iph + iph->ihl*4); int error_pkt; - if (cc < 8+sizeof(struct iphdr)+8 || + if (cc < (int) (8 + sizeof(struct iphdr) + 8) || cc < 8+iph->ihl*4+8) return 1; if (icp1->type != ICMP_ECHO || diff --git a/ping6_common.c b/ping6_common.c index ffdc8f9c..83a20dfa 100644 --- a/ping6_common.c +++ b/ping6_common.c @@ -90,7 +90,7 @@ static struct sockaddr_in6 whereto; static struct sockaddr_in6 firsthop; static unsigned char cmsgbuf[4096]; -static int cmsglen = 0; +static size_t cmsglen = 0; static int pr_icmph(__u8 type, __u8 code, __u32 info); void ping6_usage(unsigned) __attribute((noreturn)); @@ -444,7 +444,7 @@ static int niquery_option_subject_name_handler(int index, const char *name) static char nigroup_buf[INET6_ADDRSTRLEN + 1 + IFNAMSIZ]; unsigned char *dnptrs[2], **dpp, **lastdnptr; int n; - int i; + size_t i; char *p; char *canonname = NULL, *idn = NULL; unsigned char *buf = NULL; @@ -517,7 +517,7 @@ static int niquery_option_subject_name_handler(int index, const char *name) if (n < 0) { fprintf(stderr, "ping6: Inappropriate subject name: %s\n", canonname); goto errexit; - } else if (n >= buflen) { + } else if ((size_t) n >= buflen) { fprintf(stderr, "ping6: dn_comp() returned too long result.\n"); goto errexit; } @@ -617,7 +617,7 @@ int ping6_run(int argc, char **argv, struct addrinfo *ai, struct socket_st *sock struct in6_addr *addr; if (srcrt == NULL) { - int space; + size_t space; fprintf(stderr, "ping6: Warning: " "Source routing is deprecated by RFC5095.\n"); @@ -868,7 +868,7 @@ int ping6_run(int argc, char **argv, struct addrinfo *ai, struct socket_st *sock exit(2); } - if (datalen >= sizeof(struct timeval) && (ni_query < 0)) { + if ((ssize_t) datalen >= (ssize_t) sizeof(struct timeval) && (ni_query < 0)) { /* can we time transfer */ timing = 1; } @@ -1034,7 +1034,7 @@ int ping6_run(int argc, char **argv, struct addrinfo *ai, struct socket_st *sock int ping6_receive_error_msg(socket_st *sock) { - int res; + ssize_t res; char cbuf[512]; struct iovec iov; struct msghdr msg; @@ -1084,7 +1084,7 @@ int ping6_receive_error_msg(socket_st *sock) } else if (e->ee_origin == SO_EE_ORIGIN_ICMP6) { struct sockaddr_in6 *sin6 = (struct sockaddr_in6*)(e+1); - if (res < sizeof(icmph) || + if ((size_t) res < sizeof(icmph) || memcmp(&target.sin6_addr, &whereto.sin6_addr, 16) || icmph.icmp6_type != ICMP6_ECHO_REQUEST || !is_ours(sock, icmph.icmp6_id)) { @@ -1234,7 +1234,7 @@ void pr_niquery_reply_name(struct ni_hdr *nih, int len) } while (p < end) { int fqdn = 1; - int i; + size_t i; memset(buf, 0xff, sizeof(buf)); @@ -1420,7 +1420,7 @@ ping6_parse_reply(socket_st *sock, struct msghdr *msg, int cc, void *addr, struc * using RECVRERR. :-) */ - if (cc < 8+sizeof(struct ip6_hdr)+8) + if (cc < (int) (8 + sizeof(struct ip6_hdr) + 8)) return 1; if (memcmp(&iph1->ip6_dst, &whereto.sin6_addr, 16)) diff --git a/ping_common.c b/ping_common.c index 041105d6..2226d0d5 100644 --- a/ping_common.c +++ b/ping_common.c @@ -233,7 +233,7 @@ void drop_capabilities(void) */ void fill(char *patp, void *packet, unsigned packet_size) { - int ii, jj, kk; + int ii, jj; int pat[16]; char *cp; unsigned char *bp = packet+8; @@ -256,6 +256,7 @@ void fill(char *patp, void *packet, unsigned packet_size) &pat[13], &pat[14], &pat[15]); if (ii > 0) { + unsigned kk; for (kk = 0; kk <= packet_size - (8 + ii); kk += ii) for (jj = 0; jj < ii; ++jj) bp[jj + kk] = pat[jj]; @@ -295,12 +296,12 @@ int __schedule_exit(int next) if (nreceived) { waittime = 2 * tmax; - if (waittime < 1000*interval) + if (waittime < (unsigned long) (1000*interval)) waittime = 1000*interval; } else waittime = lingertime*1000; - if (next < 0 || next < waittime/1000) + if (next < 0 || (unsigned long)next < waittime/1000) next = waittime/1000; it.it_interval.tv_sec = 0; @@ -782,7 +783,7 @@ int gather_statistics(__u8 *icmph, int icmplen, if (!csfailed) acknowledge(seq); - if (timing && cc >= 8+sizeof(struct timeval)) { + if (timing && cc >= (int) (8+sizeof(struct timeval))) { struct timeval tmp_tv; memcpy(&tmp_tv, ptr, sizeof(tmp_tv)); diff --git a/rarpd.c b/rarpd.c index aa407088..fde99a27 100644 --- a/rarpd.c +++ b/rarpd.c @@ -420,7 +420,7 @@ void serve_it(int fd) struct arphdr *a = (struct arphdr*)buf; struct rarp_map *rmap; unsigned char *ptr; - int n; + ssize_t n; n = recvfrom(fd, buf, sizeof(buf), MSG_DONTWAIT, (struct sockaddr*)&sll, &sll_len); if (n<0) { @@ -438,8 +438,8 @@ void serve_it(int fd) if (ifidx && sll.sll_ifindex != ifidx) return; - if (nar_hln > n) { - syslog(LOG_ERR, "truncated rarp request; len=%d", n); + if (sizeof(*a) + 2*4 + 2*a->ar_hln > (size_t) n) { + syslog(LOG_ERR, "truncated rarp request; len=%zu", n); return; } /* 5. Silly check: if this guy set different source diff --git a/rdisc.c b/rdisc.c index 1aaec9ea..f81fb111 100644 --- a/rdisc.c +++ b/rdisc.c @@ -778,7 +778,7 @@ pr_pack(char *buf, int cc, struct sockaddr_in *from) rap->icmp_wpa); return; } - if ((unsigned)cc < + if (cc < 8 + rap->icmp_num_addrs * rap->icmp_wpa * 4) { if (verbose) logtrace("ICMP %s from %s: Too short %d, %d\n", @@ -1363,7 +1363,7 @@ age_table(int time) if (recalculate_max) { int max_pref = max_preference(); - if (max_pref != INELIGIBLE_PREF) { + if (max_pref != (int) INELIGIBLE_PREF) { tp = table; while (tp) { if (tp->preference == max_pref && !tp->in_kernel) { @@ -1433,18 +1433,18 @@ record_router(struct in_addr router, int pref, int ttl) } if (!tp->in_kernel && (!best_preference || tp->preference == max_preference()) && - tp->preference != INELIGIBLE_PREF) { + tp->preference != (int) INELIGIBLE_PREF) { add_route(tp->router); tp->in_kernel++; } - if (tp->preference == INELIGIBLE_PREF && tp->in_kernel) { + if (tp->preference == (int) INELIGIBLE_PREF && tp->in_kernel) { del_route(tp->router); tp->in_kernel = 0; } if (best_preference && changed_down) { /* Check if we should add routes */ int new_max = max_preference(); - if (new_max != INELIGIBLE_PREF) { + if (new_max != (int) INELIGIBLE_PREF) { tp = table; while (tp) { if (tp->preference == new_max && diff --git a/traceroute6.c b/traceroute6.c index aee669b8..92506786 100644 --- a/traceroute6.c +++ b/traceroute6.c @@ -290,8 +290,8 @@ unsigned char packet[512]; /* last inbound (icmp) packet */ int wait_for_reply(int, struct sockaddr_in6 *, struct in6_addr *, int); int packet_ok(unsigned char *buf, int cc, struct sockaddr_in6 *from, - struct in6_addr *to, int seq, struct timeval *); -void send_probe(int seq, int ttl); + struct in6_addr *to, uint32_t seq, struct timeval *); +void send_probe(uint32_t seq, int ttl); double deltaT (struct timeval *, struct timeval *); void print(unsigned char *buf, int cc, struct sockaddr_in6 *from); void tvsub (struct timeval *, struct timeval *); @@ -341,7 +341,8 @@ int main(int argc, char *argv[]) struct addrinfo *result; int status; struct sockaddr_in6 from, *to; - int ch, i, on, probe, seq, tos, ttl; + int ch, i, on, probe, tos, ttl; + uint32_t seq; int socket_errno; char *resolved_hostname = NULL; @@ -732,7 +733,7 @@ wait_for_reply(sock, from, to, reset_timer) } -void send_probe(int seq, int ttl) +void send_probe(uint32_t seq, int ttl) { struct pkt_format *pkt = (struct pkt_format *) sendbuff; int i; @@ -831,7 +832,7 @@ char * pr_type(unsigned char t) int packet_ok(unsigned char *buf, int cc, struct sockaddr_in6 *from, - struct in6_addr *to, int seq, + struct in6_addr *to, uint32_t seq, struct timeval *tv) { struct icmp6_hdr *icp; @@ -863,7 +864,7 @@ int packet_ok(unsigned char *buf, int cc, struct sockaddr_in6 *from, pkt = (struct pkt_format *) (up + 1); - if (ntohl(pkt->ident) == ident && + if (ntohl(pkt->ident) == (uint32_t) ident && ntohl(pkt->seq) == seq) { *tv = pkt->tv;