Remove trailing whitespace

This commit is contained in:
Erik Ekman 2014-06-01 08:34:18 +02:00
parent 388afe3845
commit a23899513d
25 changed files with 275 additions and 275 deletions

View File

@ -16,7 +16,7 @@ RM_FLAGS=-f
TARGETOS = `uname`
all:
all:
@(cd src; $(MAKE) TARGETOS=$(TARGETOS) all)
install: all

View File

@ -27,7 +27,7 @@ $(SERVER): $(COMMONOBJS) $(SERVEROBJS)
@mkdir -p ../bin
@$(CC) $(COMMONOBJS) $(SERVEROBJS) -o $(SERVER) $(LDFLAGS)
.c.o:
.c.o:
@echo CC $<
@$(CC) $(CFLAGS) $< -o $@

View File

@ -42,7 +42,7 @@
* accent chars since they might readily be entered in normal use,
* don't use 254-255 because of possible function overloading in DNS systems.
*/
static const unsigned char cb128[] =
static const unsigned char cb128[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
"\274\275\276\277"
"\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317"
@ -75,19 +75,19 @@ struct encoder
return &base128_encoder;
}
static int
static int
base128_handles_dots()
{
return 0;
}
static int
static int
base128_blksize_raw()
{
return BLKSIZE_RAW;
}
static int
static int
base128_blksize_enc()
{
return BLKSIZE_ENC;
@ -109,7 +109,7 @@ base128_reverse_init()
}
}
static int
static int
base128_encode(char *buf, size_t *buflen, const void *data, size_t size)
/*
* Fills *buf with max. *buflen characters, encoding size bytes of *data.
@ -231,7 +231,7 @@ base128_decode(void *buf, size_t *buflen, const char *str, size_t slen)
if (iout >= *buflen || iin + 1 >= slen ||
str[iin] == '\0' || str[iin + 1] == '\0')
break;
ubuf[iout] = ((REV128(ustr[iin]) & 0x7f) << 1) |
ubuf[iout] = ((REV128(ustr[iin]) & 0x7f) << 1) |
((REV128(ustr[iin + 1]) & 0x40) >> 6);
iin++; /* 0 used up, iin=1 */
iout++;

View File

@ -26,9 +26,9 @@
#define BLKSIZE_RAW 5
#define BLKSIZE_ENC 8
static const char cb32[] =
static const char cb32[] =
"abcdefghijklmnopqrstuvwxyz012345";
static const char cb32_ucase[] =
static const char cb32_ucase[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
static unsigned char rev32[256];
static int reverse_init = 0;
@ -56,19 +56,19 @@ struct encoder
return &base32_encoder;
}
static int
static int
base32_handles_dots()
{
return 0;
}
static int
static int
base32_blksize_raw()
{
return BLKSIZE_RAW;
}
static int
static int
base32_blksize_enc()
{
return BLKSIZE_ENC;
@ -105,7 +105,7 @@ b32_8to5(int in)
return rev32[in];
}
static int
static int
base32_encode(char *buf, size_t *buflen, const void *data, size_t size)
/*
* Fills *buf with max. *buflen characters, encoding size bytes of *data.
@ -223,7 +223,7 @@ base32_decode(void *buf, size_t *buflen, const char *str, size_t slen)
if (iout >= *buflen || iin + 1 >= slen ||
str[iin] == '\0' || str[iin + 1] == '\0')
break;
ubuf[iout] = ((REV32(str[iin]) & 0x1f) << 3) |
ubuf[iout] = ((REV32(str[iin]) & 0x1f) << 3) |
((REV32(str[iin + 1]) & 0x1c) >> 2);
iin++; /* 0 used up, iin=1 */
iout++;
@ -232,8 +232,8 @@ base32_decode(void *buf, size_t *buflen, const char *str, size_t slen)
str[iin] == '\0' || str[iin + 1] == '\0' ||
str[iin + 2] == '\0')
break;
ubuf[iout] = ((REV32(str[iin]) & 0x03) << 6) |
((REV32(str[iin + 1]) & 0x1f) << 1) |
ubuf[iout] = ((REV32(str[iin]) & 0x03) << 6) |
((REV32(str[iin + 1]) & 0x1f) << 1) |
((REV32(str[iin + 2]) & 0x10) >> 4);
iin += 2; /* 1,2 used up, iin=3 */
iout++;

View File

@ -28,7 +28,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[] =
static const char cb64[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789+";
static unsigned char rev64[256];
static int reverse_init = 0;
@ -56,19 +56,19 @@ struct encoder
return &base64_encoder;
}
static int
static int
base64_handles_dots()
{
return 0;
}
static int
static int
base64_blksize_raw()
{
return BLKSIZE_RAW;
}
static int
static int
base64_blksize_enc()
{
return BLKSIZE_ENC;
@ -90,7 +90,7 @@ base64_reverse_init()
}
}
static int
static int
base64_encode(char *buf, size_t *buflen, const void *data, size_t size)
/*
* Fills *buf with max. *buflen characters, encoding size bytes of *data.
@ -178,7 +178,7 @@ base64_decode(void *buf, size_t *buflen, const char *str, size_t slen)
if (iout >= *buflen || iin + 1 >= slen ||
str[iin] == '\0' || str[iin + 1] == '\0')
break;
ubuf[iout] = ((REV64(str[iin]) & 0x3f) << 2) |
ubuf[iout] = ((REV64(str[iin]) & 0x3f) << 2) |
((REV64(str[iin + 1]) & 0x30) >> 4);
iin++; /* 0 used up, iin=1 */
iout++;
@ -186,7 +186,7 @@ base64_decode(void *buf, size_t *buflen, const char *str, size_t slen)
if (iout >= *buflen || iin + 1 >= slen ||
str[iin] == '\0' || str[iin + 1] == '\0')
break;
ubuf[iout] = ((REV64(str[iin]) & 0x0f) << 4) |
ubuf[iout] = ((REV64(str[iin]) & 0x0f) << 4) |
((REV64(str[iin + 1]) & 0x3c) >> 2);
iin++; /* 1 used up, iin=2 */
iout++;

View File

