for (i = 0; command_string[i]; i++) {
if (on_space) {
- if (!isspace(command_string[i])) {
+ if (!isspace((unsigned char)command_string[i])) {
/* Take care not to exceed the token array length */
if (token_count >= max_tokens) {
return -1;
on_space = 0;
}
} else {
- if (isspace(command_string[i])) {
+ if (isspace((unsigned char)command_string[i])) {
command_string[i] = 0;
on_space = 1;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include "cmdparse.h"
#include "platform.h"
sizeof(struct IPHeader) + sizeof(struct UDPHeader);
const int ip_tcp_size =
sizeof(struct IPHeader) + sizeof(struct TCPHeader);
- const int ip_sctp_size =
- sizeof(struct IPHeader) + sizeof(struct SCTPHeader);
const struct ICMPHeader *icmp;
const struct UDPHeader *udp;
const struct TCPHeader *tcp;
- const struct SCTPHeader *sctp;
int udp_length;
+#ifdef IPPROTO_SCTP
+ const int ip_sctp_size =
+ sizeof(struct IPHeader) + sizeof(struct SCTPHeader);
+ const struct SCTPHeader *sctp;
+#endif
if (ip->protocol == IPPROTO_ICMP) {
if (packet_length < ip_icmp_size) {
sizeof(struct IP6Header) + sizeof(struct UDPHeader);
const int ip_tcp_size =
sizeof(struct IP6Header) + sizeof(struct TCPHeader);
- const int ip_sctp_size =
- sizeof(struct IPHeader) + sizeof(struct SCTPHeader);
const struct ICMPHeader *icmp;
const struct UDPHeader *udp;
const struct TCPHeader *tcp;
- const struct SCTPHeader *sctp;
int udp_length;
+#ifdef IPPROTO_SCTP
+ const int ip_sctp_size =
+ sizeof(struct IPHeader) + sizeof(struct SCTPHeader);
+ const struct SCTPHeader *sctp;
+#endif
if (ip->protocol == IPPROTO_ICMPV6) {
if (packet_length < ip_icmp_size) {
char *append_pos = str;
const struct mpls_label_t *mpls;
- strcpy(str, "");
+ /* Start with an empty string */
+ str[0] = 0;
for (i = 0; i < mpls_count; i++) {
mpls = &mpls_list[i];
void check_sctp_support(
struct net_state_t *net_state)
{
+#ifdef IPPROTO_SCTP
int sctp_socket;
-#ifdef IPPROTO_SCTP
sctp_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
if (sctp_socket != -1) {
close(sctp_socket);
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/select.h>
/*
#ifdef ENABLE_IPV6
/* from dns.c:addr2ip6arpa() */
-static void reverse_host6(struct in6_addr *addr, char *buff) {
+static void reverse_host6(struct in6_addr *addr, char *buff, int buff_length) {
int i;
char *b = buff;
for (i=(sizeof(*addr)/2-1); i>=0; i--, b+=4) /* 64b portion */
- sprintf(b, "%x.%x.", addr->s6_addr[i] & 0xf, addr->s6_addr[i] >> 4);
+ snprintf(
+ b, buff_length,
+ "%x.%x.", addr->s6_addr[i] & 0xf, addr->s6_addr[i] >> 4);
+
buff[strlen(buff) - 1] = '\0';
}
#endif
if (ctl->af == AF_INET6) {
#ifdef ENABLE_IPV6
- reverse_host6(addr, key);
+ reverse_host6(addr, key, NAMELEN);
if (snprintf(lookup_key, NAMELEN, "%s.origin6.asn.cymru.com", key) >= NAMELEN)
return NULL;
#else
DEB_syslog(LOG_INFO, "Looked up: %s", key);
if (iihash)
if ((item.key = xstrdup(key))) {
- item.data = items;
+ item.data = (void *)items;
hsearch(item, ENTER);
DEB_syslog(LOG_INFO, "Insert into hash: %s", key);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <sys/wait.h>
#include <unistd.h>
First, try to execute using /usr/bin/env, because this
will search the PATH for mtr-packet
*/
- execl("/usr/bin/env", "mtr-packet", mtr_packet_path, NULL);
+ execl("/usr/bin/env", "mtr-packet", mtr_packet_path, (char *)NULL);
/*
If env fails to execute, try to use the MTR_PACKET environment
could be executed. This will only be the case if /usr/bin/env
doesn't exist.
*/
- execl(mtr_packet_path, "mtr-packet", NULL);
+ execl(mtr_packet_path, "mtr-packet", (char *)NULL);
/* Both exec attempts failed, so nothing to do but exit */
exit(1);
getmaxyx(stdscr, __unused_int, maxx);
cx = (size_t)(maxx - strlen(str)) / 2;
- printw("%*s%s", cx, "", str);
+ printw("%*s%s", (int)cx, "", str);
}
}
-static void format_field (char *dst, const char *format, int n)
+static void format_field (char *dst, int dst_length, const char *format, int n)
{
if (index (format, 'N' ) ) {
*dst++ = ' ';
} else if (strchr( format, 'f' ) ) {
/* this is for fields where we measure integer microseconds but
display floating point miliseconds. Convert to float here. */
- sprintf(dst, format, n / 1000.0 );
+ snprintf(dst, dst_length, format, n / 1000.0 );
/* this was marked as a temporary hack over 10 years ago. -- REW */
} else {
- sprintf(dst, format, n);
+ snprintf(dst, dst_length, format, n);
}
}
can't be careful enough. */
j = ctl->fld_index[ctl->fld_active[i]];
if (j == -1) continue;
- format_field (buf+hd_len, data_fields[j].format, data_fields[j].net_xxx(at));
+ format_field (
+ buf+hd_len, sizeof(buf) - hd_len,
+ data_fields[j].format, data_fields[j].net_xxx(at));
hd_len += data_fields[j].length;
}
buf[hd_len] = 0;
j = ctl->fld_index[ctl->fld_active[i]];
if (j < 0) continue;
- sprintf( fmt, "%%%ds", data_fields[j].length );
- sprintf( buf + hd_len, fmt, data_fields[j].title );
+ snprintf( fmt, sizeof(fmt), "%%%ds", data_fields[j].length );
+ snprintf(
+ buf + hd_len, sizeof(buf) - hd_len, fmt, data_fields[j].title );
hd_len += data_fields[j].length;
}
attron(A_BOLD);
max_cols = maxx <= SAVED_PINGS + padding ? maxx-padding : SAVED_PINGS;
startstat = padding - 2;
- sprintf(msg, " Last %3d pings", max_cols);
+ snprintf(msg, sizeof(msg), " Last %3d pings", max_cols);
mvprintw(rowstat - 1, startstat, msg);
attroff(A_BOLD);
rv = getnameinfo ((struct sockaddr *) &sa, salen,
hostname, sizeof (hostname), NULL, 0, 0);
if (rv == 0) {
- sprintf (result, "%s %s\n", strlongip (ctl, &host), hostname);
+ snprintf (
+ result, sizeof(result),
+ "%s %s\n", strlongip (ctl, &host), hostname);
+
rv = write (fromdns[1], result, strlen (result));
if (rv < 0)
error (0, errno, "write DNS lookup result");
net_best(at) /1000, net_avg(at)/1000,
net_worst(at)/1000);
} else {
- sprintf(newLine, "???");
+ snprintf(newLine, sizeof(newLine), "???");
}
if (strcmp(newLine, Lines[at]) == 0) {
extern int split_keyaction(void)
{
#ifdef HAVE_CURSES
- char c = getch();
+ unsigned char c = getch();
#else
fd_set readfds;
struct timeval tv;
size_t len;
/* left trim */
- while (*p && (isspace(*p) || (c && *p == c)))
+ while (*p && (isspace((unsigned char)*p) || (c && *p == c)))
p++;
if (str < p) {
len = strlen(str);
len = strlen(str);
while (len) {
len--;
- if (isspace(str[len]) || (c && str[len] == c)) {
+ if (isspace((unsigned char)str[len]) || (c && str[len] == c)) {
continue;
}
len++;