1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 20:51:30 +00:00

Moar const

This commit is contained in:
dmiller
2021-04-26 17:58:01 +00:00
parent d142d1f808
commit c9b7c2f590
11 changed files with 58 additions and 58 deletions

View File

@@ -171,7 +171,7 @@ static char *split_netmask(const char *expr, int *bits) {
slash = strrchr(expr, '/'); slash = strrchr(expr, '/');
if (slash != NULL) { if (slash != NULL) {
long l; long l;
char *tail; const char *tail;
l = parse_long(slash + 1, &tail); l = parse_long(slash + 1, &tail);
if (tail == slash + 1 || *tail != '\0' || l < 0 || l > INT_MAX) if (tail == slash + 1 || *tail != '\0' || l < 0 || l > INT_MAX)
@@ -203,7 +203,7 @@ static int parse_ipv4_ranges(octet_bitvector octets[4], const char *spec) {
} else { } else {
for (;;) { for (;;) {
long start, end; long start, end;
char *tail; const char *tail;
errno = 0; errno = 0;
start = parse_long(p, &tail); start = parse_long(p, &tail);

View File

@@ -435,7 +435,7 @@ char *escape_windows_command_arg(const char *arg);
/* parse_long is like strtol or atoi, but it allows digits only. /* parse_long is like strtol or atoi, but it allows digits only.
No whitespace, sign, or radix prefix. */ No whitespace, sign, or radix prefix. */
long parse_long(const char *s, char **tail); long parse_long(const char *s, const char **tail);
/* This function takes a byte count and stores a short ascii equivalent /* This function takes a byte count and stores a short ascii equivalent
in the supplied buffer. Eg: 0.122MB, 10.322Kb or 128B. */ in the supplied buffer. Eg: 0.122MB, 10.322Kb or 128B. */

View File

@@ -602,7 +602,7 @@ int addrset_add_spec(struct addrset *set, const char *spec, int af, int dns)
{ {
char *local_spec; char *local_spec;
char *netmask_s; char *netmask_s;
char *tail; const char *tail;
long netmask_bits; long netmask_bits;
struct addrinfo *addrs, *addr; struct addrinfo *addrs, *addr;
struct addrset_elem *elem; struct addrset_elem *elem;
@@ -789,7 +789,7 @@ static int parse_ipv4_ranges(struct addrset_elem *elem, const char *spec)
} else { } else {
for (;;) { for (;;) {
long start, end; long start, end;
char *tail; const char *tail;
errno = 0; errno = 0;
start = parse_long(p, &tail); start = parse_long(p, &tail);

View File

@@ -700,7 +700,7 @@ char *hexdump(const u8 *cp, u32 length){
/* This is like strtol or atoi, but it allows digits only. No whitespace, sign, /* This is like strtol or atoi, but it allows digits only. No whitespace, sign,
or radix prefix. */ or radix prefix. */
long parse_long(const char *s, char **tail) long parse_long(const char *s, const char **tail)
{ {
if (!isdigit((int) (unsigned char) *s)) { if (!isdigit((int) (unsigned char) *s)) {
*tail = (char *) s; *tail = (char *) s;

View File

@@ -396,7 +396,7 @@ struct uri *uri_parse_authority(struct uri *uri, const char *authority)
{ {
const char *portsep; const char *portsep;
const char *host_start, *host_end; const char *host_start, *host_end;
char *tail; const char *tail;
/* We do not support "user:pass@" userinfo. The proxy has no use for it. */ /* We do not support "user:pass@" userinfo. The proxy has no use for it. */
if (strchr(authority, '@') != NULL) if (strchr(authority, '@') != NULL)
@@ -996,7 +996,7 @@ int http_parse_header(struct http_header **result, const char *header)
static int http_header_get_content_length(const struct http_header *header, int *content_length_set, unsigned long *content_length) static int http_header_get_content_length(const struct http_header *header, int *content_length_set, unsigned long *content_length)
{ {
char *content_length_s; char *content_length_s;
char *tail; const char *tail;
int code; int code;
content_length_s = http_header_get_first(header, "Content-Length"); content_length_s = http_header_get_first(header, "Content-Length");
@@ -1010,7 +1010,7 @@ static int http_header_get_content_length(const struct http_header *header, int
errno = 0; errno = 0;
*content_length_set = 1; *content_length_set = 1;
*content_length = parse_long(content_length_s, (char **) &tail); *content_length = parse_long(content_length_s, &tail);
if (errno != 0 || *tail != '\0' || tail == content_length_s) if (errno != 0 || *tail != '\0' || tail == content_length_s)
code = 400; code = 400;
free(content_length_s); free(content_length_s);
@@ -1088,7 +1088,7 @@ static const char *parse_http_version(const char *s, enum http_version *version)
/* Major version. */ /* Major version. */
errno = 0; errno = 0;
major = parse_long(p, (char **) &q); major = parse_long(p, &q);
if (errno != 0 || q == p) if (errno != 0 || q == p)
return s; return s;
@@ -1099,7 +1099,7 @@ static const char *parse_http_version(const char *s, enum http_version *version)
/* Minor version. */ /* Minor version. */
errno = 0; errno = 0;
minor = parse_long(p, (char **) &q); minor = parse_long(p, &q);
if (errno != 0 || q == p) if (errno != 0 || q == p)
return s; return s;
@@ -1212,7 +1212,7 @@ int http_parse_status_line(const char *line, struct http_response *response)
/* Status code. */ /* Status code. */
errno = 0; errno = 0;
response->code = parse_long(p, (char **) &q); response->code = parse_long(p, &q);
if (errno != 0 || q == p) if (errno != 0 || q == p)
return -1; return -1;
p = q; p = q;

View File

@@ -235,7 +235,7 @@ static int percent_decode(char *s) {
static int uri_parse_authority(const char *authority, struct uri *uri) { static int uri_parse_authority(const char *authority, struct uri *uri) {
const char *portsep; const char *portsep;
const char *host_start, *host_end; const char *host_start, *host_end;
char *tail; const char *tail;
/* We do not support "user:pass@" userinfo. The proxy has no use for it. */ /* We do not support "user:pass@" userinfo. The proxy has no use for it. */
if (strchr(authority, '@') != NULL) if (strchr(authority, '@') != NULL)

View File

@@ -459,9 +459,9 @@ int get_ping_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
bool adjust_timing = true; bool adjust_timing = true;
struct timeval rcvdtime; struct timeval rcvdtime;
struct link_header linkhdr; struct link_header linkhdr;
struct ip *ip_tmp; const struct ip *ip_tmp;
unsigned int bytes; unsigned int bytes;
struct ppkt *ping; const struct ppkt *ping;
long to_usec; long to_usec;
HostScanStats *hss = NULL; HostScanStats *hss = NULL;
std::list<UltraProbe *>::iterator probeI; std::list<UltraProbe *>::iterator probeI;
@@ -636,18 +636,18 @@ int get_ping_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
if (probe->icmpid() != ntohs(((struct icmp *) encaps_data)->icmp_id)) if (probe->icmpid() != ntohs(((struct icmp *) encaps_data)->icmp_id))
continue; continue;
} else if (encaps_hdr.proto == IPPROTO_TCP && USI->ptech.rawtcpscan) { } else if (encaps_hdr.proto == IPPROTO_TCP && USI->ptech.rawtcpscan) {
struct tcp_hdr *tcp = (struct tcp_hdr *) encaps_data; const struct tcp_hdr *tcp = (struct tcp_hdr *) encaps_data;
if (probe->dport() != ntohs(tcp->th_dport) || if (probe->dport() != ntohs(tcp->th_dport) ||
probe->sport() != ntohs(tcp->th_sport) || probe->sport() != ntohs(tcp->th_sport) ||
probe->tcpseq() != ntohl(tcp->th_seq)) probe->tcpseq() != ntohl(tcp->th_seq))
continue; continue;
} else if (encaps_hdr.proto == IPPROTO_UDP && USI->ptech.rawudpscan) { } else if (encaps_hdr.proto == IPPROTO_UDP && USI->ptech.rawudpscan) {
struct udp_hdr *udp = (struct udp_hdr *) encaps_data; const struct udp_hdr *udp = (struct udp_hdr *) encaps_data;
if (probe->dport() != ntohs(udp->uh_dport) || if (probe->dport() != ntohs(udp->uh_dport) ||
probe->sport() != ntohs(udp->uh_sport)) probe->sport() != ntohs(udp->uh_sport))
continue; continue;
} else if (encaps_hdr.proto == IPPROTO_SCTP && USI->ptech.rawsctpscan) { } else if (encaps_hdr.proto == IPPROTO_SCTP && USI->ptech.rawsctpscan) {
struct sctp_hdr *sctp = (struct sctp_hdr *) encaps_data; const struct sctp_hdr *sctp = (struct sctp_hdr *) encaps_data;
if (probe->dport() != ntohs(sctp->sh_dport) || if (probe->dport() != ntohs(sctp->sh_dport) ||
probe->sport() != ntohs(sctp->sh_sport) || probe->sport() != ntohs(sctp->sh_sport) ||
probe->sctpvtag() != ntohl(sctp->sh_vtag)) probe->sctpvtag() != ntohl(sctp->sh_vtag))
@@ -726,7 +726,7 @@ int get_ping_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
} }
} }
} else if (hdr.proto == IPPROTO_TCP && USI->ptech.rawtcpscan) { } else if (hdr.proto == IPPROTO_TCP && USI->ptech.rawtcpscan) {
struct tcp_hdr *tcp = (struct tcp_hdr *) data; const struct tcp_hdr *tcp = (struct tcp_hdr *) data;
/* Check that the packet has useful flags. */ /* Check that the packet has useful flags. */
if (o.discovery_ignore_rst if (o.discovery_ignore_rst
&& (tcp->th_flags & TH_RST)) && (tcp->th_flags & TH_RST))
@@ -772,7 +772,7 @@ int get_ping_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
log_write(LOG_STDOUT, "We got a TCP ping packet back from %s port %hu (trynum = %d)\n", inet_ntop_ez(&hdr.src, sizeof(hdr.src)), ntohs(tcp->th_sport), trynum); log_write(LOG_STDOUT, "We got a TCP ping packet back from %s port %hu (trynum = %d)\n", inet_ntop_ez(&hdr.src, sizeof(hdr.src)), ntohs(tcp->th_sport), trynum);
} }
} else if (hdr.proto == IPPROTO_UDP && USI->ptech.rawudpscan) { } else if (hdr.proto == IPPROTO_UDP && USI->ptech.rawudpscan) {
struct udp_hdr *udp = (struct udp_hdr *) data; const struct udp_hdr *udp = (struct udp_hdr *) data;
/* Search for this host on the incomplete list */ /* Search for this host on the incomplete list */
hss = USI->findHost(&hdr.src); hss = USI->findHost(&hdr.src);
if (!hss) if (!hss)
@@ -820,8 +820,8 @@ int get_ping_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
log_write(LOG_STDOUT, "In response to UDP-ping, we got UDP packet back from %s port %hu (trynum = %d)\n", inet_ntop_ez(&hdr.src, sizeof(hdr.src)), htons(udp->uh_sport), trynum); log_write(LOG_STDOUT, "In response to UDP-ping, we got UDP packet back from %s port %hu (trynum = %d)\n", inet_ntop_ez(&hdr.src, sizeof(hdr.src)), htons(udp->uh_sport), trynum);
} }
} else if (hdr.proto == IPPROTO_SCTP && USI->ptech.rawsctpscan) { } else if (hdr.proto == IPPROTO_SCTP && USI->ptech.rawsctpscan) {
struct sctp_hdr *sctp = (struct sctp_hdr *) data; const struct sctp_hdr *sctp = (struct sctp_hdr *) data;
struct dnet_sctp_chunkhdr *chunk = const struct dnet_sctp_chunkhdr *chunk =
(struct dnet_sctp_chunkhdr *) ((u8 *) sctp + 12); (struct dnet_sctp_chunkhdr *) ((u8 *) sctp + 12);
/* Search for this host on the incomplete list */ /* Search for this host on the incomplete list */
hss = USI->findHost(&hdr.src); hss = USI->findHost(&hdr.src);
@@ -1747,7 +1747,7 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
gettimeofday(&USI->now, NULL); gettimeofday(&USI->now, NULL);
do { do {
struct ip *ip_tmp; const struct ip *ip_tmp;
to_usec = TIMEVAL_SUBTRACT(*stime, USI->now); to_usec = TIMEVAL_SUBTRACT(*stime, USI->now);
if (to_usec < 2000) if (to_usec < 2000)
@@ -1807,7 +1807,7 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
} }
if (hdr.proto == IPPROTO_TCP && !USI->prot_scan) { if (hdr.proto == IPPROTO_TCP && !USI->prot_scan) {
struct tcp_hdr *tcp = (struct tcp_hdr *) data; const struct tcp_hdr *tcp = (struct tcp_hdr *) data;
/* Now ensure this host is even in the incomplete list */ /* Now ensure this host is even in the incomplete list */
hss = USI->findHost(&hdr.src); hss = USI->findHost(&hdr.src);
if (!hss) if (!hss)
@@ -1853,8 +1853,8 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
goodone = true; goodone = true;
} }
} else if (hdr.proto == IPPROTO_SCTP && !USI->prot_scan) { } else if (hdr.proto == IPPROTO_SCTP && !USI->prot_scan) {
struct sctp_hdr *sctp = (struct sctp_hdr *) data; const struct sctp_hdr *sctp = (struct sctp_hdr *) data;
struct dnet_sctp_chunkhdr *chunk = (struct dnet_sctp_chunkhdr *) ((u8 *) sctp + 12); const struct dnet_sctp_chunkhdr *chunk = (struct dnet_sctp_chunkhdr *) ((u8 *) sctp + 12);
/* Now ensure this host is even in the incomplete list */ /* Now ensure this host is even in the incomplete list */
hss = USI->findHost(&hdr.src); hss = USI->findHost(&hdr.src);
@@ -1924,7 +1924,7 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
const void *encaps_data; const void *encaps_data;
unsigned int encaps_len; unsigned int encaps_len;
struct abstract_ip_hdr encaps_hdr; struct abstract_ip_hdr encaps_hdr;
struct icmp *icmp = NULL; const struct icmp *icmp = NULL;
icmp = (struct icmp *) data; icmp = (struct icmp *) data;
@@ -1980,20 +1980,20 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
continue; continue;
if (encaps_hdr.proto == IPPROTO_TCP && !USI->prot_scan) { if (encaps_hdr.proto == IPPROTO_TCP && !USI->prot_scan) {
struct tcp_hdr *tcp = (struct tcp_hdr *) encaps_data; const struct tcp_hdr *tcp = (struct tcp_hdr *) encaps_data;
if (ntohs(tcp->th_sport) != probe->sport() || if (ntohs(tcp->th_sport) != probe->sport() ||
ntohs(tcp->th_dport) != probe->dport() || ntohs(tcp->th_dport) != probe->dport() ||
ntohl(tcp->th_seq) != probe->tcpseq()) ntohl(tcp->th_seq) != probe->tcpseq())
continue; continue;
} else if (encaps_hdr.proto == IPPROTO_SCTP && !USI->prot_scan) { } else if (encaps_hdr.proto == IPPROTO_SCTP && !USI->prot_scan) {
struct sctp_hdr *sctp = (struct sctp_hdr *) encaps_data; const struct sctp_hdr *sctp = (struct sctp_hdr *) encaps_data;
if (ntohs(sctp->sh_sport) != probe->sport() || if (ntohs(sctp->sh_sport) != probe->sport() ||
ntohs(sctp->sh_dport) != probe->dport() || ntohs(sctp->sh_dport) != probe->dport() ||
ntohl(sctp->sh_vtag) != probe->sctpvtag()) ntohl(sctp->sh_vtag) != probe->sctpvtag())
continue; continue;
} else if (encaps_hdr.proto == IPPROTO_UDP && !USI->prot_scan) { } else if (encaps_hdr.proto == IPPROTO_UDP && !USI->prot_scan) {
/* TODO: IPID verification */ /* TODO: IPID verification */
struct udp_hdr *udp = (struct udp_hdr *) encaps_data; const struct udp_hdr *udp = (struct udp_hdr *) encaps_data;
if (ntohs(udp->uh_sport) != probe->sport() || if (ntohs(udp->uh_sport) != probe->sport() ||
ntohs(udp->uh_dport) != probe->dport()) ntohs(udp->uh_dport) != probe->dport())
continue; continue;
@@ -2109,20 +2109,20 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
continue; continue;
if (encaps_hdr.proto == IPPROTO_TCP && !USI->prot_scan) { if (encaps_hdr.proto == IPPROTO_TCP && !USI->prot_scan) {
struct tcp_hdr *tcp = (struct tcp_hdr *) encaps_data; const struct tcp_hdr *tcp = (struct tcp_hdr *) encaps_data;
if (ntohs(tcp->th_sport) != probe->sport() || if (ntohs(tcp->th_sport) != probe->sport() ||
ntohs(tcp->th_dport) != probe->dport() || ntohs(tcp->th_dport) != probe->dport() ||
ntohl(tcp->th_seq) != probe->tcpseq()) ntohl(tcp->th_seq) != probe->tcpseq())
continue; continue;
} else if (encaps_hdr.proto == IPPROTO_SCTP && !USI->prot_scan) { } else if (encaps_hdr.proto == IPPROTO_SCTP && !USI->prot_scan) {
struct sctp_hdr *sctp = (struct sctp_hdr *) encaps_data; const struct sctp_hdr *sctp = (struct sctp_hdr *) encaps_data;
if (ntohs(sctp->sh_sport) != probe->sport() || if (ntohs(sctp->sh_sport) != probe->sport() ||
ntohs(sctp->sh_dport) != probe->dport() || ntohs(sctp->sh_dport) != probe->dport() ||
ntohl(sctp->sh_vtag) != probe->sctpvtag()) ntohl(sctp->sh_vtag) != probe->sctpvtag())
continue; continue;
} else if (encaps_hdr.proto == IPPROTO_UDP && !USI->prot_scan) { } else if (encaps_hdr.proto == IPPROTO_UDP && !USI->prot_scan) {
/* TODO: IPID verification */ /* TODO: IPID verification */
struct udp_hdr *udp = (struct udp_hdr *) encaps_data; const struct udp_hdr *udp = (struct udp_hdr *) encaps_data;
if (ntohs(udp->uh_sport) != probe->sport() || if (ntohs(udp->uh_sport) != probe->sport() ||
ntohs(udp->uh_dport) != probe->dport()) ntohs(udp->uh_dport) != probe->dport())
continue; continue;
@@ -2206,7 +2206,7 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
goodone = true; goodone = true;
} }
} else if (hdr.proto == IPPROTO_UDP && !USI->prot_scan) { } else if (hdr.proto == IPPROTO_UDP && !USI->prot_scan) {
struct udp_hdr *udp = (struct udp_hdr *) data; const struct udp_hdr *udp = (struct udp_hdr *) data;
/* Search for this host on the incomplete list */ /* Search for this host on the incomplete list */
hss = USI->findHost(&hdr.src); hss = USI->findHost(&hdr.src);
@@ -2296,7 +2296,7 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
if (probe->isPing()) if (probe->isPing())
ultrascan_ping_update(USI, hss, probeI, &rcvdtime, adjust_timing); ultrascan_ping_update(USI, hss, probeI, &rcvdtime, adjust_timing);
else { else {
struct icmp *icmp = (struct icmp *) data; const struct icmp *icmp = (struct icmp *) data;
ultrascan_port_probe_update(USI, hss, probeI, PORT_OPEN, &rcvdtime, adjust_timing); ultrascan_port_probe_update(USI, hss, probeI, PORT_OPEN, &rcvdtime, adjust_timing);
if (sockaddr_storage_cmp(&hdr.src, &protoscanicmphackaddy) == 0) if (sockaddr_storage_cmp(&hdr.src, &protoscanicmphackaddy) == 0)
reason_sip.ss_family = AF_UNSPEC; reason_sip.ss_family = AF_UNSPEC;

View File

@@ -191,9 +191,9 @@ void PacketTrace::traceArp(pdirection pdir, const u8 *frame, u32 len,
void PacketTrace::traceND(pdirection pdir, const u8 *frame, u32 len, void PacketTrace::traceND(pdirection pdir, const u8 *frame, u32 len,
struct timeval *now) { struct timeval *now) {
struct timeval tv; struct timeval tv;
struct ip6_hdr *ip6; const struct ip6_hdr *ip6;
struct icmpv6_hdr *icmpv6; const struct icmpv6_hdr *icmpv6;
union icmpv6_msg *msg; const union icmpv6_msg *msg;
size_t msg_len; size_t msg_len;
const char *label; const char *label;
char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN]; char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN];
@@ -326,9 +326,9 @@ void PacketTrace::traceConnect(u8 proto, const struct sockaddr *sock,
int socklen, int connectrc, int socklen, int connectrc,
int connect_errno, int connect_errno,
const struct timeval *now) { const struct timeval *now) {
struct sockaddr_in *sin = (struct sockaddr_in *) sock; const struct sockaddr_in *sin = (struct sockaddr_in *) sock;
#if HAVE_IPV6 #if HAVE_IPV6
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sock; const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sock;
#endif #endif
struct timeval tv; struct timeval tv;
char errbuf[64] = ""; char errbuf[64] = "";
@@ -386,11 +386,11 @@ void PacketTrace::traceConnect(u8 proto, const struct sockaddr *sock,
/* Converts an IP address given in a sockaddr_storage to an IPv4 or /* Converts an IP address given in a sockaddr_storage to an IPv4 or
IPv6 IP address string. Since a static buffer is returned, this is IPv6 IP address string. Since a static buffer is returned, this is
not thread-safe and can only be used once in calls like printf() */ not thread-safe and can only be used once in calls like printf() */
const char *inet_socktop(struct sockaddr_storage *ss) { const char *inet_socktop(const struct sockaddr_storage *ss) {
static char buf[INET6_ADDRSTRLEN]; static char buf[INET6_ADDRSTRLEN];
struct sockaddr_in *sin = (struct sockaddr_in *) ss; const struct sockaddr_in *sin = (struct sockaddr_in *) ss;
#if HAVE_IPV6 #if HAVE_IPV6
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) ss; const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) ss;
#endif #endif
if (inet_ntop(sin->sin_family, (sin->sin_family == AF_INET) ? if (inet_ntop(sin->sin_family, (sin->sin_family == AF_INET) ?
@@ -435,7 +435,7 @@ struct addrinfo *resolve_all(const char *hostname, int pf) {
static int send_ipv4_packet(int sd, const struct eth_nfo *eth, static int send_ipv4_packet(int sd, const struct eth_nfo *eth,
const struct sockaddr_in *dst, const struct sockaddr_in *dst,
const u8 *packet, unsigned int packetlen) { const u8 *packet, unsigned int packetlen) {
struct ip *ip = (struct ip *) packet; const struct ip *ip = (struct ip *) packet;
int res; int res;
assert(packet); assert(packet);
@@ -469,7 +469,7 @@ static int send_ipv6_packet(int sd, const struct eth_nfo *eth,
int send_ip_packet(int sd, const struct eth_nfo *eth, int send_ip_packet(int sd, const struct eth_nfo *eth,
const struct sockaddr_storage *dst, const struct sockaddr_storage *dst,
const u8 *packet, unsigned int packetlen) { const u8 *packet, unsigned int packetlen) {
struct ip *ip = (struct ip *) packet; const struct ip *ip = (struct ip *) packet;
/* Ensure there's enough to read ip->ip_v at least. */ /* Ensure there's enough to read ip->ip_v at least. */
if (packetlen < 1) if (packetlen < 1)
@@ -1159,8 +1159,8 @@ u8 *build_igmp_raw(const struct in_addr *source,
of a TCP packet*/ of a TCP packet*/
int readtcppacket(const u8 *packet, int readdata) { int readtcppacket(const u8 *packet, int readdata) {
struct ip *ip = (struct ip *) packet; const struct ip *ip = (struct ip *) packet;
struct tcp_hdr *tcp = (struct tcp_hdr *) (packet + sizeof(struct ip)); const struct tcp_hdr *tcp = (struct tcp_hdr *) (packet + sizeof(struct ip));
const unsigned char *data = packet + sizeof(struct ip) + sizeof(struct tcp_hdr); const unsigned char *data = packet + sizeof(struct ip) + sizeof(struct tcp_hdr);
int tot_len; int tot_len;
struct in_addr bullshit, bullshit2; struct in_addr bullshit, bullshit2;
@@ -1235,8 +1235,8 @@ int readtcppacket(const u8 *packet, int readdata) {
/* A simple function I wrote to help in debugging, shows the important fields /* A simple function I wrote to help in debugging, shows the important fields
of a UDP packet*/ of a UDP packet*/
int readudppacket(const u8 *packet, int readdata) { int readudppacket(const u8 *packet, int readdata) {
struct ip *ip = (struct ip *) packet; const struct ip *ip = (struct ip *) packet;
struct udp_hdr *udp = (struct udp_hdr *) (packet + sizeof(struct ip)); const struct udp_hdr *udp = (struct udp_hdr *) (packet + sizeof(struct ip));
const unsigned char *data = packet + sizeof(struct ip) + sizeof(struct udp_hdr); const unsigned char *data = packet + sizeof(struct ip) + sizeof(struct udp_hdr);
int tot_len; int tot_len;
struct in_addr bullshit, bullshit2; struct in_addr bullshit, bullshit2;
@@ -1283,7 +1283,7 @@ int readudppacket(const u8 *packet, int readdata) {
/* Used by validatepkt() to validate the TCP header (including option lengths). /* Used by validatepkt() to validate the TCP header (including option lengths).
The options checked are MSS, WScale, SackOK, Sack, and Timestamp. */ The options checked are MSS, WScale, SackOK, Sack, and Timestamp. */
static bool validateTCPhdr(const u8 *tcpc, unsigned len) { static bool validateTCPhdr(const u8 *tcpc, unsigned len) {
struct tcp_hdr *tcp = (struct tcp_hdr *) tcpc; const struct tcp_hdr *tcp = (struct tcp_hdr *) tcpc;
unsigned hdrlen, optlen; unsigned hdrlen, optlen;
hdrlen = tcp->th_off * 4; hdrlen = tcp->th_off * 4;
@@ -1371,7 +1371,7 @@ static bool validateTCPhdr(const u8 *tcpc, unsigned len) {
* data to the caller. * data to the caller.
*/ */
static bool validatepkt(const u8 *ipc, unsigned *len) { static bool validatepkt(const u8 *ipc, unsigned *len) {
struct ip *ip = (struct ip *) ipc; const struct ip *ip = (struct ip *) ipc;
const void *data; const void *data;
unsigned int datalen, iplen; unsigned int datalen, iplen;
u8 hdr; u8 hdr;
@@ -1492,7 +1492,7 @@ static bool accept_any (const unsigned char *p, const struct pcap_pkthdr *h, int
} }
static bool accept_ip (const unsigned char *p, const struct pcap_pkthdr *h, int datalink, size_t offset) { static bool accept_ip (const unsigned char *p, const struct pcap_pkthdr *h, int datalink, size_t offset) {
struct ip *ip = NULL; const struct ip *ip = NULL;
if (h->caplen < offset + sizeof(struct ip)) { if (h->caplen < offset + sizeof(struct ip)) {
return false; return false;

View File

@@ -136,7 +136,7 @@ class PacketCounter {
IPv6 IP address string. Since a static buffer is returned, this is IPv6 IP address string. Since a static buffer is returned, this is
not thread-safe and can only be used once in calls like printf() not thread-safe and can only be used once in calls like printf()
*/ */
const char *inet_socktop(struct sockaddr_storage *ss); const char *inet_socktop(const struct sockaddr_storage *ss);
/* Tries to resolve the given name (or literal IP) into a sockaddr /* Tries to resolve the given name (or literal IP) into a sockaddr
structure. This function calls getaddrinfo and returns the same structure. This function calls getaddrinfo and returns the same

View File

@@ -412,7 +412,7 @@ char *cstring_unescape(char *str, unsigned int *newlen) {
} }
void bintohexstr(char *buf, int buflen, char *src, int srclen) { void bintohexstr(char *buf, int buflen, const char *src, int srclen) {
int bp = 0; int bp = 0;
int i; int i;
@@ -439,12 +439,12 @@ void bintohexstr(char *buf, int buflen, char *src, int srclen) {
* hex spec or NULL in case of error. * hex spec or NULL in case of error.
* @warning Returned pointer points to a static buffer that subsequent calls * @warning Returned pointer points to a static buffer that subsequent calls
* will overwrite. */ * will overwrite. */
u8 *parse_hex_string(char *str, size_t *outlen) { u8 *parse_hex_string(const char *str, size_t *outlen) {
char auxbuff[4096]; char auxbuff[4096];
static u8 dst[16384]; static u8 dst[16384];
size_t dstlen=16384; size_t dstlen=16384;
unsigned int i=0, j=0; unsigned int i=0, j=0;
char *start=NULL; const char *start=NULL;
if(str==NULL || outlen==NULL) if(str==NULL || outlen==NULL)
return NULL; return NULL;

View File

@@ -115,9 +115,9 @@ void arg_parse_free(char **argv);
char *cstring_unescape(char *str, unsigned int *len); char *cstring_unescape(char *str, unsigned int *len);
void bintohexstr(char *buf, int buflen, char *src, int srclen); void bintohexstr(char *buf, int buflen, const char *src, int srclen);
u8 *parse_hex_string(char *str, size_t *outlen); u8 *parse_hex_string(const char *str, size_t *outlen);
int cpe_get_part(const char *cpe); int cpe_get_part(const char *cpe);