#include "buffer.h"
#include "xalloc.h"
-void buffer_compact(buffer_t *buffer, int maxsize) {
+void buffer_compact(buffer_t *buffer, uint32_t maxsize) {
if(buffer->len >= maxsize || buffer->offset / 7 > buffer->len / 8) {
memmove(buffer->data, buffer->data + buffer->offset, buffer->len - buffer->offset);
buffer->len -= buffer->offset;
// Make sure we can add size bytes to the buffer, and return a pointer to the start of those bytes.
-char *buffer_prepare(buffer_t *buffer, int size) {
+char *buffer_prepare(buffer_t *buffer, uint32_t size) {
if(!buffer->data) {
buffer->maxlen = size;
buffer->data = xmalloc(size);
// Copy data into the buffer.
-void buffer_add(buffer_t *buffer, const char *data, int size) {
+void buffer_add(buffer_t *buffer, const char *data, uint32_t size) {
memcpy(buffer_prepare(buffer, size), data, size);
}
// Remove given number of bytes from the buffer, return a pointer to the start of them.
-static char *buffer_consume(buffer_t *buffer, int size) {
+static char *buffer_consume(buffer_t *buffer, uint32_t size) {
char *start = buffer->data + buffer->offset;
buffer->offset += size;
return NULL;
}
- int len = newline + 1 - (buffer->data + buffer->offset);
+ uint32_t len = newline + 1 - (buffer->data + buffer->offset);
*newline = 0;
return buffer_consume(buffer, len);
}
// Check if we have enough bytes in the buffer, and if so, return a pointer to the start of them.
-char *buffer_read(buffer_t *buffer, int size) {
+char *buffer_read(buffer_t *buffer, uint32_t size) {
if(buffer->len - buffer->offset < size) {
return NULL;
}
typedef struct buffer_t {
char *data;
- int maxlen;
- int len;
- int offset;
+ uint32_t maxlen;
+ uint32_t len;
+ uint32_t offset;
} buffer_t;
-extern void buffer_compact(buffer_t *buffer, int maxsize);
-extern char *buffer_prepare(buffer_t *buffer, int size);
-extern void buffer_add(buffer_t *buffer, const char *data, int size);
+extern void buffer_compact(buffer_t *buffer, uint32_t maxsize);
+extern char *buffer_prepare(buffer_t *buffer, uint32_t size);
+extern void buffer_add(buffer_t *buffer, const char *data, uint32_t size);
extern char *buffer_readline(buffer_t *buffer);
-extern char *buffer_read(buffer_t *buffer, int size);
+extern char *buffer_read(buffer_t *buffer, uint32_t size);
extern void buffer_clear(buffer_t *buffer);
#endif
free(ctx);
}
-bool chacha_poly1305_set_key(chacha_poly1305_ctx_t *ctx, const void *key) {
+bool chacha_poly1305_set_key(chacha_poly1305_ctx_t *ctx, const void *vkey) {
+ const uint8_t *key = vkey;
chacha_keysetup(&ctx->main_ctx, key, 256);
chacha_keysetup(&ctx->header_ctx, key + 32, 256);
return true;
p[7] = (uint8_t) v & 0xff;
}
-bool chacha_poly1305_encrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const void *indata, size_t inlen, void *outdata, size_t *outlen) {
+bool chacha_poly1305_encrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const void *indata, size_t inlen, void *voutdata, size_t *outlen) {
uint8_t seqbuf[8];
const uint8_t one[8] = { 1, 0, 0, 0, 0, 0, 0, 0 }; /* NB little-endian */
uint8_t poly_key[POLY1305_KEYLEN];
+ uint8_t *outdata = voutdata;
/*
* Run ChaCha20 once to generate the Poly1305 key. The IV is the
return true;
}
-bool chacha_poly1305_decrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const void *indata, size_t inlen, void *outdata, size_t *outlen) {
+bool chacha_poly1305_decrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const void *vindata, size_t inlen, void *outdata, size_t *outlen) {
uint8_t seqbuf[8];
const uint8_t one[8] = { 1, 0, 0, 0, 0, 0, 0, 0 }; /* NB little-endian */
uint8_t expected_tag[POLY1305_TAGLEN], poly_key[POLY1305_KEYLEN];
+ const uint8_t *indata = vindata;
/*
* Run ChaCha20 once to generate the Poly1305 key. The IV is the
}
bool get_config_subnet(const config_t *cfg, subnet_t **result) {
- subnet_t subnet = {NULL};
+ subnet_t subnet = {0};
if(!cfg) {
return false;
// And we try to read the ones that end with ".conf"
if(l > 5 && !strcmp(".conf", & ep->d_name[ l - 5 ])) {
- if(snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ep->d_name) >= sizeof(fname)) {
+ if((size_t)snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ep->d_name) >= sizeof(fname)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Pathname too long: %s/%s", dname, ep->d_name);
return false;
}
}
static bool read_packet(vpn_packet_t *packet) {
+ (void)packet;
return false;
}
static bool write_packet(vpn_packet_t *packet) {
+ (void)packet;
return true;
}
// Read PEM ECDSA keys
-static bool read_pem(FILE *fp, const char *type, void *buf, size_t size) {
+static bool read_pem(FILE *fp, const char *type, void *vbuf, size_t size) {
char line[1024];
bool data = false;
size_t typelen = strlen(type);
+ char *buf = vbuf;
while(fgets(line, sizeof(line), fp)) {
if(!data) {
}
size_t ecdsa_size(ecdsa_t *ecdsa) {
+ (void)ecdsa;
return 64;
}
// Write PEM ECDSA keys
-static bool write_pem(FILE *fp, const char *type, void *buf, size_t size) {
+static bool write_pem(FILE *fp, const char *type, void *vbuf, size_t size) {
fprintf(fp, "-----BEGIN %s-----\n", type);
+ char *buf = vbuf;
char base64[65];
while(size) {
}
static void signalio_handler(void *data, int flags) {
+ (void)data;
+ (void)flags;
unsigned char signum;
if(read(pipefd[0], &signum, 1) != 1) {
}
static void check_conffile(const char *fname, bool server) {
+ (void)server;
+
FILE *f = fopen(fname, "r");
if(!f) {
static subnet_t ipv4, ipv6;
void ifconfig_address(FILE *out, const char *value) {
- subnet_t address = {NULL};
+ subnet_t address = {0};
char address_str[MAXNETSTR];
if(!str2net(&address, value) || !net2str(address_str, sizeof(address_str), &address)) {
}
void ifconfig_route(FILE *out, const char *value) {
- subnet_t subnet = {NULL}, gateway = {NULL};
+ subnet_t subnet = {0}, gateway = {0};
char subnet_str[MAXNETSTR] = "", gateway_str[MAXNETSTR] = "";
char *sep = strchr(value, ' ');
#include "xalloc.h"
void logger(int level, int priority, const char *format, ...) {
+ (void)level;
+ (void)priority;
va_list ap;
+
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
+
fputc('\n', stderr);
}
char invname[PATH_MAX];
struct stat st;
- if(snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name) >= sizeof(invname)) {
+ if((size_t)snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name) >= sizeof(invname)) {
fprintf(stderr, "Filename too long: %s" SLASH "%s\n", filename, ent->d_name);
continue;
}
static char line[1024];
const char *end = strchr(*data, '\n');
- size_t len = end ? end - *data : strlen(*data);
+ size_t len = end ? (size_t)(end - *data) : strlen(*data);
if(len >= sizeof(line)) {
fprintf(stderr, "Maximum line length exceeded!\n");
return xstrdup(p);
}
- if(e - p >= sizeof(value)) {
+ if((size_t)(e - p) >= sizeof(value)) {
fprintf(stderr, "Maximum line length exceeded!\n");
return NULL;
}
}
static bool finalize_join(void) {
- const char *name = get_value(data, "Name");
+ const char *temp_name = get_value(data, "Name");
- if(!name) {
+ if(!temp_name) {
fprintf(stderr, "No Name found in invitation!\n");
return false;
}
+ size_t len = strlen(temp_name);
+ char name[len + 1];
+ memcpy(name, temp_name, len);
+ name[len] = 0;
+
if(!check_id(name)) {
fprintf(stderr, "Invalid Name found in invitation!\n");
return false;
char newbase[PATH_MAX];
- if(snprintf(newbase, sizeof(newbase), CONFDIR SLASH "tinc" SLASH "%s", line) >= sizeof(newbase)) {
+ if((size_t)snprintf(newbase, sizeof(newbase), CONFDIR SLASH "tinc" SLASH "%s", line) >= sizeof(newbase)) {
fprintf(stderr, "Filename too long: " CONFDIR SLASH "tinc" SLASH "%s\n", line);
goto ask_netname;
}
if(response == 'e') {
char *command;
#ifndef HAVE_MINGW
- xasprintf(&command, "\"%s\" \"%s\"", getenv("VISUAL") ? : getenv("EDITOR") ? : "vi", filename);
+ const char *editor = getenv("VISUAL");
+ if (!editor)
+ editor = getenv("EDITOR");
+ if (!editor)
+ editor = "vi";
+
+ xasprintf(&command, "\"%s\" \"%s\"", editor, filename);
#else
xasprintf(&command, "edit \"%s\"", filename);
#endif
}
-static bool invitation_send(void *handle, uint8_t type, const void *data, size_t len) {
+static bool invitation_send(void *handle, uint8_t type, const void *vdata, size_t len) {
+ (void)handle;
+ (void)type;
+ const char *data = vdata;
+
while(len) {
int result = send(sock, data, len, 0);
}
static bool invitation_receive(void *handle, uint8_t type, const void *msg, uint16_t len) {
+ (void)handle;
+
switch(type) {
case SPTPS_HANDSHAKE:
return sptps_send_record(&sptps, 0, cookie, sizeof(cookie));
// Tell him we have an invitation, and give him our throw-away key.
int len = snprintf(line, sizeof(line), "0 ?%s %d.%d\n", b64key, PROT_MAJOR, PROT_MINOR);
- if(len <= 0 || len >= sizeof(line)) {
+ if(len <= 0 || (size_t)len >= sizeof(line)) {
abort();
}
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-bool recvdata(int fd, char *data, size_t len);
int cmd_invite(int argc, char *argv[]);
int cmd_join(int argc, char *argv[]);
fcntl(device_fd, F_SETFD, FD_CLOEXEC);
#endif
- struct ifreq ifr = {{{0}}};
+ struct ifreq ifr = {0};
get_config_string(lookup_config(config_tree, "DeviceType"), &type);
logger(DEBUG_ALWAYS, LOG_INFO, "%s is a %s", device, device_info);
if(ifr.ifr_flags & IFF_TAP) {
- struct ifreq ifr_mac = {{{0}}};
+ struct ifreq ifr_mac = {0};
if(!ioctl(device_fd, SIOCGIFHWADDR, &ifr_mac)) {
memcpy(mymac.x, ifr_mac.ifr_hwaddr.sa_data, ETH_ALEN);
message[sizeof(message) - 1] = 0;
va_end(ap);
- if(len > 0 && len < sizeof(message) - 1 && message[len - 1] == '\n') {
+ if(len > 0 && (size_t)len < sizeof(message) - 1 && message[len - 1] == '\n') {
message[len - 1] = 0;
}
}
static void sptps_logger(sptps_t *s, int s_errno, const char *format, va_list ap) {
+ (void)s_errno;
char message[1024];
size_t msglen = sizeof(message);
int len = vsnprintf(message, msglen, format, ap);
message[sizeof(message) - 1] = 0;
- if(len > 0 && len < sizeof(message) - 1) {
+ if(len > 0 && (size_t)len < sizeof(message) - 1) {
if(message[len - 1] == '\n') {
message[--len] = 0;
}
#endif
bool send_meta_sptps(void *handle, uint8_t type, const void *buffer, size_t length) {
+ (void)type;
connection_t *c = handle;
if(!c) {
return true;
}
-bool send_meta(connection_t *c, const char *buffer, int length) {
+bool send_meta(connection_t *c, const char *buffer, size_t length) {
if(!c) {
logger(DEBUG_ALWAYS, LOG_ERR, "send_meta() called with NULL pointer!");
abort();
}
- logger(DEBUG_META, LOG_DEBUG, "Sending %d bytes of metadata to %s (%s)", length,
+ logger(DEBUG_META, LOG_DEBUG, "Sending %lu bytes of metadata to %s (%s)", (unsigned long)length,
c->name, c->hostname);
if(c->protocol_minor >= 2) {
return true;
}
-void send_meta_raw(connection_t *c, const char *buffer, int length) {
+void send_meta_raw(connection_t *c, const char *buffer, size_t length) {
if(!c) {
logger(DEBUG_ALWAYS, LOG_ERR, "send_meta() called with NULL pointer!");
abort();
}
- logger(DEBUG_META, LOG_DEBUG, "Sending %d bytes of raw metadata to %s (%s)", length,
+ logger(DEBUG_META, LOG_DEBUG, "Sending %lu bytes of raw metadata to %s (%s)", (unsigned long)length,
c->name, c->hostname);
buffer_add(&c->outbuf, buffer, length);
io_set(&c->io, IO_READ | IO_WRITE);
}
-void broadcast_meta(connection_t *from, const char *buffer, int length) {
+void broadcast_meta(connection_t *from, const char *buffer, size_t length) {
for list_each(connection_t, c, connection_list)
if(c != from && c->edge) {
send_meta(c, buffer, length);
}
bool receive_meta(connection_t *c) {
- int inlen;
+ ssize_t inlen;
char inbuf[MAXBUFSIZE];
char *bufp = inbuf, *endp;
/* Are we receiving a SPTPS packet? */
if(c->sptpslen) {
- int len = MIN(inlen, c->sptpslen - c->inbuf.len);
+ ssize_t len = MIN(inlen, c->sptpslen - c->inbuf.len);
buffer_add(&c->inbuf, bufp, len);
char *sptpspacket = buffer_read(&c->inbuf, c->sptpslen);
}
if(c->protocol_minor >= 2) {
- int len = sptps_receive_data(&c->sptps, bufp, inlen);
+ size_t len = sptps_receive_data(&c->sptps, bufp, inlen);
if(!len) {
return false;
return false;
#else
- if(inlen > c->inbudget) {
- logger(DEBUG_META, LOG_ERR, "yte limit exceeded for decryption from %s (%s)", c->name, c->hostname);
+ if((size_t)inlen > c->inbudget) {
+ logger(DEBUG_META, LOG_ERR, "Byte limit exceeded for decryption from %s (%s)", c->name, c->hostname);
return false;
} else {
c->inbudget -= inlen;
size_t outlen = inlen;
- if(!cipher_decrypt(c->incipher, bufp, inlen, buffer_prepare(&c->inbuf, inlen), &outlen, false) || inlen != outlen) {
+ if(!cipher_decrypt(c->incipher, bufp, inlen, buffer_prepare(&c->inbuf, inlen), &outlen, false) || (size_t)inlen != outlen) {
logger(DEBUG_ALWAYS, LOG_ERR, "Error while decrypting metadata from %s (%s)",
c->name, c->hostname);
return false;
#include "connection.h"
-extern bool send_meta(struct connection_t *c, const char *buffer, int length);
-extern void send_meta_raw(struct connection_t *c, const char *buffer, int length);
+extern bool send_meta(struct connection_t *c, const char *buffer, size_t length);
+extern void send_meta_raw(struct connection_t *c, const char *buffer, size_t length);
extern bool send_meta_sptps(void *handle, uint8_t type, const void *data, size_t length);
extern bool receive_meta_sptps(void *handle, uint8_t type, const void *data, uint16_t length);
-extern void broadcast_meta(struct connection_t *from, const char *buffer, int length);
+extern void broadcast_meta(struct connection_t *from, const char *buffer, size_t length);
extern bool receive_meta(struct connection_t *c);
#endif
static const char *device_info = "multicast socket";
static struct addrinfo *ai = NULL;
-static mac_t ignore_src = {{0}};
+static mac_t ignore_src = {0};
static bool setup_device(void) {
char *host = NULL;
/* Put a misbehaving connection in the tarpit */
void tarpit(int fd) {
static int pits[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
- static int next_pit = 0;
+ static unsigned int next_pit = 0;
if(pits[next_pit] != -1) {
closesocket(pits[next_pit]);
uint8_t x[6];
} node_id_t;
-typedef short length_t;
+typedef uint16_t length_t;
typedef uint32_t seqno_t;
#define AF_UNKNOWN 255
extern bool send_sptps_data(node_t *to, node_t *from, int type, const void *data, size_t len);
extern bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t len);
extern void send_packet(struct node_t *n, vpn_packet_t *packet);
-extern void receive_tcppacket(struct connection_t *c, const char *buffer, int length);
-extern bool receive_tcppacket_sptps(struct connection_t *c, const char *buffer, int length);
+extern void receive_tcppacket(struct connection_t *c, const char *buffer, size_t length);
+extern bool receive_tcppacket_sptps(struct connection_t *c, const char *buffer, size_t length);
extern void broadcast_packet(const struct node_t *n, vpn_packet_t *packet);
extern char *get_name(void);
extern void device_enable(void);
lzo1x_1_compress(source, len, dest, &lzolen, lzo_wrkmem);
return lzolen;
#else
- return -1;
+ return 0;
#endif
} else if(level < 10) {
#ifdef HAVE_ZLIB
return destlen;
} else
#endif
- return -1;
+ return 0;
} else {
#ifdef HAVE_LZO
lzo_uint lzolen = MAXSIZE;
lzo1x_999_compress(source, len, dest, &lzolen, lzo_wrkmem);
return lzolen;
#else
- return -1;
+ return 0;
#endif
}
- return -1;
+ return 0;
}
static length_t uncompress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) {
return lzolen;
} else
#endif
- return -1;
+ return 0;
}
#ifdef HAVE_ZLIB
if(inflate(&stream, Z_FINISH) == Z_STREAM_END) {
return stream.total_out;
} else {
- return -1;
+ return 0;
}
}
#endif
- return -1;
+ return 0;
}
/* VPN packet I/O */
return false;
#else
- if(!n->status.validkey_in || !digest_active(n->indigest) || inpkt->len < sizeof(seqno_t) + digest_length(n->indigest)) {
+ if(!n->status.validkey_in || !digest_active(n->indigest) || (size_t)inpkt->len < sizeof(seqno_t) + digest_length(n->indigest)) {
return false;
}
/* Check packet length */
- if(inpkt->len < sizeof(seqno_t) + digest_length(n->indigest)) {
+ if((size_t)inpkt->len < sizeof(seqno_t) + digest_length(n->indigest)) {
logger(DEBUG_TRAFFIC, LOG_DEBUG, "Got too short packet from %s (%s)",
n->name, n->hostname);
return false;
return false;
}
} else {
- for(int i = n->received_seqno + 1; i < seqno; i++) {
+ for(seqno_t i = n->received_seqno + 1; i < seqno; i++) {
n->late[(i / 8) % replaywin] |= 1 << i % 8;
}
}
if(n->incompression) {
vpn_packet_t *outpkt = pkt[nextpkt++];
- if((outpkt->len = uncompress_packet(DATA(outpkt), DATA(inpkt), inpkt->len, n->incompression)) < 0) {
+ if(!(outpkt->len = uncompress_packet(DATA(outpkt), DATA(inpkt), inpkt->len, n->incompression))) {
logger(DEBUG_TRAFFIC, LOG_ERR, "Error while uncompressing packet from %s (%s)",
n->name, n->hostname);
return false;
#endif
}
-void receive_tcppacket(connection_t *c, const char *buffer, int len) {
+void receive_tcppacket(connection_t *c, const char *buffer, size_t len) {
vpn_packet_t outpkt;
outpkt.offset = DEFAULT_PACKET_OFFSET;
receive_packet(c->node, &outpkt);
}
-bool receive_tcppacket_sptps(connection_t *c, const char *data, int len) {
+bool receive_tcppacket_sptps(connection_t *c, const char *data, size_t len) {
if(len < sizeof(node_id_t) + sizeof(node_id_t)) {
logger(DEBUG_PROTOCOL, LOG_ERR, "Got too short TCP SPTPS packet from %s (%s)", c->name, c->hostname);
return false;
if(n->outcompression) {
outpkt.offset = 0;
- int len = compress_packet(DATA(&outpkt) + offset, DATA(origpkt) + offset, origpkt->len - offset, n->outcompression);
+ length_t len = compress_packet(DATA(&outpkt) + offset, DATA(origpkt) + offset, origpkt->len - offset, n->outcompression);
- if(len < 0) {
+ if(!len) {
logger(DEBUG_TRAFFIC, LOG_ERR, "Error while compressing packet to %s (%s)", n->name, n->hostname);
} else if(len < origpkt->len - offset) {
outpkt.len = len + offset;
if(n->outcompression) {
outpkt = pkt[nextpkt++];
- if((outpkt->len = compress_packet(DATA(outpkt), DATA(inpkt), inpkt->len, n->outcompression)) < 0) {
+ if(!(outpkt->len = compress_packet(DATA(outpkt), DATA(inpkt), inpkt->len, n->outcompression))) {
logger(DEBUG_TRAFFIC, LOG_ERR, "Error while compressing packet to %s (%s)",
n->name, n->hostname);
return;
if(relay_supported) {
if(direct) {
/* Inform the recipient that this packet was sent directly. */
- node_id_t nullid = {{0}};
+ node_id_t nullid = {0};
memcpy(buf_ptr, &nullid, sizeof(nullid));
buf_ptr += sizeof(nullid);
} else {
if(type & PKT_COMPRESSED) {
length_t ulen = uncompress_packet(DATA(&inpkt) + offset, (const uint8_t *)data, len, from->incompression);
- if(ulen < 0) {
+ if(!ulen) {
return false;
} else {
inpkt.len = ulen + offset;
static void handle_incoming_vpn_packet(listen_socket_t *ls, vpn_packet_t *pkt, sockaddr_t *addr) {
char *hostname;
- node_id_t nullid = {{0}};
+ node_id_t nullid = {0};
node_t *from, *to;
bool direct = false;
}
void handle_incoming_vpn_data(void *data, int flags) {
+ (void)data;
+ (void)flags;
listen_socket_t *ls = data;
#ifdef HAVE_RECVMMSG
}
void handle_device_data(void *data, int flags) {
+ (void)data;
+ (void)flags;
vpn_packet_t packet;
packet.offset = DEFAULT_PACKET_OFFSET;
packet.priority = 0;
logger(DEBUG_ALWAYS, LOG_ERR, "Error reading Ed25519 private key file `%s': %s", fname, strerror(errno));
if(errno == ENOENT) {
- logger(DEBUG_ALWAYS, LOG_INFO, "Create an Ed25519 keypair with `tinc -n %s generate-ed25519-keys'.", netname ? : ".");
+ logger(DEBUG_ALWAYS, LOG_INFO, "Create an Ed25519 keypair with `tinc -n %s generate-ed25519-keys'.", netname ? netname : ".");
}
free(fname);
fname, strerror(errno));
if(errno == ENOENT) {
- logger(DEBUG_ALWAYS, LOG_INFO, "Create an RSA keypair with `tinc -n %s generate-rsa-keys'.", netname ? : ".");
+ logger(DEBUG_ALWAYS, LOG_INFO, "Create an RSA keypair with `tinc -n %s generate-rsa-keys'.", netname ? netname : ".");
}
free(fname);
}
void setup_outgoing_connection(outgoing_t *outgoing, bool verbose) {
+ (void)verbose;
timeout_del(&outgoing->ev);
node_t *n = outgoing->node;
new connection
*/
void handle_new_meta_connection(void *data, int flags) {
+ (void)flags;
listen_socket_t *l = data;
connection_t *c;
sockaddr_t sa;
accept a new UNIX socket connection
*/
void handle_new_unix_connection(void *data, int flags) {
+ (void)flags;
io_t *io = data;
connection_t *c;
sockaddr_t sa;
sockaddr_t str2sockaddr(const char *address, const char *port) {
struct addrinfo *ai, hint = {0};
- sockaddr_t result = {{0}};
+ sockaddr_t result = {0};
int err;
hint.ai_family = AF_UNSPEC;
}
node_t *lookup_node(char *name) {
- node_t n = {NULL};
+ node_t n = {0};
n.name = name;
id[sizeof(id) - 1] = 0;
send_request(c, "%d %d %s %s %s %d %d %d %d %x %x %s %s %d %d %d %d %ld %d %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, CONTROL, REQ_DUMP_NODES,
- n->name, id, n->hostname ? : "unknown port unknown",
+ n->name, id, n->hostname ? n->hostname : "unknown port unknown",
#ifdef DISABLE_LEGACY
0, 0, 0,
#else
cipher_get_nid(n->outcipher), digest_get_nid(n->outdigest), (int)digest_length(n->outdigest),
#endif
n->outcompression, n->options, bitfield_to_int(&n->status, sizeof(n->status)),
- n->nexthop ? n->nexthop->name : "-", n->via ? n->via->name ? : "-" : "-", n->distance,
+ n->nexthop ? n->nexthop->name : "-", n->via && n->via->name ? n->via->name : "-", n->distance,
n->mtu, n->minmtu, n->maxmtu, (long)n->last_state_change, n->udp_ping_rtt,
n->in_packets, n->in_bytes, n->out_packets, n->out_bytes);
}
close(random_fd);
}
-void randomize(void *out, size_t outlen) {
+void randomize(void *vout, size_t outlen) {
+ char *out = vout;
+
while(outlen) {
size_t len = read(random_fd, out, outlen);
We use SHA512 instead of MD5 and SHA1.
*/
-static bool prf_xor(int nid, const char *secret, size_t secretlen, char *seed, size_t seedlen, char *out, ssize_t outlen) {
+static bool prf_xor(int nid, const char *secret, size_t secretlen, char *seed, size_t seedlen, char *out, size_t outlen) {
digest_t *digest = digest_open_by_nid(nid, -1);
if(!digest) {
}
/* XOR the results of the outer HMAC into the out buffer */
- for(int i = 0; i < len && i < outlen; i++) {
+ for(size_t i = 0; i < len && i < outlen; i++) {
*out++ ^= hash[i];
}
BIGNUM *bn_n = NULL;
BIGNUM *bn_e = NULL;
- if(BN_hex2bn(&bn_n, n) != strlen(n) || BN_hex2bn(&bn_e, e) != strlen(e)) {
+ if((size_t)BN_hex2bn(&bn_n, n) != strlen(n) || (size_t)BN_hex2bn(&bn_e, e) != strlen(e)) {
BN_free(bn_e);
BN_free(bn_n);
return false;
BIGNUM *bn_e = NULL;
BIGNUM *bn_d = NULL;
- if(BN_hex2bn(&bn_n, n) != strlen(n) || BN_hex2bn(&bn_e, e) != strlen(e) || BN_hex2bn(&bn_d, d) != strlen(d)) {
+ if((size_t)BN_hex2bn(&bn_n, n) != strlen(n) || (size_t)BN_hex2bn(&bn_e, e) != strlen(e) || (size_t)BN_hex2bn(&bn_d, d) != strlen(d)) {
BN_free(bn_d);
BN_free(bn_e);
BN_free(bn_n);
}
bool rsa_public_encrypt(rsa_t *rsa, void *in, size_t len, void *out) {
- if(RSA_public_encrypt(len, in, out, rsa, RSA_NO_PADDING) == len) {
+ if((size_t)RSA_public_encrypt(len, in, out, rsa, RSA_NO_PADDING) == len) {
return true;
}
}
bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out) {
- if(RSA_private_decrypt(len, in, out, rsa, RSA_NO_PADDING) == len) {
+ if((size_t)RSA_private_decrypt(len, in, out, rsa, RSA_NO_PADDING) == len) {
return true;
}
/* This function prettyprints the key generation process */
static int indicator(int a, int b, BN_GENCB *cb) {
+ (void)cb;
+
switch(a) {
case 0:
fprintf(stderr, ".");
request[sizeof(request) - 1] = 0;
va_end(args);
- if(len < 0 || len > sizeof(request) - 1) {
+ if(len < 0 || (size_t)len > sizeof(request) - 1) {
logger(DEBUG_ALWAYS, LOG_ERR, "Output buffer overflow while sending request to %s (%s)",
c->name, c->hostname);
return false;
static timeout_t past_request_timeout;
static void age_past_requests(void *data) {
+ (void)data;
int left = 0, deleted = 0;
for splay_each(past_request_t, p, past_request_tree) {
}
bool seen_request(const char *request) {
- past_request_t *new, p = {NULL};
+ past_request_t *new, p = {0};
p.request = request;
}
static bool finalize_invitation(connection_t *c, const char *data, uint16_t len) {
+ (void)len;
+
if(strchr(data, '\n')) {
logger(DEBUG_ALWAYS, LOG_ERR, "Received invalid key from invited node %s (%s)!\n", c->name, c->hostname);
return false;
/* Convert the challenge from hexadecimal back to binary */
- int inlen = hex2bin(hexkey, enckey, sizeof(enckey));
+ size_t inlen = hex2bin(hexkey, enckey, sizeof(enckey));
/* Check if the length of the meta key is all right */
/* Convert the hash to binary format */
- int inlen = hex2bin(hishash, hishash, sizeof(hishash));
+ size_t inlen = hex2bin(hishash, hishash, sizeof(hishash));
/* Check if the length of the hash is all right */
char to_port[MAX_STRING_SIZE];
char address_local[MAX_STRING_SIZE];
char port_local[MAX_STRING_SIZE];
- sockaddr_t address, local_address = {{0}};
+ sockaddr_t address, local_address = {0};
uint32_t options;
int weight;
}
static bool send_initial_sptps_data(void *handle, uint8_t type, const void *data, size_t len) {
+ (void)type;
node_t *to = handle;
to->sptps.send_data = send_sptps_data_myself;
char buf[len * 4 / 3 + 5];
+
b64encode(data, buf, len);
+
return send_request(to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, myself->name, to->name, REQ_KEY, buf);
}
/* REQ_KEY is overloaded to allow arbitrary requests to be routed between two nodes. */
static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, node_t *to, int reqno) {
+ (void)c;
+
/* If this is a SPTPS packet, see if sending UDP info helps.
Note that we only do this if we're the destination or the static relay;
otherwise every hop would initiate its own UDP info message, resulting in elevated chatter. */
}
char buf[MAX_STRING_SIZE];
- int len;
+ size_t len;
if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, buf) != 1 || !(len = b64decode(buf, buf, strlen(buf)))) {
logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s): %s", "REQ_SPTPS_START", from->name, from->hostname, "invalid SPTPS data");
if(from->status.sptps) {
char buf[strlen(key)];
- int len = b64decode(key, buf, strlen(key));
+ size_t len = b64decode(key, buf, strlen(key));
if(!len || !sptps_receive_data(&from->sptps, buf, len)) {
/* Uh-oh. It might be that the tunnel is stuck in some corrupted state,
from->outdigest = NULL;
}
- if(maclength != digest_length(from->outdigest)) {
+ if((size_t)maclength != digest_length(from->outdigest)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses bogus MAC length!", from->name, from->hostname);
return false;
}
/* Process key */
- int keylen = hex2bin(key, key, sizeof(key));
+ size_t 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);
}
bool termreq_h(connection_t *c, const char *request) {
+ (void)c;
+ (void)request;
return false;
}
}
bool ping_h(connection_t *c, const char *request) {
+ (void)request;
return send_pong(c);
}
}
bool pong_h(connection_t *c, const char *request) {
+ (void)request;
c->status.pinged = false;
/* Successful connection, reset timeout if this is an outgoing connection. */
char subnetstr[MAX_STRING_SIZE];
char name[MAX_STRING_SIZE];
node_t *owner;
- subnet_t s = {NULL}, *new, *old;
+ subnet_t s = {0}, *new, *old;
if(sscanf(request, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) {
logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "ADD_SUBNET", c->name,
char subnetstr[MAX_STRING_SIZE];
char name[MAX_STRING_SIZE];
node_t *owner;
- subnet_t s = {NULL}, *find;
+ subnet_t s = {0}, *find;
if(sscanf(request, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) {
logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "DEL_SUBNET", c->name,
}
static void age_subnets(void *data) {
+ (void)data;
bool left = false;
for splay_each(subnet_t, s, myself->subnet_tree) {
/* Splay operation */
static splay_node_t *splay_top_down(splay_tree_t *tree, const void *data, int *result) {
- splay_node_t left = {NULL}, right = {NULL};
+ splay_node_t left = {0}, right = {0};
splay_node_t *leftbottom = &left, *rightbottom = &right, *child, *grandchild;
splay_node_t *root = tree->root;
int c;
*/
void sptps_log_quiet(sptps_t *s, int s_errno, const char *format, va_list ap) {
+ (void)s;
+ (void)s_errno;
+ (void)format;
+ (void)ap;
}
void sptps_log_stderr(sptps_t *s, int s_errno, const char *format, va_list ap) {
+ (void)s;
+ (void)s_errno;
+
vfprintf(stderr, format, ap);
fputc('\n', stderr);
}
// Log an error message.
static bool error(sptps_t *s, int s_errno, const char *format, ...) {
+ (void)s;
+ (void)s_errno;
+
if(format) {
va_list ap;
va_start(ap, format);
// Receive an ACKnowledgement record.
static bool receive_ack(sptps_t *s, const char *data, uint16_t len) {
+ (void)data;
+
if(len) {
return error(s, EIO, "Invalid ACK record length");
}
return false;
}
+ // Fall through
case SPTPS_KEX:
// We have sent our KEX request, we expect our peer to sent one as well.
}
} else if(update_state) {
// We missed some packets. Mark them in the bitmap as being late.
- for(int i = s->inseqno; i < seqno; i++) {
+ for(uint32_t i = s->inseqno; i < seqno; i++) {
s->late[(i / 8) % s->replaywin] |= 1 << i % 8;
}
}
}
// Check datagram for valid HMAC
-bool sptps_verify_datagram(sptps_t *s, const void *data, size_t len) {
+bool sptps_verify_datagram(sptps_t *s, const void *vdata, size_t len) {
if(!s->instate || len < 21) {
return error(s, EIO, "Received short packet");
}
+ const char *data = vdata;
uint32_t seqno;
memcpy(&seqno, data, 4);
seqno = ntohl(seqno);
}
// Receive incoming data. Check if it contains a complete record, if so, handle it.
-size_t sptps_receive_data(sptps_t *s, const void *data, size_t len) {
+size_t sptps_receive_data(sptps_t *s, const void *vdata, size_t len) {
+ const char *data = vdata;
size_t total_read = 0;
if(!s->state) {
static char *program_name;
void logger(int level, int priority, const char *format, ...) {
+ (void)level;
+ (void)priority;
va_list ap;
+
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
+
fputc('\n', stderr);
}
// Symbols necessary to link with logger.o
bool send_request(void *c, const char *msg, ...) {
+ (void)c;
+ (void)msg;
return false;
}
+
struct list_t *connection_list = NULL;
+
bool send_meta(void *c, const char *msg, int len) {
+ (void)c;
+ (void)msg;
+ (void)len;
return false;
}
+
char *logfilename = NULL;
bool do_detach = false;
struct timeval now;
static int addressfamily = AF_UNSPEC;
static bool send_data(void *handle, uint8_t type, const void *data, size_t len) {
+ (void)type;
char hex[len * 2 + 1];
bin2hex(data, hex, len);
const int *sock = handle;
- if(send(*sock, data, len, 0) != len) {
+ if((size_t)send(*sock, data, len, 0) != len) {
return false;
}
}
static bool receive_record(void *handle, uint8_t type, const void *data, uint16_t len) {
+ (void)handle;
if(verbose) {
fprintf(stderr, "Received type %d record of %u bytes:\n", type, len);
}
if(len > 1) {
sptps_send_record(&s, 0, buf, len);
}
- } else if(!sptps_send_record(&s, buf[0] == '!' ? 1 : 0, buf, (len == 1 && buf[0] == '\n') ? 0 : buf[0] == '*' ? sizeof(buf) : len)) {
+ } else if(!sptps_send_record(&s, buf[0] == '!' ? 1 : 0, buf, (len == 1 && buf[0] == '\n') ? 0 : buf[0] == '*' ? sizeof(buf) : (size_t)len)) {
return 1;
}
}
bool net2str(char *netstr, int len, const subnet_t *subnet) {
if(!netstr || !subnet) {
- logger(DEBUG_ALWAYS, LOG_ERR, "net2str() was called with netstr=%p, subnet=%p!", netstr, subnet);
+ logger(DEBUG_ALWAYS, LOG_ERR, "net2str() was called with netstr=%p, subnet=%p!", (void *)netstr, (void *)subnet);
return false;
}
/* The directory is a relative path or a filename. */
getcwd(directory, sizeof(directory));
- if(snprintf(buf2, sizeof(buf2), "%s" SLASH "%s", directory, filename) >= sizeof(buf2)) {
+ if((size_t)snprintf(buf2, sizeof(buf2), "%s" SLASH "%s", directory, filename) >= sizeof(buf2)) {
fprintf(stderr, "Filename too long: %s" SLASH "%s\n", directory, filename);
if(ask && tty) {
blen += result;
}
- if(newline - buffer >= len) {
+ if((size_t)(newline - buffer) >= len) {
return false;
}
return true;
}
-bool recvdata(int fd, char *data, size_t len) {
- if(len == -1) {
- len = blen;
- }
-
+static bool recvdata(int fd, char *data, size_t len) {
while(blen < len) {
int result = recv(fd, buffer + blen, sizeof(buffer) - blen, 0);
bool sendline(int fd, char *format, ...) {
static char buffer[4096];
char *p = buffer;
- int blen = 0;
+ int blen;
va_list ap;
va_start(ap, format);
buffer[sizeof(buffer) - 1] = 0;
va_end(ap);
- if(blen < 1 || blen >= sizeof(buffer)) {
+ if(blen < 1 || (size_t)blen >= sizeof(buffer)) {
return false;
}
return true;
}
-static void pcap(int fd, FILE *out, int snaplen) {
+static void pcap(int fd, FILE *out, uint32_t snaplen) {
sendline(fd, "%d %d %d", CONTROL, REQ_PCAP, snaplen);
char data[9018];
0xa1b2c3d4,
2, 4,
0, 0,
- snaplen ? : sizeof(data),
+ snaplen ? snaplen : sizeof(data),
1,
};
int n = sscanf(line, "%d %d %d", &code, &req, &len);
gettimeofday(&tv, NULL);
- if(n != 3 || code != CONTROL || req != REQ_PCAP || len < 0 || len > sizeof(data)) {
+ if(n != 3 || code != CONTROL || req != REQ_PCAP || len < 0 || (size_t)len > sizeof(data)) {
break;
}
int code, req, len;
int n = sscanf(line, "%d %d %d", &code, &req, &len);
- if(n != 3 || code != CONTROL || req != REQ_LOG || len < 0 || len > sizeof(data)) {
+ if(n != 3 || code != CONTROL || req != REQ_LOG || len < 0 || (size_t)len > sizeof(data)) {
break;
}
}
static int cmd_stop(int argc, char *argv[]) {
+ (void)argv;
+
if(argc > 1) {
fprintf(stderr, "Too many arguments!\n");
return 1;
}
static int cmd_reload(int argc, char *argv[]) {
+ (void)argv;
+
if(argc > 1) {
fprintf(stderr, "Too many arguments!\n");
return 1;
char fname[PATH_MAX];
- if(snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ent->d_name) >= sizeof(fname)) {
+ if((size_t)snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ent->d_name) >= sizeof(fname)) {
fprintf(stderr, "Filename too long: %s" SLASH "%s\n", dname, ent->d_name);
continue;
}
}
static int cmd_purge(int argc, char *argv[]) {
+ (void)argv;
+
if(argc > 1) {
fprintf(stderr, "Too many arguments!\n");
return 1;
}
static int cmd_retry(int argc, char *argv[]) {
+ (void)argv;
+
if(argc > 1) {
fprintf(stderr, "Too many arguments!\n");
return 1;
}
static int cmd_top(int argc, char *argv[]) {
+ (void)argv;
+
if(argc > 1) {
fprintf(stderr, "Too many arguments!\n");
return 1;
#ifdef SIGINT
static void sigint_handler(int sig) {
+ (void)sig;
+
fprintf(stderr, "\n");
shutdown(fd, SHUT_RDWR);
}
}
static int cmd_pid(int argc, char *argv[]) {
+ (void)argv;
+
if(argc > 1) {
fprintf(stderr, "Too many arguments!\n");
return 1;
FILE *tf = NULL;
if(action >= -1) {
- if(snprintf(tmpfile, sizeof(tmpfile), "%s.config.tmp", filename) >= sizeof(tmpfile)) {
+ if((size_t)snprintf(tmpfile, sizeof(tmpfile), "%s.config.tmp", filename) >= sizeof(tmpfile)) {
fprintf(stderr, "Filename too long: %s.config.tmp\n", filename);
return 1;
}
#endif
static int cmd_generate_ed25519_keys(int argc, char *argv[]) {
+ (void)argv;
+
if(argc > 1) {
fprintf(stderr, "Too many arguments!\n");
return 1;
}
static int cmd_help(int argc, char *argv[]) {
+ (void)argc;
+ (void)argv;
+
usage(false);
return 0;
}
static int cmd_version(int argc, char *argv[]) {
+ (void)argv;
+
if(argc > 1) {
fprintf(stderr, "Too many arguments!\n");
return 1;
char *command;
#ifndef HAVE_MINGW
- xasprintf(&command, "\"%s\" \"%s\"", getenv("VISUAL") ? : getenv("EDITOR") ? : "vi", filename);
+ const char *editor = getenv("VISUAL");
+ if (!editor)
+ editor = getenv("EDITOR");
+ if (!editor)
+ editor = "vi";
+
+ xasprintf(&command, "\"%s\" \"%s\"", editor, filename);
#else
xasprintf(&command, "edit \"%s\"", filename);
#endif
}
static int cmd_export(int argc, char *argv[]) {
+ (void)argv;
+
if(argc > 1) {
fprintf(stderr, "Too many arguments!\n");
return 1;
}
static int cmd_export_all(int argc, char *argv[]) {
+ (void)argv;
+
if(argc > 1) {
fprintf(stderr, "Too many arguments!\n");
return 1;
}
static int cmd_import(int argc, char *argv[]) {
+ (void)argv;
+
if(argc > 1) {
fprintf(stderr, "Too many arguments!\n");
return 1;
fclose(out);
}
- if(snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name) >= sizeof(filename)) {
+ if((size_t)snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name) >= sizeof(filename)) {
fprintf(stderr, "Filename too long: %s" SLASH "%s\n", hosts_dir, name);
return 1;
}
}
static int cmd_exchange(int argc, char *argv[]) {
- return cmd_export(argc, argv) ? : cmd_import(argc, argv);
+ return cmd_export(argc, argv) ? 1 : cmd_import(argc, argv);
}
static int cmd_exchange_all(int argc, char *argv[]) {
- return cmd_export_all(argc, argv) ? : cmd_import(argc, argv);
+ return cmd_export_all(argc, argv) ? 1 : cmd_import(argc, argv);
}
static int switch_network(char *name) {
}
static int cmd_fsck(int argc, char *argv[]) {
+ (void)argv;
+
if(argc > 1) {
fprintf(stderr, "Too many arguments!\n");
return 1;
int (*function)(int argc, char *argv[]);
bool hidden;
} commands[] = {
- {"start", cmd_start},
- {"stop", cmd_stop},
- {"restart", cmd_restart},
- {"reload", cmd_reload},
- {"dump", cmd_dump},
- {"list", cmd_dump},
- {"purge", cmd_purge},
- {"debug", cmd_debug},
- {"retry", cmd_retry},
- {"connect", cmd_connect},
- {"disconnect", cmd_disconnect},
- {"top", cmd_top},
- {"pcap", cmd_pcap},
- {"log", cmd_log},
- {"pid", cmd_pid},
+ {"start", cmd_start, false},
+ {"stop", cmd_stop, false},
+ {"restart", cmd_restart, false},
+ {"reload", cmd_reload, false},
+ {"dump", cmd_dump, false},
+ {"list", cmd_dump, false},
+ {"purge", cmd_purge, false},
+ {"debug", cmd_debug, false},
+ {"retry", cmd_retry, false},
+ {"connect", cmd_connect, false},
+ {"disconnect", cmd_disconnect, false},
+ {"top", cmd_top, false},
+ {"pcap", cmd_pcap, false},
+ {"log", cmd_log, false},
+ {"pid", cmd_pid, false},
{"config", cmd_config, true},
- {"add", cmd_config},
- {"del", cmd_config},
- {"get", cmd_config},
- {"set", cmd_config},
- {"init", cmd_init},
- {"generate-keys", cmd_generate_keys},
+ {"add", cmd_config, false},
+ {"del", cmd_config, false},
+ {"get", cmd_config, false},
+ {"set", cmd_config, false},
+ {"init", cmd_init, false},
+ {"generate-keys", cmd_generate_keys, false},
#ifndef DISABLE_LEGACY
- {"generate-rsa-keys", cmd_generate_rsa_keys},
+ {"generate-rsa-keys", cmd_generate_rsa_keys, false},
#endif
- {"generate-ed25519-keys", cmd_generate_ed25519_keys},
- {"help", cmd_help},
- {"version", cmd_version},
- {"info", cmd_info},
- {"edit", cmd_edit},
- {"export", cmd_export},
- {"export-all", cmd_export_all},
- {"import", cmd_import},
- {"exchange", cmd_exchange},
- {"exchange-all", cmd_exchange_all},
- {"invite", cmd_invite},
- {"join", cmd_join},
- {"network", cmd_network},
- {"fsck", cmd_fsck},
- {"sign", cmd_sign},
- {"verify", cmd_verify},
- {NULL, NULL},
+ {"generate-ed25519-keys", cmd_generate_ed25519_keys, false},
+ {"help", cmd_help, false},
+ {"version", cmd_version, false},
+ {"info", cmd_info, false},
+ {"edit", cmd_edit, false},
+ {"export", cmd_export, false},
+ {"export-all", cmd_export_all, false},
+ {"import", cmd_import, false},
+ {"exchange", cmd_exchange, false},
+ {"exchange-all", cmd_exchange_all, false},
+ {"invite", cmd_invite, false},
+ {"join", cmd_join, false},
+ {"network", cmd_network, false},
+ {"fsck", cmd_fsck, false},
+ {"sign", cmd_sign, false},
+ {"verify", cmd_verify, false},
+ {NULL, NULL, false},
};
#ifdef HAVE_READLINE
}
static char *complete_nothing(const char *text, int state) {
+ (void)text;
+ (void)state;
return NULL;
}
static char **completion(const char *text, int start, int end) {
+ (void)end;
char **matches = NULL;
if(!start) {
static void redraw(void) {
erase();
- mvprintw(0, 0, "Tinc %-16s Nodes: %4d Sort: %-10s %s", netname ? : "", node_list.count, sortname[sortmode], cumulative ? "Cumulative" : "Current");
+ mvprintw(0, 0, "Tinc %-16s Nodes: %4d Sort: %-10s %s", netname ? netname : "", node_list.count, sortname[sortmode], cumulative ? "Cumulative" : "Current");
attrset(A_REVERSE);
mvprintw(2, 0, "Node IN %s IN %s OUT %s OUT %s", punit, bunit, punit, bunit);
chgat(-1, A_REVERSE, 0, NULL);
}
static void *upnp_thread(void *data) {
+ (void)data;
+
while(true) {
time_t start = time(NULL);
upnp_refresh();
}
}
-int hex2bin(const char *src, void *vdst, int length) {
+size_t hex2bin(const char *src, void *vdst, size_t length) {
char *dst = vdst;
- int i;
+ size_t i;
for(i = 0; i < length && isxdigit(src[i * 2]) && isxdigit(src[i * 2 + 1]); i++) {
dst[i] = charhex2bin(src[i * 2]) * 16 + charhex2bin(src[i * 2 + 1]);
return i;
}
-int bin2hex(const void *vsrc, char *dst, int length) {
+size_t bin2hex(const void *vsrc, char *dst, size_t length) {
const char *src = vsrc;
- for(int i = length - 1; i >= 0; i--) {
+ for(size_t i = length; i-- > 0;) {
dst[i * 2 + 1] = hexadecimals[(unsigned char) src[i] & 15];
dst[i * 2] = hexadecimals[(unsigned char) src[i] >> 4];
}
return length * 2;
}
-int b64decode(const char *src, void *dst, int length) {
- int i;
+size_t b64decode(const char *src, void *dst, size_t length) {
+ size_t i;
uint32_t triplet = 0;
unsigned char *udst = (unsigned char *)dst;
}
}
-static int b64encode_internal(const void *src, char *dst, int length, const char *alphabet) {
+static size_t b64encode_internal(const void *src, char *dst, size_t length, const char *alphabet) {
uint32_t triplet;
const unsigned char *usrc = (unsigned char *)src;
- int si = length / 3 * 3;
- int di = length / 3 * 4;
+ size_t si = length / 3 * 3;
+ size_t di = length / 3 * 4;
switch(length % 3) {
case 2:
return length;
}
-int b64encode(const void *src, char *dst, int length) {
+size_t b64encode(const void *src, char *dst, size_t length) {
return b64encode_internal(src, dst, length, base64_original);
}
-int b64encode_urlsafe(const void *src, char *dst, int length) {
+size_t b64encode_urlsafe(const void *src, char *dst, size_t length) {
return b64encode_internal(src, dst, length, base64_urlsafe);
}
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-extern int hex2bin(const char *src, void *dst, int length);
-extern int bin2hex(const void *src, char *dst, int length);
+extern size_t hex2bin(const char *src, void *dst, size_t length);
+extern size_t bin2hex(const void *src, char *dst, size_t length);
-extern int b64encode(const void *src, char *dst, int length);
-extern int b64encode_urlsafe(const void *src, char *dst, int length);
-extern int b64decode(const char *src, void *dst, int length);
+extern size_t b64encode(const void *src, char *dst, size_t length);
+extern size_t b64encode_urlsafe(const void *src, char *dst, size_t length);
+extern size_t b64decode(const char *src, void *dst, size_t length);
#ifdef HAVE_MINGW
extern const char *winerror(int);