Skip to content

Commit

Permalink
Moar const
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Apr 26, 2021
1 parent d142d1f commit c9b7c2f
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 58 deletions.
4 changes: 2 additions & 2 deletions TargetGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static char *split_netmask(const char *expr, int *bits) {
slash = strrchr(expr, '/');
if (slash != NULL) {
long l;
char *tail;
const char *tail;

l = parse_long(slash + 1, &tail);
if (tail == slash + 1 || *tail != '\0' || l < 0 || l > INT_MAX)
Expand Down Expand Up @@ -203,7 +203,7 @@ static int parse_ipv4_ranges(octet_bitvector octets[4], const char *spec) {
} else {
for (;;) {
long start, end;
char *tail;
const char *tail;

errno = 0;
start = parse_long(p, &tail);
Expand Down
2 changes: 1 addition & 1 deletion nbase/nbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ char *escape_windows_command_arg(const char *arg);

/* parse_long is like strtol or atoi, but it allows digits only.
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
in the supplied buffer. Eg: 0.122MB, 10.322Kb or 128B. */
Expand Down
4 changes: 2 additions & 2 deletions nbase/nbase_addrset.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ int addrset_add_spec(struct addrset *set, const char *spec, int af, int dns)
{
char *local_spec;
char *netmask_s;
char *tail;
const char *tail;
long netmask_bits;
struct addrinfo *addrs, *addr;
struct addrset_elem *elem;
Expand Down Expand Up @@ -789,7 +789,7 @@ static int parse_ipv4_ranges(struct addrset_elem *elem, const char *spec)
} else {
for (;;) {
long start, end;
char *tail;
const char *tail;

errno = 0;
start = parse_long(p, &tail);
Expand Down
2 changes: 1 addition & 1 deletion nbase/nbase_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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)) {
*tail = (char *) s;
Expand Down
12 changes: 6 additions & 6 deletions ncat/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ struct uri *uri_parse_authority(struct uri *uri, const char *authority)
{
const char *portsep;
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. */
if (strchr(authority, '@') != NULL)
Expand Down Expand Up @@ -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)
{
char *content_length_s;
char *tail;
const char *tail;
int code;

content_length_s = http_header_get_first(header, "Content-Length");
Expand All @@ -1010,7 +1010,7 @@ static int http_header_get_content_length(const struct http_header *header, int

errno = 0;
*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)
code = 400;
free(content_length_s);
Expand Down Expand Up @@ -1088,7 +1088,7 @@ static const char *parse_http_version(const char *s, enum http_version *version)

/* Major version. */
errno = 0;
major = parse_long(p, (char **) &q);
major = parse_long(p, &q);
if (errno != 0 || q == p)
return s;

Expand All @@ -1099,7 +1099,7 @@ static const char *parse_http_version(const char *s, enum http_version *version)

/* Minor version. */
errno = 0;
minor = parse_long(p, (char **) &q);
minor = parse_long(p, &q);
if (errno != 0 || q == p)
return s;

Expand Down Expand Up @@ -1212,7 +1212,7 @@ int http_parse_status_line(const char *line, struct http_response *response)

/* Status code. */
errno = 0;
response->code = parse_long(p, (char **) &q);
response->code = parse_long(p, &q);
if (errno != 0 || q == p)
return -1;
p = q;
Expand Down
2 changes: 1 addition & 1 deletion nsock/src/nsock_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static int percent_decode(char *s) {
static int uri_parse_authority(const char *authority, struct uri *uri) {
const char *portsep;
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. */
if (strchr(authority, '@') != NULL)
Expand Down
44 changes: 22 additions & 22 deletions scan_engine_raw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@ int get_ping_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
bool adjust_timing = true;
struct timeval rcvdtime;
struct link_header linkhdr;
struct ip *ip_tmp;
const struct ip *ip_tmp;
unsigned int bytes;
struct ppkt *ping;
const struct ppkt *ping;
long to_usec;
HostScanStats *hss = NULL;
std::list<UltraProbe *>::iterator probeI;
Expand Down Expand Up @@ -636,18 +636,18 @@ int get_ping_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
if (probe->icmpid() != ntohs(((struct icmp *) encaps_data)->icmp_id))
continue;
} 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) ||
probe->sport() != ntohs(tcp->th_sport) ||
probe->tcpseq() != ntohl(tcp->th_seq))
continue;
} 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) ||
probe->sport() != ntohs(udp->uh_sport))
continue;
} 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) ||
probe->sport() != ntohs(sctp->sh_sport) ||
probe->sctpvtag() != ntohl(sctp->sh_vtag))
Expand Down Expand Up @@ -726,7 +726,7 @@ int get_ping_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
}
}
} 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. */
if (o.discovery_ignore_rst
&& (tcp->th_flags & TH_RST))
Expand Down Expand Up @@ -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);
}
} 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 */
hss = USI->findHost(&hdr.src);
if (!hss)
Expand Down Expand Up @@ -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);
}
} else if (hdr.proto == IPPROTO_SCTP && USI->ptech.rawsctpscan) {
struct sctp_hdr *sctp = (struct sctp_hdr *) data;
struct dnet_sctp_chunkhdr *chunk =
const struct sctp_hdr *sctp = (struct sctp_hdr *) data;
const struct dnet_sctp_chunkhdr *chunk =
(struct dnet_sctp_chunkhdr *) ((u8 *) sctp + 12);
/* Search for this host on the incomplete list */
hss = USI->findHost(&hdr.src);
Expand Down Expand Up @@ -1747,7 +1747,7 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
gettimeofday(&USI->now, NULL);

do {
struct ip *ip_tmp;
const struct ip *ip_tmp;

to_usec = TIMEVAL_SUBTRACT(*stime, USI->now);
if (to_usec < 2000)
Expand Down Expand Up @@ -1807,7 +1807,7 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
}

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 */
hss = USI->findHost(&hdr.src);
if (!hss)
Expand Down Expand Up @@ -1853,8 +1853,8 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
goodone = true;
}
} else if (hdr.proto == IPPROTO_SCTP && !USI->prot_scan) {
struct sctp_hdr *sctp = (struct sctp_hdr *) data;
struct dnet_sctp_chunkhdr *chunk = (struct dnet_sctp_chunkhdr *) ((u8 *) sctp + 12);
const struct sctp_hdr *sctp = (struct sctp_hdr *) data;
const struct dnet_sctp_chunkhdr *chunk = (struct dnet_sctp_chunkhdr *) ((u8 *) sctp + 12);

/* Now ensure this host is even in the incomplete list */
hss = USI->findHost(&hdr.src);
Expand Down Expand Up @@ -1924,7 +1924,7 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
const void *encaps_data;
unsigned int encaps_len;
struct abstract_ip_hdr encaps_hdr;
struct icmp *icmp = NULL;
const struct icmp *icmp = NULL;

icmp = (struct icmp *) data;

Expand Down Expand Up @@ -1980,20 +1980,20 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
continue;

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() ||
ntohs(tcp->th_dport) != probe->dport() ||
ntohl(tcp->th_seq) != probe->tcpseq())
continue;
} 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() ||
ntohs(sctp->sh_dport) != probe->dport() ||
ntohl(sctp->sh_vtag) != probe->sctpvtag())
continue;
} else if (encaps_hdr.proto == IPPROTO_UDP && !USI->prot_scan) {
/* 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() ||
ntohs(udp->uh_dport) != probe->dport())
continue;
Expand Down Expand Up @@ -2109,20 +2109,20 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
continue;

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() ||
ntohs(tcp->th_dport) != probe->dport() ||
ntohl(tcp->th_seq) != probe->tcpseq())
continue;
} 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() ||
ntohs(sctp->sh_dport) != probe->dport() ||
ntohl(sctp->sh_vtag) != probe->sctpvtag())
continue;
} else if (encaps_hdr.proto == IPPROTO_UDP && !USI->prot_scan) {
/* 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() ||
ntohs(udp->uh_dport) != probe->dport())
continue;
Expand Down Expand Up @@ -2206,7 +2206,7 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
goodone = true;
}
} 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 */
hss = USI->findHost(&hdr.src);
Expand Down Expand Up @@ -2296,7 +2296,7 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
if (probe->isPing())
ultrascan_ping_update(USI, hss, probeI, &rcvdtime, adjust_timing);
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);
if (sockaddr_storage_cmp(&hdr.src, &protoscanicmphackaddy) == 0)
reason_sip.ss_family = AF_UNSPEC;
Expand Down
34 changes: 17 additions & 17 deletions tcpip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ void PacketTrace::traceArp(pdirection pdir, const u8 *frame, u32 len,
void PacketTrace::traceND(pdirection pdir, const u8 *frame, u32 len,
struct timeval *now) {
struct timeval tv;
struct ip6_hdr *ip6;
struct icmpv6_hdr *icmpv6;
union icmpv6_msg *msg;
const struct ip6_hdr *ip6;
const struct icmpv6_hdr *icmpv6;
const union icmpv6_msg *msg;
size_t msg_len;
const char *label;
char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN];
Expand Down Expand Up @@ -326,9 +326,9 @@ void PacketTrace::traceConnect(u8 proto, const struct sockaddr *sock,
int socklen, int connectrc,
int connect_errno,
const struct timeval *now) {
struct sockaddr_in *sin = (struct sockaddr_in *) sock;
const struct sockaddr_in *sin = (struct sockaddr_in *) sock;
#if HAVE_IPV6
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sock;
const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sock;
#endif
struct timeval tv;
char errbuf[64] = "";
Expand Down Expand Up @@ -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
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() */
const char *inet_socktop(struct sockaddr_storage *ss) {
const char *inet_socktop(const struct sockaddr_storage *ss) {
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
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) ss;
const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) ss;
#endif

if (inet_ntop(sin->sin_family, (sin->sin_family == AF_INET) ?
Expand Down Expand Up @@ -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,
const struct sockaddr_in *dst,
const u8 *packet, unsigned int packetlen) {
struct ip *ip = (struct ip *) packet;
const struct ip *ip = (struct ip *) packet;
int res;

assert(packet);
Expand Down Expand Up @@ -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,
const struct sockaddr_storage *dst,
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. */
if (packetlen < 1)
Expand Down Expand Up @@ -1159,8 +1159,8 @@ u8 *build_igmp_raw(const struct in_addr *source,
of a TCP packet*/
int readtcppacket(const u8 *packet, int readdata) {

struct ip *ip = (struct ip *) packet;
struct tcp_hdr *tcp = (struct tcp_hdr *) (packet + sizeof(struct ip));
const struct ip *ip = (struct ip *) packet;
const struct tcp_hdr *tcp = (struct tcp_hdr *) (packet + sizeof(struct ip));
const unsigned char *data = packet + sizeof(struct ip) + sizeof(struct tcp_hdr);
int tot_len;
struct in_addr bullshit, bullshit2;
Expand Down Expand Up @@ -1235,8 +1235,8 @@ int readtcppacket(const u8 *packet, int readdata) {
/* A simple function I wrote to help in debugging, shows the important fields
of a UDP packet*/
int readudppacket(const u8 *packet, int readdata) {
struct ip *ip = (struct ip *) packet;
struct udp_hdr *udp = (struct udp_hdr *) (packet + sizeof(struct ip));
const struct ip *ip = (struct ip *) packet;
const struct udp_hdr *udp = (struct udp_hdr *) (packet + sizeof(struct ip));
const unsigned char *data = packet + sizeof(struct ip) + sizeof(struct udp_hdr);
int tot_len;
struct in_addr bullshit, bullshit2;
Expand Down Expand Up @@ -1283,7 +1283,7 @@ int readudppacket(const u8 *packet, int readdata) {
/* Used by validatepkt() to validate the TCP header (including option lengths).
The options checked are MSS, WScale, SackOK, Sack, and Timestamp. */
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;

hdrlen = tcp->th_off * 4;
Expand Down Expand Up @@ -1371,7 +1371,7 @@ static bool validateTCPhdr(const u8 *tcpc, unsigned len) {
* data to the caller.
*/
static bool validatepkt(const u8 *ipc, unsigned *len) {
struct ip *ip = (struct ip *) ipc;
const struct ip *ip = (struct ip *) ipc;
const void *data;
unsigned int datalen, iplen;
u8 hdr;
Expand Down Expand Up @@ -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) {
struct ip *ip = NULL;
const struct ip *ip = NULL;

if (h->caplen < offset + sizeof(struct ip)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion tcpip.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class PacketCounter {
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()
*/
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
structure. This function calls getaddrinfo and returns the same
Expand Down
Loading

0 comments on commit c9b7c2f

Please sign in to comment.