@ -93,10 +93,10 @@ static struct encoder *b128;
/* The encoder used for data packets
* Defaults to Base32, can be changed after handshake */
static struct encoder *dataenc;
/* The encoder to use for downstream data */
static char downenc = ' ';
/* set query type to send */
static unsigned short do_qtype = T_UNSET;
@ -214,7 +214,7 @@ set_downenc(char *encoding)
downenc = 'R';
}
void
void
client_set_selecttimeout(int select_timeout)
{
selecttimeout = select_timeout;
@ -333,7 +333,7 @@ send_packet(int fd, char cmd, const char *data, const size_t datalen)
char buf[4096];
buf[0] = cmd;
build_hostname(buf + 1, sizeof(buf) - 1, data, datalen, topdomain,
b32, hostname_maxlen);
send_query(fd, buf);
@ -366,7 +366,7 @@ send_chunk(int fd)
/* Build upstream data header (see doc/proto_xxxxxxxx.txt) */
buf[0] = userid_char; /* First byte is hex userid */
code = ((outpkt.seqno & 7) << 2) | ((outpkt.fragment & 15) >> 2);
buf[1] = b32_5to8(code); /* Second byte is 3 bits seqno, 2 upper bits fragment count */
@ -380,7 +380,7 @@ send_chunk(int fd)
datacmc++;
if (datacmc >= 36)
datacmc = 0;
#if 0
fprintf(stderr, " Send: down %d/%d up %d/%d, %d bytes\n",
inpkt.seqno, inpkt.fragment, outpkt.seqno, outpkt.fragment,
@ -395,12 +395,12 @@ send_ping(int fd)
{
if (conn == CONN_DNS_NULL) {
char data[4];
data[0] = userid;
data[1] = ((inpkt.seqno & 7) << 4) | (inpkt.fragment & 15);
data[2] = (rand_seed >> 8) & 0xff;
data[3] = (rand_seed >> 0) & 0xff;
rand_seed++;
#if 0
@ -566,7 +566,7 @@ read_dns_withq(int dns_fd, int tun_fd, char *buf, int buflen, struct query *q)
int r;
addrlen = sizeof(from);
if ((r = recvfrom(dns_fd, data, sizeof(data), 0,
if ((r = recvfrom(dns_fd, data, sizeof(data), 0,
(struct sockaddr*)&from, &addrlen)) < 0) {
warn("recvfrom");
return -1;
@ -588,9 +588,9 @@ read_dns_withq(int dns_fd, int tun_fd, char *buf, int buflen, struct query *q)
/*
* buf is a hostname or txt stream that we still need to
* decode to binary
*
*
* also update rv with the number of valid bytes
*
*
* data is unused here, and will certainly hold the smaller binary
*/
@ -1131,11 +1131,11 @@ client_tunnel(int tun_fd, int dns_fd)
warnx("No downstream data received in 60 seconds, shutting down.");
running = 0;
}
if (running == 0)
break;
if (i < 0)
if (i < 0)
err(1, "select");
if (i == 0) {
@ -1178,7 +1178,7 @@ client_tunnel(int tun_fd, int dns_fd)
if (FD_ISSET(dns_fd, &fds)) {
if (tunnel_dns(tun_fd, dns_fd) <= 0)
continue;
}
}
}
}
@ -1196,7 +1196,7 @@ send_login(int fd, char *login, int len)
data[17] = (rand_seed >> 8) & 0xff;
data[18] = (rand_seed >> 0) & 0xff;
rand_seed++;
send_packet(fd, 'l', data, sizeof(data));
@ -1235,23 +1235,23 @@ static void
send_set_downstream_fragsize(int fd, int fragsize)
{
char data[5];
data[0] = userid;
data[1] = (fragsize & 0xff00) >> 8;
data[2] = (fragsize & 0x00ff);
data[3] = (rand_seed >> 8) & 0xff;
data[4] = (rand_seed >> 0) & 0xff;
rand_seed++;
send_packet(fd, 'n', data, sizeof(data));
}
static void
static void
send_version(int fd, uint32_t version)
{
char data[6];
data[0] = (version >> 24) & 0xff;
data[1] = (version >> 16) & 0xff;
data[2] = (version >> 8) & 0xff;
@ -1259,7 +1259,7 @@ send_version(int fd, uint32_t version)
data[4] = (rand_seed >> 8) & 0xff;
data[5] = (rand_seed >> 0) & 0xff;
rand_seed++;
send_packet(fd, 'v', data, sizeof(data));
@ -1270,7 +1270,7 @@ send_ip_request(int fd, int userid)
{
char buf[512] = "i____.";
buf[1] = b32_5to8(userid);
buf[2] = b32_5to8((rand_seed >> 10) & 0x1f);
buf[3] = b32_5to8((rand_seed >> 5) & 0x1f);
buf[4] = b32_5to8((rand_seed ) & 0x1f);
@ -1294,7 +1294,7 @@ send_upenctest(int fd, char *s)
/* NOTE: String may be at most 63-4=59 chars to fit in 1 dns chunk. */
{
char buf[512] = "z___";
buf[1] = b32_5to8((rand_seed >> 10) & 0x1f);
buf[2] = b32_5to8((rand_seed >> 5) & 0x1f);
buf[3] = b32_5to8((rand_seed ) & 0x1f);
@ -1330,7 +1330,7 @@ send_codec_switch(int fd, int userid, int bits)
char buf[512] = "s_____.";
buf[1] = b32_5to8(userid);
buf[2] = b32_5to8(bits);
buf[3] = b32_5to8((rand_seed >> 10) & 0x1f);
buf[4] = b32_5to8((rand_seed >> 5) & 0x1f);
buf[5] = b32_5to8((rand_seed ) & 0x1f);
@ -1408,7 +1408,7 @@ handshake_version(int dns_fd, int *seed)
fprintf(stderr, "Version ok, both using protocol v 0x%08x. You are user #%d\n", VERSION, userid);
return 0;
} else if (strncmp("VNAK", in, 4) == 0) {
warnx("You use protocol v 0x%08x, server uses v 0x%08x. Giving up",
warnx("You use protocol v 0x%08x, server uses v 0x%08x. Giving up",
VERSION, payload);
return 1;
} else if (strncmp("VFUL", in, 4) == 0) {
@ -1417,7 +1417,7 @@ handshake_version(int dns_fd, int *seed)
}
} else if (read > 0)
warnx("did not receive proper login challenge");
fprintf(stderr, "Retrying version check...\n");
}
warnx("couldn't connect to server (maybe other -T options will work)");
@ -1436,7 +1436,7 @@ handshake_login(int dns_fd, int seed)
int read;
login_calculate(login, 16, password, seed);
for (i=0; running && i<5 ;i++) {
send_login(dns_fd, login, 16);
@ -1510,7 +1510,7 @@ handshake_raw_udp(int dns_fd, int seed)
fprintf(stderr, "\n");
if (!running)
return 0;
if (!remoteaddr) {
fprintf(stderr, "Failed to get raw server IP, will use DNS mode.\n");
return 0;
@ -1524,7 +1524,7 @@ handshake_raw_udp(int dns_fd, int seed)
raw_serv.sin_port = htons(53);
raw_serv.sin_addr = server;
/* do login against port 53 on remote server
/* do login against port 53 on remote server
* based on the old seed. If reply received,
* switch to raw udp mode */
for (i=0; running && i<4 ;i++) {
@ -1532,7 +1532,7 @@ handshake_raw_udp(int dns_fd, int seed)
tv.tv_usec = 0;
send_raw_udp_login(dns_fd, userid, seed);
FD_ZERO(&fds);
FD_SET(dns_fd, &fds);
@ -1545,7 +1545,7 @@ handshake_raw_udp(int dns_fd, int seed)
char hash[16];
login_calculate(hash, 16, password, seed - 1);
if (memcmp(in, raw_header, RAW_HDR_IDENT_LEN) == 0
&& RAW_HDR_GET_CMD(in) == RAW_HDR_CMD_LOGIN
&& RAW_HDR_GET_CMD(in) == RAW_HDR_CMD_LOGIN
&& memcmp(&in[RAW_HDR_LEN], hash, sizeof(hash)) == 0) {
fprintf(stderr, "OK\n");
@ -1556,7 +1556,7 @@ handshake_raw_udp(int dns_fd, int seed)
fprintf(stderr, ".");
fflush(stderr);
}
fprintf(stderr, "failed\n");
return 0;
}
@ -2024,7 +2024,7 @@ handshake_switch_codec(int dns_fd, int bits)
for (i=0; running && i<5 ;i++) {
send_codec_switch(dns_fd, userid, bits);
read = handshake_waitdns(dns_fd, in, sizeof(in), 's', 'S', i+1);
if (read > 0) {
@ -2051,7 +2051,7 @@ handshake_switch_codec(int dns_fd, int bits)
fprintf(stderr, "No reply from server on codec switch. ");
codec_revert:
codec_revert:
fprintf(stderr, "Falling back to upstream codec %s\n", dataenc->name);
}
@ -2103,7 +2103,7 @@ handshake_switch_downenc(int dns_fd)
fprintf(stderr, "No reply from server on codec switch. ");
codec_revert:
codec_revert:
fprintf(stderr, "Falling back to downstream codec Base32\n");
}
@ -2145,7 +2145,7 @@ handshake_try_lazy(int dns_fd)
fprintf(stderr, "No reply from server on lazy switch. ");
codec_revert:
codec_revert:
fprintf(stderr, "Falling back to legacy mode\n");
lazymode = 0;
selecttimeout = 1;
@ -2262,7 +2262,7 @@ handshake_autoprobe_fragsize(int dns_fd)
int max_fragsize;
max_fragsize = 0;
fprintf(stderr, "Autoprobing max downstream fragment size... (skip with -m fragsize)\n");
fprintf(stderr, "Autoprobing max downstream fragment size... (skip with -m fragsize)\n");
while (running && range > 0 && (range >= 8 || max_fragsize < 300)) {
/* stop the slow probing early when we have enough bytes anyway */
for (i=0; running && i<3 ;i++) {
@ -2270,7 +2270,7 @@ handshake_autoprobe_fragsize(int dns_fd)
send_fragsize_probe(dns_fd, proposed_fragsize);
read = handshake_waitdns(dns_fd, in, sizeof(in), 'r', 'R', 1);
if (read > 0) {
/* We got a reply */
if (fragsize_check(in, read, proposed_fragsize, &max_fragsize) == 1)

View File

@ -61,7 +61,7 @@ const unsigned char raw_header[RAW_HDR_LEN] = { 0x10, 0xd1, 0x9e, 0x00 };
static int daemon(int nochdir, int noclose)
{
int fd, i;
switch (fork()) {
case 0:
break;
@ -70,15 +70,15 @@ static int daemon(int nochdir, int noclose)
default:
_exit(0);
}
if (!nochdir) {
chdir("/");
}
if (setsid() < 0) {
return -1;
}
if (!noclose) {
if ((fd = open("/dev/null", O_RDWR)) >= 0) {
for (i = 0; i < 3; i++) {
@ -170,7 +170,7 @@ get_addr(char *host, int port, int addr_family, int flags, struct sockaddr_stora
return res;
}
int
int
open_dns(struct sockaddr_storage *sockaddr, size_t sockaddr_len)
{
int flag = 1;
@ -291,7 +291,7 @@ read_password(char *buf, size_t len)
tcgetattr(0, &tp);
old = tp;
tp.c_lflag &= (~ECHO);
tcsetattr(0, TCSANOW, &tp);
#else
@ -317,7 +317,7 @@ read_password(char *buf, size_t len)
fprintf(stderr, "\n");
#ifndef WINDOWS32
tcsetattr(0, TCSANOW, &old);
tcsetattr(0, TCSANOW, &old);
#endif
strncpy(buf, pwd, len);
@ -360,7 +360,7 @@ check_topdomain(char *str, char **errormsg)
} else {
chunklen++;
}
if( (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') ||
if( (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') ||
isdigit(str[i]) || str[i] == '-' || str[i] == '.' ) {
continue;
} else {
@ -404,7 +404,7 @@ warn(const char *fmt, ...)
if (fmt) fprintf(stderr, fmt, list);
#ifndef ANDROID
if (errno == 0) {
fprintf(stderr, ": WSA error %d\n", WSAGetLastError());
fprintf(stderr, ": WSA error %d\n", WSAGetLastError());
} else {
fprintf(stderr, ": %s\n", strerror(errno));
}

View File

@ -53,12 +53,12 @@ extern const unsigned char raw_header[RAW_HDR_LEN];
#define QUERY_NAME_SIZE 256
#if defined IP_RECVDSTADDR
# define DSTADDR_SOCKOPT IP_RECVDSTADDR
# define dstaddr(x) ((struct in_addr *) CMSG_DATA(x))
#elif defined IP_PKTINFO
# define DSTADDR_SOCKOPT IP_PKTINFO
# define dstaddr(x) (&(((struct in_pktinfo *)(CMSG_DATA(x)))->ipi_addr))
#if defined IP_RECVDSTADDR
# define DSTADDR_SOCKOPT IP_RECVDSTADDR
# define dstaddr(x) ((struct in_addr *) CMSG_DATA(x))
#elif defined IP_PKTINFO
# define DSTADDR_SOCKOPT IP_PKTINFO
# define dstaddr(x) (&(((struct in_pktinfo *)(CMSG_DATA(x)))->ipi_addr))
#endif
#if defined IP_MTU_DISCOVER
@ -78,7 +78,7 @@ extern const unsigned char raw_header[RAW_HDR_LEN];
#define T_UNSET 65432
/* Unused RR type; "private use" range, see http://www.bind9.net/dns-parameters */
struct packet
struct packet
{
int len; /* Total packet length */
int sentlen; /* Length of chunk currently transmitted */

View File

@ -62,9 +62,9 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
return 0;
memset(buf, 0, buflen);
header = (HEADER*)buf;
header->id = htons(q->id);
header->qr = (qr == QR_ANSWER);
header->opcode = 0;
@ -78,7 +78,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
switch (qr) {
case QR_ANSWER:
header->qdcount = htons(1);
name = 0xc000 | ((p - buf) & 0x3fff);
/* Question section */
@ -97,7 +97,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
int namelen;
CHECKLEN(10);
putshort(&p, name);
putshort(&p, name);
if (q->type == T_A)
/* answer CNAME to A question */
putshort(&p, T_CNAME);
@ -127,7 +127,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
ancnt = 1;
while (1) {
CHECKLEN(10);
putshort(&p, name);
putshort(&p, name);
putshort(&p, q->type);
putshort(&p, C_IN);
putlong(&p, 0); /* TTL */
@ -162,7 +162,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
int txtlen;
CHECKLEN(10);
putshort(&p, name);
putshort(&p, name);
putshort(&p, q->type);
putshort(&p, C_IN);
putlong(&p, 0); /* TTL */
@ -179,7 +179,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
/* NULL has raw binary data */
CHECKLEN(10);
putshort(&p, name);
putshort(&p, name);
putshort(&p, q->type);
putshort(&p, C_IN);
putlong(&p, 0); /* TTL */
@ -198,7 +198,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
/* Note that iodined also uses this for forward queries */
header->qdcount = htons(1);
datalen = MIN(datalen, buflen - (p - buf));
putname(&p, datalen, data);
@ -221,7 +221,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
break;
}
len = p - buf;
return len;
@ -245,9 +245,9 @@ dns_encode_ns_response(char *buf, size_t buflen, struct query *q, char *topdomai
return 0;
memset(buf, 0, buflen);
header = (HEADER*)buf;
header->id = htons(q->id);
header->qr = 1;
header->opcode = 0;
@ -334,9 +334,9 @@ dns_encode_a_response(char *buf, size_t buflen, struct query *q)
return 0;
memset(buf, 0, buflen);
header = (HEADER*)buf;
header->id = htons(q->id);
header->qr = 1;
header->opcode = 0;
@ -408,7 +408,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
short type;
char *data;
short rlen;
int id;
int id;
int rv;
q->id2 = 0;
@ -416,9 +416,9 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
header = (HEADER*)packet;
/* Reject short packets */
if (packetlen < sizeof(HEADER))
if (packetlen < sizeof(HEADER))
return 0;
if (header->qr != qr) {
warnx("header->qr does not match the requested qr");
return -1;
@ -427,13 +427,13 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
data = packet + sizeof(HEADER);
qdcount = ntohs(header->qdcount);
ancount = ntohs(header->ancount);
id = ntohs(header->id);
id = id & 0xFFFF; /* Kill any sign extension */
rlen = 0;
if (q != NULL)
if (q != NULL)
q->rcode = header->rcode;
switch (qr) {
@ -443,7 +443,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
return -1;
}
if (q != NULL)
if (q != NULL)
q->id = id;
/* Read name even if no answer, to give better error message */
@ -451,14 +451,14 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
CHECKLEN(4);
readshort(packet, &data, &type);
readshort(packet, &data, &class);
/* if CHECKLEN okay, then we're sure to have a proper name */
if (q != NULL) {
/* We only need the first char to check it */
q->name[0] = name[0];
q->name[1] = '\0';
}
}
if (ancount < 1) {
/* DNS errors like NXDOMAIN have ancount=0 and
stop here. CNAME may also have A; MX/SRV may have
@ -539,7 +539,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
names[pref / 10 - 1][QUERY_NAME_SIZE-1] = '\0';
}
/* always trust rlen, not name encoding */
/* always trust rlen, not name encoding */
data = rdatastart + rlen;
CHECKLEN(0);
}

View File

@ -20,8 +20,8 @@
#include "encoding.h"
int
build_hostname(char *buf, size_t buflen,
const char *data, const size_t datalen,
build_hostname(char *buf, size_t buflen,
const char *data, const size_t datalen,
const char *topdomain, struct encoder *encoder, int maxlen)
{
size_t space;
@ -34,7 +34,7 @@ build_hostname(char *buf, size_t buflen,
space -= (space / 57); /* space for dots */
memset(buf, 0, buflen);
encoder->encode(buf, &space, data, datalen);
if (!encoder->places_dots())
@ -45,7 +45,7 @@ build_hostname(char *buf, size_t buflen,
/* move b back one step to see if the dot is there */
b--;
if (*b != '.')
if (*b != '.')
*++b = '.';
b++;
/* move b ahead of the string so we can copy to it */
@ -63,7 +63,7 @@ unpack_data(char *buf, size_t buflen, char *data, size_t datalen, struct encoder
return enc->decode(buf, &buflen, data, datalen);
}
int
int
inline_dotify(char *buf, size_t buflen)
{
unsigned dots;
@ -101,7 +101,7 @@ inline_dotify(char *buf, size_t buflen)
return total;
}
int
int
inline_undotify(char *buf, size_t len)
{
unsigned pos;
@ -124,7 +124,7 @@ inline_undotify(char *buf, size_t len)
*writer++ = *reader++;
pos++;
}
/* return new length of string */
return len - dots;
}

View File

@ -29,9 +29,9 @@ void fw_query_init()
void fw_query_put(struct fw_query *fw_query)
{
memcpy(&(fwq[fwq_ix]), fw_query, sizeof(struct fw_query));
++fwq_ix;
if (fwq_ix >= FW_QUERY_CACHE_SIZE)
if (fwq_ix >= FW_QUERY_CACHE_SIZE)
fwq_ix = 0;
}

View File

@ -53,7 +53,7 @@ static char *__progname;
#define PASSWORD_ENV_VAR "IODINE_PASS"
static void
sighandler(int sig)
sighandler(int sig)
{
client_stop();
}
@ -179,7 +179,7 @@ main(int argc, char **argv)
srand((unsigned) time(NULL));
client_init();
#if !defined(BSD) && !defined(__GLIBC__)
__progname = strrchr(argv[0], '/');
if (__progname == NULL)
@ -227,9 +227,9 @@ main(int argc, char **argv)
case 'P':
strncpy(password, optarg, sizeof(password));
password[sizeof(password)-1] = 0;
/* XXX: find better way of cleaning up ps(1) */
memset(optarg, 0, strlen(optarg));
memset(optarg, 0, strlen(optarg));
break;
case 'm':
autodetect_frag_size = 0;
@ -247,7 +247,7 @@ main(int argc, char **argv)
break;
case 'F':
pidfile = optarg;
break;
break;
case 'T':
set_qtype(optarg);
break;
@ -273,7 +273,7 @@ main(int argc, char **argv)
/* NOTREACHED */
}
}
check_superuser(usage);
argc -= optind;
@ -310,7 +310,7 @@ main(int argc, char **argv)
warnx("No nameserver found - not connected to any network?\n");
usage();
/* NOTREACHED */
}
}
if(check_topdomain(topdomain, &errormsg)) {
warnx("Invalid topdomain: %s", errormsg);
@ -322,7 +322,7 @@ main(int argc, char **argv)
client_set_lazymode(lazymode);
client_set_topdomain(topdomain);
client_set_hostname_maxlen(hostname_maxlen);
if (username != NULL) {
#ifndef WINDOWS32
if ((pw = getpwnam(username)) == NULL) {
@ -332,14 +332,14 @@ main(int argc, char **argv)
}
#endif
}
if (strlen(password) == 0) {
if (NULL != getenv(PASSWORD_ENV_VAR))
snprintf(password, sizeof(password), "%s", getenv(PASSWORD_ENV_VAR));
else
read_password(password, sizeof(password));
}
client_set_password(password);
if ((tun_fd = open_tun(device)) == -1) {
@ -365,22 +365,22 @@ main(int argc, char **argv)
retval = 1;
goto cleanup2;
}
if (client_get_conn() == CONN_RAW_UDP) {
fprintf(stderr, "Sending raw traffic directly to %s\n", client_get_raw_addr());
}
fprintf(stderr, "Connection setup complete, transmitting data.\n");
if (foreground == 0)
if (foreground == 0)
do_detach();
if (pidfile != NULL)
do_pidfile(pidfile);
if (newroot != NULL)
do_chroot(newroot);
if (username != NULL) {
#ifndef WINDOWS32
gid_t gids[1];

View File

@ -152,7 +152,7 @@ static int get_external_ip(struct in_addr *ip)
}
static void
sigint(int sig)
sigint(int sig)
{
running = 0;
}
@ -182,7 +182,7 @@ check_user_and_ip(int userid, struct query *q)
/* Note: duplicate in handle_raw_login() except IP-address check */
if (userid < 0 || userid >= created_users ) {
return 1;
return 1;
}
if (!users[userid].active || users[userid].disabled) {
return 1;
@ -217,7 +217,7 @@ send_raw(int fd, char *buf, int buflen, int user, int cmd, struct query *q)
packet[RAW_HDR_CMD] = cmd | (user & 0x0F);
if (debug >= 2) {
fprintf(stderr, "TX-raw: client %s, cmd %d, %d bytes\n",
fprintf(stderr, "TX-raw: client %s, cmd %d, %d bytes\n",
format_addr(&q->from, q->fromlen), cmd, len);
}
@ -552,12 +552,12 @@ send_chunk_or_dataless(int dns_fd, int userid, struct query *q)
pkt[0] = (1<<7) | ((users[userid].inpacket.seqno & 7) << 4) |
(users[userid].inpacket.fragment & 15);
/* Second byte is 3 bits downstream seqno, 4 bits downstream fragment, 1 bit last flag */
pkt[1] = ((users[userid].outpacket.seqno & 7) << 5) |
pkt[1] = ((users[userid].outpacket.seqno & 7) << 5) |
((users[userid].outpacket.fragment & 15) << 1) | (last & 1);
if (debug >= 1) {
fprintf(stderr, "OUT pkt seq# %d, frag %d (last=%d), offset %d, fragsize %d, total %d, to user %d\n",
users[userid].outpacket.seqno & 7, users[userid].outpacket.fragment & 15,
users[userid].outpacket.seqno & 7, users[userid].outpacket.fragment & 15,
last, users[userid].outpacket.offset, datalen, users[userid].outpacket.len, userid);
}
write_dns(dns_fd, q, pkt, datalen + 2, users[userid].downenc);
@ -611,7 +611,7 @@ tunnel_tun(int tun_fd, int dns_fd)
if ((read = read_tun(tun_fd, in, sizeof(in))) <= 0)
return 0;
/* find target ip in packet, in is padded with 4 bytes TUN header */
header = (struct ip*) (in + 4);
userid = find_user_by_ip(header->ip_dst.s_addr);
@ -657,7 +657,7 @@ static void
send_version_response(int fd, version_ack_t ack, uint32_t payload, int userid, struct query *q)
{
char out[9];
switch (ack) {
case VERSION_ACK:
strncpy(out, "VACK", sizeof(out));
@ -669,7 +669,7 @@ send_version_response(int fd, version_ack_t ack, uint32_t payload, int userid, s
strncpy(out, "VFUL", sizeof(out));
break;
}
out[4] = ((payload >> 24) & 0xff);
out[5] = ((payload >> 16) & 0xff);
out[6] = ((payload >> 8) & 0xff);
@ -742,7 +742,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), domain_len - 1, b32);
/* Version greeting, compare and send ack/nak */
if (read > 4) {
if (read > 4) {
/* Received V + 32bits version */
version = (((unpacked[0] & 0xff) << 24) |
((unpacked[1] & 0xff) << 16) |
@ -760,7 +760,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
/* Store remote IP number */
tempin = (struct sockaddr_in *) &(q->from);
memcpy(&(users[userid].host), &(tempin->sin_addr), sizeof(struct in_addr));
memcpy(&(users[userid].q), q, sizeof(struct query));
users[userid].encoder = get_base32_encoder();
users[userid].downenc = 'T';
@ -807,12 +807,12 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
} else {
/* No space for another user */
send_version_response(dns_fd, VERSION_FULL, created_users, 0, q);
syslog(LOG_INFO, "dropped user from %s, server full",
syslog(LOG_INFO, "dropped user from %s, server full",
format_addr(&q->from, q->fromlen));
}
} else {
send_version_response(dns_fd, VERSION_NACK, VERSION, 0, q);
syslog(LOG_INFO, "dropped user from %s, sent bad version %08X",
syslog(LOG_INFO, "dropped user from %s, sent bad version %08X",
format_addr(&q->from, q->fromlen), version);
}
return;
@ -843,7 +843,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
tempip.s_addr = users[userid].tun_ip;
tmp[1] = strdup(inet_ntoa(tempip));
read = snprintf(out, sizeof(out), "%s-%s-%d-%d",
read = snprintf(out, sizeof(out), "%s-%s-%d-%d",
tmp[0], tmp[1], my_mtu, netmask);
write_dns(dns_fd, q, out, read, users[userid].downenc);
@ -864,7 +864,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
in_addr_t replyaddr;
unsigned addr;
char reply[5];
userid = b32_8to5(in[1]);
if (check_user_and_ip(userid, q) != 0) {
write_dns(dns_fd, q, "BADIP", 5, 'T');
@ -902,12 +902,12 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
}
userid = b32_8to5(in[1]);
if (check_user_and_ip(userid, q) != 0) {
write_dns(dns_fd, q, "BADIP", 5, 'T');
return; /* illegal id */
}
codec = b32_8to5(in[2]);
switch (codec) {
@ -1076,9 +1076,9 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
write_dns(dns_fd, q, "BADIP", 5, 'T');
return; /* illegal id */
}
req_frag_size = ((b32_8to5(in[1]) & 1) << 10) | ((b32_8to5(in[2]) & 31) << 5) | (b32_8to5(in[3]) & 31);
if (req_frag_size < 2 || req_frag_size > 2047) {
if (req_frag_size < 2 || req_frag_size > 2047) {
write_dns(dns_fd, q, "BADFRAG", 7, users[userid].downenc);
} else {
char buf[2048];
@ -1111,9 +1111,9 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
write_dns(dns_fd, q, "BADIP", 5, 'T');
return; /* illegal id */
}
max_frag_size = ((unpacked[1] & 0xff) << 8) | (unpacked[2] & 0xff);
if (max_frag_size < 2) {
if (max_frag_size < 2) {
write_dns(dns_fd, q, "BADFRAG", 7, users[userid].downenc);
} else {
users[userid].fragsize = max_frag_size;
@ -1178,7 +1178,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
memcpy(&(users[userid].q.from2), &(q->from), q->fromlen);
return;
}
if (users[userid].q_sendrealsoon.id != 0 &&
q->type == users[userid].q_sendrealsoon.type &&
!strcmp(q->name, users[userid].q_sendrealsoon.name)) {
@ -1194,7 +1194,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
&(q->from), q->fromlen);
return;
}
dn_seq = unpacked[1] >> 4;
dn_frag = unpacked[1] & 15;
@ -1289,7 +1289,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
like to re-try early and often (with _different_ .id!) */
if (users[userid].q.id != 0 &&
q->type == users[userid].q.type &&
!strcmp(q->name, users[userid].q.name) &&
!strcmp(q->name, users[userid].q.name) &&
users[userid].lazy) {
/* We have this packet already, and it's waiting to be
answered. Always keep the last duplicate, since the
@ -1306,7 +1306,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
memcpy(&(users[userid].q.from2), &(q->from), q->fromlen);
return;
}
if (users[userid].q_sendrealsoon.id != 0 &&
q->type == users[userid].q_sendrealsoon.type &&
!strcmp(q->name, users[userid].q_sendrealsoon.name)) {
@ -1322,7 +1322,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
&(q->from), q->fromlen);
return;
}
/* Decode data header */
up_seq = (b32_8to5(in[1]) >> 2) & 7;
@ -1333,7 +1333,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
process_downstream_ack(userid, dn_seq, dn_frag);
if (up_seq == users[userid].inpacket.seqno &&
if (up_seq == users[userid].inpacket.seqno &&
up_frag <= users[userid].inpacket.fragment) {
/* Got repeated old packet _with data_, probably
because client didn't receive our ack. So re-send
@ -1491,9 +1491,9 @@ handle_ns_request(int dns_fd, struct query *q)
warnx("dns_encode_ns_response doesn't fit");
return;
}
if (debug >= 2) {
fprintf(stderr, "TX: client %s, type %d, name %s, %d bytes NS reply\n",
fprintf(stderr, "TX: client %s, type %d, name %s, %d bytes NS reply\n",
format_addr(&q->from, q->fromlen), q->type, q->name, len);
}
if (sendto(dns_fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen) <= 0) {
@ -1523,7 +1523,7 @@ handle_a_request(int dns_fd, struct query *q, int fakeip)
warnx("dns_encode_a_response doesn't fit");
return;
}
if (debug >= 2) {
fprintf(stderr, "TX: client %s, type %d, name %s, %d bytes A reply\n",
format_addr(&q->from, q->fromlen), q->type, q->name, len);
@ -1558,7 +1558,7 @@ forward_query(int bind_fd, struct query *q)
myaddr = (struct sockaddr_in *) &(q->from);
memcpy(&(myaddr->sin_addr), &newaddr, sizeof(in_addr_t));
myaddr->sin_port = htons(bind_port);
if (debug >= 2) {
fprintf(stderr, "TX: NS reply \n");
}
@ -1567,7 +1567,7 @@ forward_query(int bind_fd, struct query *q)
warn("forward query error");
}
}
static int
tunnel_bind(int bind_fd, int dns_fd)
{
@ -1579,14 +1579,14 @@ tunnel_bind(int bind_fd, int dns_fd)
int r;
fromlen = sizeof(struct sockaddr);
r = recvfrom(bind_fd, packet, sizeof(packet), 0,
r = recvfrom(bind_fd, packet, sizeof(packet), 0,
(struct sockaddr*)&from, &fromlen);
if (r <= 0)
return 0;
id = dns_get_id(packet, r);
if (debug >= 2) {
fprintf(stderr, "RX: Got response on query %u from DNS\n", (id & 0xFFFF));
}
@ -1604,8 +1604,8 @@ tunnel_bind(int bind_fd, int dns_fd)
fprintf(stderr, "TX: client %s id %u, %d bytes\n",
format_addr(&query->addr, query->addrlen), (id & 0xffff), r);
}
if (sendto(dns_fd, packet, r, 0, (const struct sockaddr *) &(query->addr),
if (sendto(dns_fd, packet, r, 0, (const struct sockaddr *) &(query->addr),
query->addrlen) <= 0) {
warn("forward reply error");
}
@ -1625,7 +1625,7 @@ tunnel_dns(int tun_fd, int dns_fd, int bind_fd)
return 0;
if (debug >= 2) {
fprintf(stderr, "RX: client %s, type %d, name %s\n",
fprintf(stderr, "RX: client %s, type %d, name %s\n",
format_addr(&q.from, q.fromlen), q.type, q.name);
}
@ -1736,9 +1736,9 @@ tunnel(int tun_fd, int dns_fd, int bind_fd, int max_idle_time)
}
i = select(maxfd + 1, &fds, NULL, NULL, &tv);
if(i < 0) {
if (running)
if (running)
warn("select");
return 1;
}
@ -1763,7 +1763,7 @@ tunnel(int tun_fd, int dns_fd, int bind_fd, int max_idle_time)
}
if (FD_ISSET(dns_fd, &fds)) {
tunnel_dns(tun_fd, dns_fd, bind_fd);
}
}
if (FD_ISSET(bind_fd, &fds)) {
tunnel_bind(bind_fd, dns_fd);
}
@ -1791,7 +1791,7 @@ handle_full_packet(int tun_fd, int dns_fd, int userid)
int ret;
outlen = sizeof(out);
ret = uncompress((uint8_t*)out, &outlen,
ret = uncompress((uint8_t*)out, &outlen,
(uint8_t*)users[userid].inpacket.data, users[userid].inpacket.len);
if (ret == Z_OK) {
@ -1843,7 +1843,7 @@ static void
handle_raw_login(char *packet, int len, struct query *q, int fd, int userid)
{
char myhash[16];
if (len < 16) return;
/* can't use check_user_and_ip() since IP address will be different,
@ -1869,7 +1869,7 @@ handle_raw_login(char *packet, int len, struct query *q, int fd, int userid)
/* Store remote IP number */
tempin = (struct sockaddr_in *) &(q->from);
memcpy(&(users[userid].host), &(tempin->sin_addr), sizeof(struct in_addr));
/* Correct hash, reply with hash of seed - 1 */
user_set_conn_type(userid, CONN_RAW_UDP);
login_calculate(myhash, 16, password, users[userid].seed - 1);
@ -1975,7 +1975,7 @@ read_dns(int fd, int tun_fd, struct query *q) /* FIXME: tun_fd is because of raw
msg.msg_control = address;
msg.msg_controllen = sizeof(address);
msg.msg_flags = 0;
r = recvmsg(fd, &msg, 0);
#else
addrlen = sizeof(struct sockaddr);
@ -1993,22 +1993,22 @@ read_dns(int fd, int tun_fd, struct query *q) /* FIXME: tun_fd is because of raw
if (dns_decode(NULL, 0, q, QR_QUERY, packet, r) < 0) {
return 0;
}
#ifndef WINDOWS32
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level == IPPROTO_IP &&
cmsg->cmsg_type == DSTADDR_SOCKOPT) {
q->destination = *dstaddr(cmsg);
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level == IPPROTO_IP &&
cmsg->cmsg_type == DSTADDR_SOCKOPT) {
q->destination = *dstaddr(cmsg);
break;
}
}
}
#endif
return strlen(q->name);
} else if (r < 0) {
} else if (r < 0) {
/* Error */
warn("read dns");
}
@ -2073,7 +2073,7 @@ write_dns_nameenc(char *buf, size_t buflen, char *data, int datalen, char downen
/* Add dot (if it wasn't there already) and topdomain */
b = buf;
b += strlen(buf) - 1;
if (*b != '.')
if (*b != '.')
*++b = '.';
b++;
@ -2165,9 +2165,9 @@ write_dns(int fd, struct query *q, char *data, int datalen, char downenc)
warnx("dns_encode doesn't fit");
return;
}
if (debug >= 2) {
fprintf(stderr, "TX: client %s, type %d, name %s, %d bytes data\n",
fprintf(stderr, "TX: client %s, type %d, name %s, %d bytes data\n",
format_addr(&q->from, q->fromlen), q->type, q->name, datalen);
}
@ -2247,11 +2247,11 @@ main(int argc, char **argv)
int dnsd_fd;
int tun_fd;
/* settings for forwarding normal DNS to
/* settings for forwarding normal DNS to
* local real DNS server */
int bind_fd;
int bind_enable;
int choice;
int port;
int mtu;
@ -2293,7 +2293,7 @@ main(int argc, char **argv)
b64 = get_base64_encoder();
b64u = get_base64u_encoder();
b128 = get_base128_encoder();
retval = 0;
#ifdef WINDOWS32
@ -2311,7 +2311,7 @@ main(int argc, char **argv)
memset(password, 0, sizeof(password));
srand(time(NULL));
fw_query_init();
while ((choice = getopt(argc, argv, "vcsfhDu:t:d:m:l:p:n:b:P:z:F:i:")) != -1) {
switch(choice) {
case 'v':
@ -2363,16 +2363,16 @@ main(int argc, char **argv)
break;
case 'F':
pidfile = optarg;
break;
break;
case 'i':
max_idle_time = atoi(optarg);
break;
case 'P':
strncpy(password, optarg, sizeof(password));
password[sizeof(password)-1] = 0;
/* XXX: find better way of cleaning up ps(1) */
memset(optarg, 0, strlen(optarg));
memset(optarg, 0, strlen(optarg));
break;
case 'z':
context = optarg;
@ -2388,9 +2388,9 @@ main(int argc, char **argv)
check_superuser(usage);
if (argc != 2)
if (argc != 2)
usage();
netsize = strchr(argv[0], '/');
if (netsize) {
*netsize = 0;
@ -2399,7 +2399,7 @@ main(int argc, char **argv)
}
my_ip = inet_addr(argv[0]);
if (my_ip == INADDR_NONE) {
warnx("Bad IP address to use inside tunnel.");
usage();
@ -2425,12 +2425,12 @@ main(int argc, char **argv)
warnx("Bad MTU given.");
usage();
}
if(port < 1 || port > 65535) {
warnx("Bad port number given.");
usage();
}
if (port != 53) {
fprintf(stderr, "ALERT! Other dns servers expect you to run on port 53.\n");
fprintf(stderr, "You must manually forward port 53 to port %d for things to work.\n", port);
@ -2485,7 +2485,7 @@ main(int argc, char **argv)
warnx("Bad netmask (%d bits). Use 8-30 bits.", netmask);
usage();
}
if (strlen(password) == 0) {
if (NULL != getenv(PASSWORD_ENV_VAR))
snprintf(password, sizeof(password), "%s", getenv(PASSWORD_ENV_VAR));
@ -2533,16 +2533,16 @@ main(int argc, char **argv)
}
my_mtu = mtu;
if (created_users < USERS) {
fprintf(stderr, "Limiting to %d simultaneous users because of netmask /%d\n",
created_users, netmask);
}
fprintf(stderr, "Listening to dns for domain %s\n", topdomain);
if (foreground == 0)
if (foreground == 0)
do_detach();
if (pidfile != NULL)
do_pidfile(pidfile);
@ -2572,7 +2572,7 @@ main(int argc, char **argv)
do_setcon(context);
syslog(LOG_INFO, "started, listening on port %d", port);
tunnel(tun_fd, dnsd_fd, bind_fd, max_idle_time);
syslog(LOG_INFO, "stopping");
@ -2581,7 +2581,7 @@ cleanup3:
cleanup2:
close_dns(dnsd_fd);
cleanup1:
close_tun(tun_fd);
close_tun(tun_fd);
cleanup0:
return retval;

View File

@ -27,11 +27,11 @@
#include "md5.h"
/*
* Needs a 16byte array for output, and 32 bytes password
/*
* Needs a 16byte array for output, and 32 bytes password
*/
void
login_calculate(char *buf, int buflen, const char *pass, int seed)
void
login_calculate(char *buf, int buflen, const char *pass, int seed)
{
unsigned char temp[32];
md5_state_t ctx;
@ -39,7 +39,7 @@ login_calculate(char *buf, int buflen, const char *pass, int seed)
int i;
int k;
if (buflen < 16)
if (buflen < 16)
return;
memcpy(temp, pass, 32);

View File

@ -71,7 +71,7 @@ typedef struct md5_state_s {
} md5_state_t;
#ifdef __cplusplus
extern "C"
extern "C"
{
#endif

View File

@ -61,7 +61,7 @@ readname_loop(char *packet, int packetlen, char **src, char *dst, size_t length,
c--;
}
if (len >= length - 1) {
break; /* We used up all space */
}
@ -104,8 +104,8 @@ readlong(char *packet, char **src, uint32_t *dst)
p = (unsigned char *) *src;
*dst = ((uint32_t)p[0] << 24)
| ((uint32_t)p[1] << 16)
*dst = ((uint32_t)p[0] << 24)
| ((uint32_t)p[1] << 16)
| ((uint32_t)p[2] << 8)
| ((uint32_t)p[3]);
@ -163,7 +163,7 @@ putname(char **buf, size_t buflen, const char *host)
h = strdup(host);
left = buflen;
p = *buf;
word = strtok(h, ".");
while(word) {
if (strlen(word) > 63 || strlen(word) > left) {
@ -231,7 +231,7 @@ int
putdata(char **dst, char *data, size_t len)
{
memcpy(*dst, data, len);
(*dst) += len;
return len;
}

View File

@ -69,8 +69,8 @@ char if_name[250];
#include <net/if.h>
#include <linux/if_tun.h>
int
open_tun(const char *tun_device)
int
open_tun(const char *tun_device)
{
int i;
int tun_fd;
@ -88,7 +88,7 @@ open_tun(const char *tun_device)
memset(&ifreq, 0, sizeof(ifreq));
ifreq.ifr_flags = IFF_TUN;
ifreq.ifr_flags = IFF_TUN;
if (tun_device != NULL) {
strncpy(ifreq.ifr_name, tun_device, IFNAMSIZ);
@ -129,8 +129,8 @@ open_tun(const char *tun_device)
#else /* BSD */
int
open_tun(const char *tun_device)
int
open_tun(const char *tun_device)
{
int i;
int tun_fd;
@ -184,7 +184,7 @@ get_device(char *device, int device_len, const char *wanted_dev)
warnx("Error opening registry key " TAP_ADAPTER_KEY );
return;
}
while (TRUE) {
char name[256];
char unit[256];
@ -222,7 +222,7 @@ get_device(char *device, int device_len, const char *wanted_dev)
strncmp(TAP_VERSION_ID_0901, component, strlen(TAP_VERSION_ID_0901)) == 0) {
/* We found a TAP32 device, get its NetCfgInstanceId */
char iid_string[256] = NET_CFG_INST_ID;
status = RegQueryValueEx(device_key, iid_string, NULL, &datatype, (LPBYTE) device, (DWORD *) &device_len);
if (status != ERROR_SUCCESS || datatype != REG_SZ) {
warnx("Error reading registry key %s\\%s on TAP device", unit, iid_string);
@ -299,7 +299,7 @@ DWORD WINAPI tun_reader(LPVOID arg)
if (!res) {
WaitForSingleObject(olpd.hEvent, INFINITE);
res = GetOverlappedResult(dev_handle, &olpd, (LPDWORD) &len, FALSE);
res = sendto(sock, buf, len, 0, (struct sockaddr*) &(tun->addr),
res = sendto(sock, buf, len, 0, (struct sockaddr*) &(tun->addr),
tun->addrlen);
}
}
@ -307,8 +307,8 @@ DWORD WINAPI tun_reader(LPVOID arg)
return 0;
}
int
open_tun(const char *tun_device)
int
open_tun(const char *tun_device)
{
char adapter[256];
char tapfile[512];
@ -328,7 +328,7 @@ open_tun(const char *tun_device)
}
return -1;
}
fprintf(stderr, "Opening device %s\n", if_name);
snprintf(tapfile, sizeof(tapfile), "%s%s.tap", TAP_DEVICE_SPACE, adapter);
dev_handle = CreateFile(tapfile, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, NULL);
@ -339,9 +339,9 @@ open_tun(const char *tun_device)
/* Use a UDP connection to forward packets from tun,
* so we can still use select() in main code.
* A thread does blocking reads on tun device and
* A thread does blocking reads on tun device and
* sends data as udp to this socket */
localsock_len = get_addr("127.0.0.1", 55353, AF_INET, 0, &localsock);
tunfd = open_dns(&localsock, localsock_len);
@ -349,20 +349,20 @@ open_tun(const char *tun_device)
memcpy(&(data.addr), &localsock, localsock_len);
data.addrlen = localsock_len;
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)tun_reader, &data, 0, NULL);
return tunfd;
}
#endif
#endif
void
close_tun(int tun_fd)
void
close_tun(int tun_fd)
{
if (tun_fd >= 0)
close(tun_fd);
}
int
write_tun(int tun_fd, char *data, size_t len)
int
write_tun(int tun_fd, char *data, size_t len)
{
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(WINDOWS32)
data += 4;
@ -409,7 +409,7 @@ write_tun(int tun_fd, char *data, size_t len)
}
ssize_t
read_tun(int tun_fd, char *buf, size_t len)
read_tun(int tun_fd, char *buf, size_t len)
{
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(WINDOWS32)
/* FreeBSD/Darwin/NetBSD has no header */
@ -471,13 +471,13 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
# else
display_ip = ip;
# endif
snprintf(cmdline, sizeof(cmdline),
snprintf(cmdline, sizeof(cmdline),
IFCONFIGPATH "ifconfig %s %s %s netmask %s",
if_name,
ip,
display_ip,
inet_ntoa(net));
fprintf(stderr, "Setting IP of %s to %s\n", if_name, ip);
#ifndef LINUX
netip.s_addr = inet_addr(ip);
@ -486,7 +486,7 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
if(r != 0) {
return r;
} else {
snprintf(cmdline, sizeof(cmdline),
"/sbin/route add %s/%d %s",
inet_ntoa(netip), netbits, ip);
@ -499,13 +499,13 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
/* Set device as connected */
fprintf(stderr, "Enabling interface '%s'\n", if_name);
status = 1;
r = DeviceIoControl(dev_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status,
r = DeviceIoControl(dev_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status,
sizeof(status), &status, sizeof(status), &len, NULL);
if (!r) {
fprintf(stderr, "Failed to enable interface\n");
return -1;
}
if (inet_aton(ip, &addr)) {
ipdata[0] = (DWORD) addr.s_addr; /* local ip addr */
ipdata[1] = net.s_addr & ipdata[0]; /* network addr */
@ -515,7 +515,7 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
}
/* Tell ip/networkaddr/netmask to device for arp use */
r = DeviceIoControl(dev_handle, TAP_IOCTL_CONFIG_TUN, &ipdata,
r = DeviceIoControl(dev_handle, TAP_IOCTL_CONFIG_TUN, &ipdata,
sizeof(ipdata), &ipdata, sizeof(ipdata), &len, NULL);
if (!r) {
fprintf(stderr, "Failed to set interface in TUN mode\n");
@ -530,18 +530,18 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
#endif
}
int
int
tun_setmtu(const unsigned mtu)
{
#ifndef WINDOWS32
char cmdline[512];
if (mtu > 200 && mtu <= 1500) {
snprintf(cmdline, sizeof(cmdline),
snprintf(cmdline, sizeof(cmdline),
IFCONFIGPATH "ifconfig %s mtu %u",
if_name,
mtu);
fprintf(stderr, "Setting MTU of %s to %u\n", if_name, mtu);
return system(cmdline);
} else {

View File

@ -59,7 +59,7 @@ init_users(in_addr_t my_ip, int netbits)
maxusers = (1 << (32-netbits)) - 3; /* 3: Net addr, broadcast addr, iodined addr */
usercount = MIN(maxusers, USERS);
users = calloc(usercount, sizeof(struct tun_user));
for (i = 0; i < usercount; i++) {
in_addr_t ip;
@ -98,13 +98,13 @@ users_waiting_on_reply()
ret = 0;
for (i = 0; i < usercount; i++) {
if (users[i].active && !users[i].disabled &&
if (users[i].active && !users[i].disabled &&
users[i].last_pkt + 60 > time(NULL) &&
users[i].q.id != 0 && users[i].conn == CONN_DNS_NULL) {
ret++;
}
}
return ret;
}
@ -143,8 +143,8 @@ all_users_waiting_to_send()
for (i = 0; i < usercount; i++) {
if (users[i].active && !users[i].disabled &&
users[i].last_pkt + 60 > now &&
((users[i].conn == CONN_RAW_UDP) ||
((users[i].conn == CONN_DNS_NULL)
((users[i].conn == CONN_RAW_UDP) ||
((users[i].conn == CONN_DNS_NULL)
#ifdef OUTPACKETQ_LEN
&& users[i].outpacketq_filled < 1
#else
@ -183,7 +183,7 @@ user_switch_codec(int userid, struct encoder *enc)
{
if (userid < 0 || userid >= usercount)
return;
users[userid].encoder = enc;
}
@ -195,7 +195,7 @@ user_set_conn_type(int userid, enum connection c)
if (c < 0 || c >= CONN_MAX)
return;
users[userid].conn = c;
}

View File

@ -36,12 +36,12 @@ get_resolvconf_addr()
rv = addr;
pclose(fp);
#else
rv = NULL;
if ((fp = fopen("/etc/resolv.conf", "r")) == NULL)
if ((fp = fopen("/etc/resolv.conf", "r")) == NULL)
err(1, "/etc/resolv.conf");
while (feof(fp) == 0) {
fgets(buf, sizeof(buf), fp);
@ -50,7 +50,7 @@ get_resolvconf_addr()
break;
}
}
fclose(fp);
#endif
#else /* !WINDOWS32 */

View File

@ -13,9 +13,9 @@ all: $(TEST)
$(TEST): $(OBJS) $(SRCOBJS)
@echo LD $(TEST)
@$(CC) -o $@ $(SRCOBJS) $(OBJS) $(LDFLAGS)
@$(CC) -o $@ $(SRCOBJS) $(OBJS) $(LDFLAGS)
.c.o:
.c.o:
@echo CC $<
@$(CC) $(CFLAGS) -c $<

View File

@ -63,7 +63,7 @@ START_TEST(test_base32_decode)
char buf[4096];
struct encoder *b32;
int val;
b32 = get_base32_encoder();
len = sizeof(buf);
@ -81,7 +81,7 @@ START_TEST(test_base32_5to8_8to5)
int c;
for (i = 0; i < 32; i++) {
c = b32_5to8(i);
c = b32_5to8(i);
fail_unless(b32_8to5(c) == i);
}
}

View File

@ -85,7 +85,7 @@ START_TEST(test_build_hostname)
}
buflen = sizeof(buf);
for (i = 1; i < sizeof(data); i++) {
int len = build_hostname(buf, buflen, data, i, topdomain, get_base32_encoder(), sizeof(buf));

View File

@ -28,7 +28,7 @@ START_TEST(test_fw_query_simple)
q.id = 0x848A;
fw_query_init();
/* Test empty cache */
fw_query_get(0x848A, &qp);
fail_unless(qp == NULL);
@ -49,7 +49,7 @@ START_TEST(test_fw_query_edge)
int i;
fw_query_init();
q.addrlen = 33;
q.id = 0x848A;
fw_query_put(&q);
@ -64,7 +64,7 @@ START_TEST(test_fw_query_edge)
fw_query_get(0x848A, &qp);
fail_unless(qp->addrlen == 33);
fail_unless(qp->id == 0x848A);
q.addrlen++;
q.id++;
fw_query_put(&q);

View File

@ -29,11 +29,11 @@ TCase *test_user_create_tests();
TCase *test_fw_query_create_tests();
char *va_str(const char *, ...);
#if (CHECK_MAJOR_VERSION == 0 && \
((CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION < 2) || \
(CHECK_MINOR_VERSION < 9)))
#define tcase_set_timeout(...)
#define tcase_set_timeout(...)
#endif
#endif

View File

@ -62,12 +62,12 @@ START_TEST(test_users_waiting)
fail_unless(users_waiting_on_reply() == 0);
users[3].last_pkt = time(NULL);
fail_unless(users_waiting_on_reply() == 0);
users[3].conn = CONN_DNS_NULL;
users[3].q.id = 1;
fail_unless(users_waiting_on_reply() == 1);
}
END_TEST
@ -83,17 +83,17 @@ START_TEST(test_find_user_by_ip)
testip = (unsigned int) inet_addr("10.0.0.1");
fail_unless(find_user_by_ip(testip) == -1);
testip = (unsigned int) inet_addr("127.0.0.2");
fail_unless(find_user_by_ip(testip) == -1);
users[0].active = 1;
testip = (unsigned int) inet_addr("127.0.0.2");
fail_unless(find_user_by_ip(testip) == -1);
users[0].last_pkt = time(NULL);
testip = (unsigned int) inet_addr("127.0.0.2");
fail_unless(find_user_by_ip(testip) == 0);
}
@ -107,15 +107,15 @@ START_TEST(test_all_users_waiting_to_send)
init_users(ip, 27);
fail_unless(all_users_waiting_to_send() == 1);
users[0].conn = CONN_DNS_NULL;
users[0].active = 1;
fail_unless(all_users_waiting_to_send() == 1);
users[0].last_pkt = time(NULL);
users[0].outpacket.len = 0;
fail_unless(all_users_waiting_to_send() == 0);
#ifdef OUTPACKETQ_LEN
@ -123,7 +123,7 @@ START_TEST(test_all_users_waiting_to_send)
#else
users[0].outpacket.len = 44;
#endif
fail_unless(all_users_waiting_to_send() == 1);
}
END_TEST
@ -150,7 +150,7 @@ START_TEST(test_find_available_user)
fail_unless(find_available_user() == -1);
users[3].last_pkt = 55;
fail_unless(find_available_user() == 3);
fail_unless(find_available_user() == -1);
}
@ -178,7 +178,7 @@ START_TEST(test_find_available_user_small_net)
fail_unless(find_available_user() == -1);
users[3].last_pkt = 55;
fail_unless(find_available_user() == 3);
fail_unless(find_available_user() == -1);
}