}
// If a daemon is running, ensure no other nodes know about this name
- bool found = false;
if(connect_tincd(false)) {
+ bool found = false;
sendline(fd, "%d %d", CONTROL, REQ_DUMP_NODES);
while(recvline(fd, line, sizeof line)) {
}
// Copy the safe variable to the right config file
- fprintf(variables[i].type & VAR_HOST ? fh : f, "%s = %s\n", l, value);
+ fprintf((variables[i].type & VAR_HOST) ? fh : f, "%s = %s\n", l, value);
}
fclose(f);
char key[MAX_STRING_SIZE];
char address[MAX_STRING_SIZE] = "";
char port[MAX_STRING_SIZE] = "";
- int cipher, digest, maclength, compression, keylen;
+ int cipher, digest, maclength, compression;
node_t *from, *to;
if(sscanf(request, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %d %d "MAX_STRING" "MAX_STRING,
/* Process key */
- keylen = hex2bin(key, key, sizeof key);
+ int keylen = hex2bin(key, key, sizeof key);
if(keylen != (from->outcipher ? cipher_keylength(from->outcipher) : 1)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses wrong keylength!", from->name, from->hostname);
static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet, length_t ether_size) {
struct ip ip;
vpn_packet_t fragment;
- int len, maxlen, todo;
+ int maxlen, todo;
uint8_t *offset;
uint16_t ip_off, origf;
ip_off &= IP_OFFMASK;
while(todo) {
- len = todo > maxlen ? maxlen : todo;
+ int len = todo > maxlen ? maxlen : todo;
memcpy(DATA(&fragment) + ether_size + ip_size, offset, len);
todo -= len;
offset += len;
char *newline = NULL;
if(!fd)
- abort();
+ return false;
while(!(newline = memchr(buffer, '\n', blen))) {
int result = recv(fd, buffer + blen, sizeof buffer - blen, 0);
if(!connect_tincd(true)) {
if(pid) {
if(kill(pid, SIGTERM)) {
- fprintf(stderr, "Could not send TERM signal to process with PID %u: %s\n", pid, strerror(errno));
+ fprintf(stderr, "Could not send TERM signal to process with PID %d: %s\n", pid, strerror(errno));
return 1;
}
- fprintf(stderr, "Sent TERM signal to process with PID %u.\n", pid);
+ fprintf(stderr, "Sent TERM signal to process with PID %d.\n", pid);
waitpid(pid, NULL, 0);
return 0;
}
FILE *f = fopen(fname, "r");
if(!f) {
fprintf(stderr, "Cannot open %s: %s\n", fname, strerror(errno));
- fclose(f);
continue;
}
while(p && *p) {
if(nargc >= maxargs) {
- fprintf(stderr, "next %p '%s', p %p '%s'\n", next, next, p, p);
- abort();
maxargs *= 2;
nargv = xrealloc(nargv, maxargs * sizeof *nargv);
}
static int sortfunc(const void *a, const void *b) {
const nodestats_t *na = *(const nodestats_t **)a;
const nodestats_t *nb = *(const nodestats_t **)b;
+ int result;
+
switch(sortmode) {
case 1:
if(cumulative)
- return -cmpu64(na->in_packets, nb->in_packets) ?: na->i - nb->i;
+ result = -cmpu64(na->in_packets, nb->in_packets);
else
- return -cmpfloat(na->in_packets_rate, nb->in_packets_rate) ?: na->i - nb->i;
+ result = -cmpfloat(na->in_packets_rate, nb->in_packets_rate);
case 2:
if(cumulative)
- return -cmpu64(na->in_bytes, nb->in_bytes) ?: na->i - nb->i;
+ result = -cmpu64(na->in_bytes, nb->in_bytes);
else
- return -cmpfloat(na->in_bytes_rate, nb->in_bytes_rate) ?: na->i - nb->i;
+ result = -cmpfloat(na->in_bytes_rate, nb->in_bytes_rate);
case 3:
if(cumulative)
- return -cmpu64(na->out_packets, nb->out_packets) ?: na->i - nb->i;
+ result = -cmpu64(na->out_packets, nb->out_packets);
else
- return -cmpfloat(na->out_packets_rate, nb->out_packets_rate) ?: na->i - nb->i;
+ result = -cmpfloat(na->out_packets_rate, nb->out_packets_rate);
case 4:
if(cumulative)
- return -cmpu64(na->out_bytes, nb->out_bytes) ?: na->i - nb->i;
+ result = -cmpu64(na->out_bytes, nb->out_bytes);
else
- return -cmpfloat(na->out_bytes_rate, nb->out_bytes_rate) ?: na->i - nb->i;
+ result = -cmpfloat(na->out_bytes_rate, nb->out_bytes_rate);
case 5:
if(cumulative)
- return -cmpu64(na->in_packets + na->out_packets, nb->in_packets + nb->out_packets) ?: na->i - nb->i;
+ result = -cmpu64(na->in_packets + na->out_packets, nb->in_packets + nb->out_packets);
else
- return -cmpfloat(na->in_packets_rate + na->out_packets_rate, nb->in_packets_rate + nb->out_packets_rate) ?: na->i - nb->i;
+ result = -cmpfloat(na->in_packets_rate + na->out_packets_rate, nb->in_packets_rate + nb->out_packets_rate);
case 6:
if(cumulative)
- return -cmpu64(na->in_bytes + na->out_bytes, nb->in_bytes + nb->out_bytes) ?: na->i - nb->i;
+ result = -cmpu64(na->in_bytes + na->out_bytes, nb->in_bytes + nb->out_bytes);
else
- return -cmpfloat(na->in_bytes_rate + na->out_bytes_rate, nb->in_bytes_rate + nb->out_bytes_rate) ?: na->i - nb->i;
+ result = -cmpfloat(na->in_bytes_rate + na->out_bytes_rate, nb->in_bytes_rate + nb->out_bytes_rate);
default:
- return strcmp(na->name, nb->name) ?: na->i - nb->i;
+ result = strcmp(na->name, nb->name);
}
+
+ if(result)
+ return result;
+ else
+ return na->i - nb->i;
}
static void redraw(void) {