diff --git a/src/base128.c b/src/base128.c index 32a29f8..7c77692 100644 --- a/src/base128.c +++ b/src/base128.c @@ -70,31 +70,31 @@ static struct encoder base128_encoder = }; struct encoder -*get_base128_encoder() +*get_base128_encoder(void) { return &base128_encoder; } static int -base128_handles_dots() +base128_handles_dots(void) { return 0; } static int -base128_blksize_raw() +base128_blksize_raw(void) { return BLKSIZE_RAW; } static int -base128_blksize_enc() +base128_blksize_enc(void) { return BLKSIZE_ENC; } inline static void -base128_reverse_init() +base128_reverse_init(void) { int i; unsigned char c; diff --git a/src/base32.c b/src/base32.c index 8731a92..4492899 100644 --- a/src/base32.c +++ b/src/base32.c @@ -25,10 +25,8 @@ #define BLKSIZE_RAW 5 #define BLKSIZE_ENC 8 -static const char cb32[] = - "abcdefghijklmnopqrstuvwxyz012345"; -static const char cb32_ucase[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"; +static const char cb32[] = "abcdefghijklmnopqrstuvwxyz012345"; +static const char cb32_ucase[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"; static unsigned char rev32[256]; static int reverse_init = 0; @@ -50,31 +48,31 @@ static struct encoder base32_encoder = }; struct encoder -*get_base32_encoder() +*get_base32_encoder(void) { return &base32_encoder; } static int -base32_handles_dots() +base32_handles_dots(void) { return 0; } static int -base32_blksize_raw() +base32_blksize_raw(void) { return BLKSIZE_RAW; } static int -base32_blksize_enc() +base32_blksize_enc(void) { return BLKSIZE_ENC; } inline static void -base32_reverse_init() +base32_reverse_init(void) { int i; unsigned char c; @@ -213,7 +211,7 @@ base32_decode(void *buf, size_t *buflen, const char *str, size_t slen) int iout = 0; /* to-be-filled output byte */ int iin = 0; /* next input char to use in decoding */ - base32_reverse_init (); + base32_reverse_init(); /* Note: Don't bother to optimize manually. GCC optimizes better(!) when using simplistic array indexing. */ diff --git a/src/base64.c b/src/base64.c index 5218c09..aeca1de 100644 --- a/src/base64.c +++ b/src/base64.c @@ -27,8 +27,7 @@ /* Note: the "unofficial" char is last here, which means that the \377 pattern in DOWNCODECCHECK1 ('Y' request) will properly test it. */ -static const char cb64[] = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789+"; +static const char cb64[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789+"; static unsigned char rev64[256]; static int reverse_init = 0; @@ -50,31 +49,31 @@ static struct encoder base64_encoder = }; struct encoder -*get_base64_encoder() +*get_base64_encoder(void) { return &base64_encoder; } static int -base64_handles_dots() +base64_handles_dots(void) { return 0; } static int -base64_blksize_raw() +base64_blksize_raw(void) { return BLKSIZE_RAW; } static int -base64_blksize_enc() +base64_blksize_enc(void) { return BLKSIZE_ENC; } inline static void -base64_reverse_init() +base64_reverse_init(void) { int i; unsigned char c; diff --git a/src/base64u.c b/src/base64u.c new file mode 100644 index 0000000..0c8de84 --- /dev/null +++ b/src/base64u.c @@ -0,0 +1,206 @@ +/* No use in editing, produced by Makefile! */ +/* + * Copyright (c) 2006-2009 Bjorn Andersson , Erik Ekman + * Mostly rewritten 2009 J.A.Bezemer@opensourcepartners.nl + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#include "encoding.h" +#include "base64u.h" + +#define BLKSIZE_RAW 3 +#define BLKSIZE_ENC 4 + +/* Note: the "unofficial" char is last here, which means that the \377 pattern + in DOWNCODECCHECK1 ('Y' request) will properly test it. */ +static const char cb64[] = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789_"; +static unsigned char rev64[256]; +static int reverse_init = 0; + +static int base64u_encode(char *, size_t *, const void *, size_t); +static int base64u_decode(void *, size_t *, const char *, size_t); +static int base64u_handles_dots(); +static int base64u_blksize_raw(); +static int base64u_blksize_enc(); + +static struct encoder base64u_encoder = +{ + "Base64u", + base64u_encode, + base64u_decode, + base64u_handles_dots, + base64u_handles_dots, + base64u_blksize_raw, + base64u_blksize_enc +}; + +struct encoder +*get_base64u_encoder(void) +{ + return &base64u_encoder; +} + +static int +base64u_handles_dots(void) +{ + return 0; +} + +static int +base64u_blksize_raw(void) +{ + return BLKSIZE_RAW; +} + +static int +base64u_blksize_enc(void) +{ + return BLKSIZE_ENC; +} + +inline static void +base64u_reverse_init(void) +{ + int i; + unsigned char c; + + if (!reverse_init) { + memset (rev64, 0, 256); + for (i = 0; i < 64; i++) { + c = cb64[i]; + rev64[(int) c] = i; + } + reverse_init = 1; + } +} + +static int +base64u_encode(char *buf, size_t *buflen, const void *data, size_t size) +/* + * Fills *buf with max. *buflen characters, encoding size bytes of *data. + * + * NOTE: *buf space should be at least 1 byte _more_ than *buflen + * to hold the trailing '\0'. + * + * return value : #bytes filled in buf (excluding \0) + * sets *buflen to : #bytes encoded from data + */ +{ + unsigned char *udata = (unsigned char *) data; + int iout = 0; /* to-be-filled output char */ + int iin = 0; /* one more than last input byte that can be + successfully decoded */ + + /* Note: Don't bother to optimize manually. GCC optimizes + better(!) when using simplistic array indexing. */ + + while (1) { + if (iout >= *buflen || iin >= size) + break; + buf[iout] = cb64[((udata[iin] & 0xfc) >> 2)]; + iout++; + + if (iout >= *buflen || iin >= size) { + iout--; /* previous char is useless */ + break; + } + buf[iout] = cb64[((udata[iin] & 0x03) << 4) | + ((iin + 1 < size) ? + ((udata[iin + 1] & 0xf0) >> 4) : 0)]; + iin++; /* 0 complete, iin=1 */ + iout++; + + if (iout >= *buflen || iin >= size) + break; + buf[iout] = cb64[((udata[iin] & 0x0f) << 2 ) | + ((iin + 1 < size) ? + ((udata[iin + 1] & 0xc0) >> 6) : 0)]; + iin++; /* 1 complete, iin=2 */ + iout++; + + if (iout >= *buflen || iin >= size) + break; + buf[iout] = cb64[(udata[iin] & 0x3f)]; + iin++; /* 2 complete, iin=3 */ + iout++; + } + + buf[iout] = '\0'; + + /* store number of bytes from data that was used */ + *buflen = iin; + + return iout; +} + +#define REV64(x) rev64[(int) (x)] + +static int +base64u_decode(void *buf, size_t *buflen, const char *str, size_t slen) +/* + * Fills *buf with max. *buflen bytes, decoded from slen chars in *str. + * Decoding stops early when *str contains \0. + * Illegal encoded chars are assumed to decode to zero. + * + * NOTE: *buf space should be at least 1 byte _more_ than *buflen + * to hold a trailing '\0' that is added (though *buf will usually + * contain full-binary data). + * + * return value : #bytes filled in buf (excluding \0) + */ +{ + unsigned char *ubuf = (unsigned char *) buf; + int iout = 0; /* to-be-filled output byte */ + int iin = 0; /* next input char to use in decoding */ + + base64u_reverse_init (); + + /* Note: Don't bother to optimize manually. GCC optimizes + better(!) when using simplistic array indexing. */ + + while (1) { + if (iout >= *buflen || iin + 1 >= slen || + str[iin] == '\0' || str[iin + 1] == '\0') + break; + ubuf[iout] = ((REV64(str[iin]) & 0x3f) << 2) | + ((REV64(str[iin + 1]) & 0x30) >> 4); + iin++; /* 0 used up, iin=1 */ + iout++; + + if (iout >= *buflen || iin + 1 >= slen || + str[iin] == '\0' || str[iin + 1] == '\0') + break; + ubuf[iout] = ((REV64(str[iin]) & 0x0f) << 4) | + ((REV64(str[iin + 1]) & 0x3c) >> 2); + iin++; /* 1 used up, iin=2 */ + iout++; + + if (iout >= *buflen || iin + 1 >= slen || + str[iin] == '\0' || str[iin + 1] == '\0') + break; + ubuf[iout] = ((REV64(str[iin]) & 0x03) << 6) | + (REV64(str[iin + 1]) & 0x3f); + iin += 2; /* 2,3 used up, iin=4 */ + iout++; + } + + ubuf[iout] = '\0'; + + return iout; +} diff --git a/src/client.c b/src/client.c index efb0f51..6f7740d 100644 --- a/src/client.c +++ b/src/client.c @@ -110,7 +110,7 @@ static long send_query_recvcnt = 0; static int hostname_maxlen = 0xFF; void -client_init() +client_init(void) { running = 1; b32 = get_base32_encoder(); @@ -136,13 +136,13 @@ client_init() } void -client_stop() +client_stop(void) { running = 0; } enum connection -client_get_conn() +client_get_conn(void) { return conn; } @@ -232,7 +232,7 @@ client_set_hostname_maxlen(int i) } const char * -client_get_raw_addr() +client_get_raw_addr(void) { return inet_ntoa(raw_serv.sin_addr); } @@ -338,7 +338,7 @@ send_packet(int fd, char cmd, const char *data, const size_t datalen) } static inline int -is_sending() +is_sending(void) { return (outpkt.len != 0); } diff --git a/src/common.c b/src/common.c index 0940ef1..017362e 100644 --- a/src/common.c +++ b/src/common.c @@ -268,7 +268,7 @@ do_pidfile(char *pidfile) } void -do_detach() +do_detach(void) { #ifndef WINDOWS32 fprintf(stderr, "Detaching from terminal...\n"); diff --git a/src/encoding.c b/src/encoding.c index 4b5fb08..bf5ffbd 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -51,7 +51,7 @@ build_hostname(char *buf, size_t buflen, strncpy(b, topdomain, strlen(topdomain)+1); - return space; + return (int) space; } int @@ -70,7 +70,7 @@ inline_dotify(char *buf, size_t buflen) unsigned total; char *reader, *writer; - total = strlen(buf); + total = (int) strlen(buf); dots = total / 57; writer = buf; @@ -81,7 +81,7 @@ inline_dotify(char *buf, size_t buflen) if (strlen(buf) + dots > buflen) { writer = buf; writer += buflen; - total = buflen; + total = (int) buflen; } reader = writer - dots; @@ -125,5 +125,5 @@ inline_undotify(char *buf, size_t len) } /* return new length of string */ - return len - dots; + return (int)(len - dots); } diff --git a/src/fw_query.c b/src/fw_query.c index 3727f08..f39ec15 100644 --- a/src/fw_query.c +++ b/src/fw_query.c @@ -20,7 +20,7 @@ static struct fw_query fwq[FW_QUERY_CACHE_SIZE]; static int fwq_ix; -void fw_query_init() +void fw_query_init(void) { memset(fwq, 0, sizeof(struct fw_query) * FW_QUERY_CACHE_SIZE); fwq_ix = 0; diff --git a/src/iodine.c b/src/iodine.c index d64da01..2a6e2f2 100644 --- a/src/iodine.c +++ b/src/iodine.c @@ -58,7 +58,7 @@ sighandler(int sig) } static void -usage() { +usage(void) { extern char *__progname; fprintf(stderr, "Usage: %s [-v] [-h] [-f] [-r] [-u user] [-t chrootdir] [-d device] " @@ -68,7 +68,7 @@ usage() { } static void -help() { +help(void) { extern char *__progname; fprintf(stderr, "iodine IP over DNS tunneling client\n"); @@ -101,7 +101,7 @@ help() { } static void -version() { +version(void) { fprintf(stderr, "iodine IP over DNS tunneling client\n"); fprintf(stderr, "Git version: %s\n", GITREVISION); diff --git a/src/iodined.c b/src/iodined.c index 7f6ee12..f097eb5 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -2173,7 +2173,7 @@ write_dns(int fd, struct query *q, char *data, int datalen, char downenc) } static void -usage() { +usage(void) { extern char *__progname; fprintf(stderr, "Usage: %s [-v] [-h] [-c] [-s] [-f] [-D] [-u user] " @@ -2185,7 +2185,7 @@ usage() { } static void -help() { +help(void) { extern char *__progname; fprintf(stderr, "iodine IP over DNS tunneling server\n"); @@ -2221,7 +2221,7 @@ help() { } static void -version() { +version(void) { fprintf(stderr, "iodine IP over DNS tunneling server\n"); fprintf(stderr, "Git version: %s\n", GITREVISION); exit(0); diff --git a/src/read.c b/src/read.c index f4ad4a8..616d516 100644 --- a/src/read.c +++ b/src/read.c @@ -119,7 +119,7 @@ readdata(char *packet, char **src, char *dst, size_t len) (*src) += len; - return len; + return (int) len; } int @@ -160,7 +160,7 @@ putname(char **buf, size_t buflen, const char *host) char *p; h = strdup(host); - left = buflen; + left = (int) buflen; p = *buf; word = strtok(h, "."); @@ -183,7 +183,7 @@ putname(char **buf, size_t buflen, const char *host) free(h); *buf = p; - return buflen - left; + return (int) (buflen - left); } int @@ -232,7 +232,7 @@ putdata(char **dst, char *data, size_t len) memcpy(*dst, data, len); (*dst) += len; - return len; + return (int) len; } int @@ -246,7 +246,7 @@ puttxtbin(char **buf, size_t bufremain, char *from, size_t fromremain) while (fromremain > 0) { - tocopy = fromremain; + tocopy = (int) fromremain; if (tocopy > 252) tocopy = 252; /* allow off-by-1s in caches etc */ if (tocopy + 1 > bufremain) diff --git a/src/user.c b/src/user.c index da589fe..47522c7 100644 --- a/src/user.c +++ b/src/user.c @@ -82,7 +82,7 @@ init_users(in_addr_t my_ip, int netbits) } const char* -users_get_first_ip() +users_get_first_ip(void) { struct in_addr ip; ip.s_addr = users[0].tun_ip; @@ -90,7 +90,7 @@ users_get_first_ip() } int -users_waiting_on_reply() +users_waiting_on_reply(void) { int ret; int i; @@ -126,7 +126,7 @@ find_user_by_ip(uint32_t ip) } int -all_users_waiting_to_send() +all_users_waiting_to_send(void) /* If this returns true, then reading from tun device is blocked. So only return true when all clients have at least one packet in the outpacket-queue, so that sending back-to-back is possible @@ -159,7 +159,7 @@ all_users_waiting_to_send() } int -find_available_user() +find_available_user(void) { int ret = -1; int i; diff --git a/src/util.c b/src/util.c index 7a365ac..d109c4b 100644 --- a/src/util.c +++ b/src/util.c @@ -18,7 +18,7 @@ #include "common.h" char * -get_resolvconf_addr() +get_resolvconf_addr(void) { static char addr[16]; char *rv;