mirror of
https://github.com/yarrick/iodine.git
synced 2025-01-12 10:59:30 +00:00
Declare counter variables within for loops for lowest scope.
This commit is contained in:
parent
9634d0271f
commit
b59b665b77
|
@ -96,12 +96,11 @@ base128_blksize_enc(void)
|
||||||
inline static void
|
inline static void
|
||||||
base128_reverse_init(void)
|
base128_reverse_init(void)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
|
||||||
if (!reverse_init) {
|
if (!reverse_init) {
|
||||||
memset (rev128, 0, 256);
|
memset (rev128, 0, 256);
|
||||||
for (i = 0; i < 128; i++) {
|
for (int i = 0; i < 128; i++) {
|
||||||
c = cb128[i];
|
c = cb128[i];
|
||||||
rev128[(int) c] = i;
|
rev128[(int) c] = i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,12 +74,11 @@ base32_blksize_enc(void)
|
||||||
inline static void
|
inline static void
|
||||||
base32_reverse_init(void)
|
base32_reverse_init(void)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
|
||||||
if (!reverse_init) {
|
if (!reverse_init) {
|
||||||
memset (rev32, 0, 256);
|
memset (rev32, 0, 256);
|
||||||
for (i = 0; i < 32; i++) {
|
for (int i = 0; i < 32; i++) {
|
||||||
c = cb32[i];
|
c = cb32[i];
|
||||||
rev32[(int) c] = i;
|
rev32[(int) c] = i;
|
||||||
c = cb32_ucase[i];
|
c = cb32_ucase[i];
|
||||||
|
|
|
@ -75,12 +75,11 @@ base64_blksize_enc(void)
|
||||||
inline static void
|
inline static void
|
||||||
base64_reverse_init(void)
|
base64_reverse_init(void)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
|
||||||
if (!reverse_init) {
|
if (!reverse_init) {
|
||||||
memset (rev64, 0, 256);
|
memset (rev64, 0, 256);
|
||||||
for (i = 0; i < 64; i++) {
|
for (int i = 0; i < 64; i++) {
|
||||||
c = cb64[i];
|
c = cb64[i];
|
||||||
rev64[(int) c] = i;
|
rev64[(int) c] = i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,12 +76,11 @@ base64u_blksize_enc(void)
|
||||||
inline static void
|
inline static void
|
||||||
base64u_reverse_init(void)
|
base64u_reverse_init(void)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
|
||||||
if (!reverse_init) {
|
if (!reverse_init) {
|
||||||
memset (rev64, 0, 256);
|
memset (rev64, 0, 256);
|
||||||
for (i = 0; i < 64; i++) {
|
for (int i = 0; i < 64; i++) {
|
||||||
c = cb64[i];
|
c = cb64[i];
|
||||||
rev64[(int) c] = i;
|
rev64[(int) c] = i;
|
||||||
}
|
}
|
||||||
|
|
35
src/client.c
35
src/client.c
|
@ -1835,7 +1835,6 @@ handshake_qtypetest(int dns_fd, int timeout)
|
||||||
char *s = DOWNCODECCHECK1;
|
char *s = DOWNCODECCHECK1;
|
||||||
int slen = DOWNCODECCHECK1_LEN;
|
int slen = DOWNCODECCHECK1_LEN;
|
||||||
int trycodec;
|
int trycodec;
|
||||||
int k;
|
|
||||||
|
|
||||||
if (do_qtype == T_NULL)
|
if (do_qtype == T_NULL)
|
||||||
trycodec = 'R';
|
trycodec = 'R';
|
||||||
|
@ -1852,7 +1851,7 @@ handshake_qtypetest(int dns_fd, int timeout)
|
||||||
if (read != slen)
|
if (read != slen)
|
||||||
return 0; /* incorrect */
|
return 0; /* incorrect */
|
||||||
|
|
||||||
for (k = 0; k < slen; k++) {
|
for (int k = 0; k < slen; k++) {
|
||||||
if (in[k] != s[k]) {
|
if (in[k] != s[k]) {
|
||||||
/* corrupted */
|
/* corrupted */
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1885,8 +1884,6 @@ handshake_qtype_autodetect(int dns_fd)
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
int highestworking = 100;
|
int highestworking = 100;
|
||||||
int timeout;
|
|
||||||
int qtypenum;
|
|
||||||
|
|
||||||
fprintf(stderr, "Autodetecting DNS query type (use -T to override)");
|
fprintf(stderr, "Autodetecting DNS query type (use -T to override)");
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
@ -1901,8 +1898,8 @@ handshake_qtype_autodetect(int dns_fd)
|
||||||
to see if things will start working after a while.
|
to see if things will start working after a while.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (timeout = 1; running && timeout <= 3; timeout++) {
|
for (int timeout = 1; running && timeout <= 3; timeout++) {
|
||||||
for (qtypenum = 0; running && qtypenum < highestworking; qtypenum++) {
|
for (int qtypenum = 0; running && qtypenum < highestworking; qtypenum++) {
|
||||||
do_qtype = handshake_qtype_numcvt(qtypenum);
|
do_qtype = handshake_qtype_numcvt(qtypenum);
|
||||||
if (do_qtype == T_UNSET)
|
if (do_qtype == T_UNSET)
|
||||||
break; /* this round finished */
|
break; /* this round finished */
|
||||||
|
@ -1957,7 +1954,6 @@ handshake_edns0_check(int dns_fd)
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
char in[4096];
|
char in[4096];
|
||||||
int i;
|
|
||||||
int read;
|
int read;
|
||||||
char *s = DOWNCODECCHECK1;
|
char *s = DOWNCODECCHECK1;
|
||||||
int slen = DOWNCODECCHECK1_LEN;
|
int slen = DOWNCODECCHECK1_LEN;
|
||||||
|
@ -1968,7 +1964,7 @@ handshake_edns0_check(int dns_fd)
|
||||||
else
|
else
|
||||||
trycodec = 'T';
|
trycodec = 'T';
|
||||||
|
|
||||||
for (i=0; running && i<3 ;i++) {
|
for (int i=0; running && i<3 ;i++) {
|
||||||
|
|
||||||
send_downenctest(dns_fd, trycodec, 1, NULL, 0);
|
send_downenctest(dns_fd, trycodec, 1, NULL, 0);
|
||||||
|
|
||||||
|
@ -1981,8 +1977,7 @@ handshake_edns0_check(int dns_fd)
|
||||||
return 0; /* reply incorrect = unreliable */
|
return 0; /* reply incorrect = unreliable */
|
||||||
|
|
||||||
if (read > 0) {
|
if (read > 0) {
|
||||||
int k;
|
for (int k = 0; k < slen; k++) {
|
||||||
for (k = 0; k < slen; k++) {
|
|
||||||
if (in[k] != s[k]) {
|
if (in[k] != s[k]) {
|
||||||
/* Definitely not reliable */
|
/* Definitely not reliable */
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2003,7 +1998,6 @@ static void
|
||||||
handshake_switch_codec(int dns_fd, int bits)
|
handshake_switch_codec(int dns_fd, int bits)
|
||||||
{
|
{
|
||||||
char in[4096];
|
char in[4096];
|
||||||
int i;
|
|
||||||
int read;
|
int read;
|
||||||
struct encoder *tempenc;
|
struct encoder *tempenc;
|
||||||
|
|
||||||
|
@ -2019,7 +2013,7 @@ handshake_switch_codec(int dns_fd, int bits)
|
||||||
|
|
||||||
fprintf(stderr, "Switching upstream to codec %s\n", tempenc->name);
|
fprintf(stderr, "Switching upstream to codec %s\n", tempenc->name);
|
||||||
|
|
||||||
for (i=0; running && i<5 ;i++) {
|
for (int i=0; running && i<5 ;i++) {
|
||||||
|
|
||||||
send_codec_switch(dns_fd, userid, bits);
|
send_codec_switch(dns_fd, userid, bits);
|
||||||
|
|
||||||
|
@ -2057,7 +2051,6 @@ static void
|
||||||
handshake_switch_downenc(int dns_fd)
|
handshake_switch_downenc(int dns_fd)
|
||||||
{
|
{
|
||||||
char in[4096];
|
char in[4096];
|
||||||
int i;
|
|
||||||
int read;
|
int read;
|
||||||
char *dname;
|
char *dname;
|
||||||
|
|
||||||
|
@ -2072,7 +2065,7 @@ handshake_switch_downenc(int dns_fd)
|
||||||
dname = "Raw";
|
dname = "Raw";
|
||||||
|
|
||||||
fprintf(stderr, "Switching downstream to codec %s\n", dname);
|
fprintf(stderr, "Switching downstream to codec %s\n", dname);
|
||||||
for (i=0; running && i<5 ;i++) {
|
for (int i=0; running && i<5 ;i++) {
|
||||||
|
|
||||||
send_downenc_switch(dns_fd, userid);
|
send_downenc_switch(dns_fd, userid);
|
||||||
|
|
||||||
|
@ -2109,11 +2102,10 @@ static void
|
||||||
handshake_try_lazy(int dns_fd)
|
handshake_try_lazy(int dns_fd)
|
||||||
{
|
{
|
||||||
char in[4096];
|
char in[4096];
|
||||||
int i;
|
|
||||||
int read;
|
int read;
|
||||||
|
|
||||||
fprintf(stderr, "Switching to lazy mode for low-latency\n");
|
fprintf(stderr, "Switching to lazy mode for low-latency\n");
|
||||||
for (i=0; running && i<5; i++) {
|
for (int i=0; running && i<5; i++) {
|
||||||
|
|
||||||
send_lazy_switch(dns_fd, userid);
|
send_lazy_switch(dns_fd, userid);
|
||||||
|
|
||||||
|
@ -2154,10 +2146,9 @@ handshake_lazyoff(int dns_fd)
|
||||||
/* Used in the middle of data transfer, timing is different and no error msgs */
|
/* Used in the middle of data transfer, timing is different and no error msgs */
|
||||||
{
|
{
|
||||||
char in[4096];
|
char in[4096];
|
||||||
int i;
|
|
||||||
int read;
|
int read;
|
||||||
|
|
||||||
for (i=0; running && i<5; i++) {
|
for (int i=0; running && i<5; i++) {
|
||||||
|
|
||||||
send_lazy_switch(dns_fd, userid);
|
send_lazy_switch(dns_fd, userid);
|
||||||
|
|
||||||
|
@ -2182,8 +2173,8 @@ fragsize_check(char *in, int read, int proposed_fragsize, int *max_fragsize)
|
||||||
{
|
{
|
||||||
int acked_fragsize = ((in[0] & 0xff) << 8) | (in[1] & 0xff);
|
int acked_fragsize = ((in[0] & 0xff) << 8) | (in[1] & 0xff);
|
||||||
int okay;
|
int okay;
|
||||||
int i;
|
|
||||||
unsigned int v;
|
unsigned int v;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (read >= 5 && strncmp("BADIP", in, 5) == 0) {
|
if (read >= 5 && strncmp("BADIP", in, 5) == 0) {
|
||||||
fprintf(stderr, "got BADIP (Try iodined -c)..\n");
|
fprintf(stderr, "got BADIP (Try iodined -c)..\n");
|
||||||
|
@ -2253,7 +2244,6 @@ static int
|
||||||
handshake_autoprobe_fragsize(int dns_fd)
|
handshake_autoprobe_fragsize(int dns_fd)
|
||||||
{
|
{
|
||||||
char in[4096];
|
char in[4096];
|
||||||
int i;
|
|
||||||
int read;
|
int read;
|
||||||
int proposed_fragsize = 768;
|
int proposed_fragsize = 768;
|
||||||
int range = 768;
|
int range = 768;
|
||||||
|
@ -2263,7 +2253,7 @@ handshake_autoprobe_fragsize(int dns_fd)
|
||||||
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)) {
|
while (running && range > 0 && (range >= 8 || max_fragsize < 300)) {
|
||||||
/* stop the slow probing early when we have enough bytes anyway */
|
/* stop the slow probing early when we have enough bytes anyway */
|
||||||
for (i=0; running && i<3 ;i++) {
|
for (int i=0; running && i<3 ;i++) {
|
||||||
|
|
||||||
send_fragsize_probe(dns_fd, proposed_fragsize);
|
send_fragsize_probe(dns_fd, proposed_fragsize);
|
||||||
|
|
||||||
|
@ -2327,11 +2317,10 @@ static void
|
||||||
handshake_set_fragsize(int dns_fd, int fragsize)
|
handshake_set_fragsize(int dns_fd, int fragsize)
|
||||||
{
|
{
|
||||||
char in[4096];
|
char in[4096];
|
||||||
int i;
|
|
||||||
int read;
|
int read;
|
||||||
|
|
||||||
fprintf(stderr, "Setting downstream fragment size to max %d...\n", fragsize);
|
fprintf(stderr, "Setting downstream fragment size to max %d...\n", fragsize);
|
||||||
for (i=0; running && i<5 ;i++) {
|
for (int i=0; running && i<5 ;i++) {
|
||||||
|
|
||||||
send_set_downstream_fragsize(dns_fd, fragsize);
|
send_set_downstream_fragsize(dns_fd, fragsize);
|
||||||
|
|
||||||
|
|
15
src/common.c
15
src/common.c
|
@ -59,7 +59,7 @@ const unsigned char raw_header[RAW_HDR_LEN] = { 0x10, 0xd1, 0x9e, 0x00 };
|
||||||
#if !defined(ANDROID) && !defined(WINDOWS32) && !(defined(BSD) && (BSD >= 199306)) && !defined(__GLIBC__)
|
#if !defined(ANDROID) && !defined(WINDOWS32) && !(defined(BSD) && (BSD >= 199306)) && !defined(__GLIBC__)
|
||||||
static int daemon(int nochdir, int noclose)
|
static int daemon(int nochdir, int noclose)
|
||||||
{
|
{
|
||||||
int fd, i;
|
int fd;
|
||||||
|
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -80,7 +80,7 @@ static int daemon(int nochdir, int noclose)
|
||||||
|
|
||||||
if (!noclose) {
|
if (!noclose) {
|
||||||
if ((fd = open("/dev/null", O_RDWR)) >= 0) {
|
if ((fd = open("/dev/null", O_RDWR)) >= 0) {
|
||||||
for (i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
dup2(fd, i);
|
dup2(fd, i);
|
||||||
}
|
}
|
||||||
if (fd > 2) {
|
if (fd > 2) {
|
||||||
|
@ -293,8 +293,6 @@ read_password(char *buf, size_t len)
|
||||||
|
|
||||||
tp.c_lflag &= (~ECHO);
|
tp.c_lflag &= (~ECHO);
|
||||||
tcsetattr(0, TCSANOW, &tp);
|
tcsetattr(0, TCSANOW, &tp);
|
||||||
#else
|
|
||||||
int i;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fprintf(stderr, "Enter password: ");
|
fprintf(stderr, "Enter password: ");
|
||||||
|
@ -302,7 +300,7 @@ read_password(char *buf, size_t len)
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
fscanf(stdin, "%79[^\n]", pwd);
|
fscanf(stdin, "%79[^\n]", pwd);
|
||||||
#else
|
#else
|
||||||
for (i = 0; i < sizeof(pwd); i++) {
|
for (int i = 0; i < sizeof(pwd); i++) {
|
||||||
pwd[i] = getch();
|
pwd[i] = getch();
|
||||||
if (pwd[i] == '\r' || pwd[i] == '\n') {
|
if (pwd[i] == '\r' || pwd[i] == '\n') {
|
||||||
pwd[i] = 0;
|
pwd[i] = 0;
|
||||||
|
@ -326,12 +324,10 @@ read_password(char *buf, size_t len)
|
||||||
int
|
int
|
||||||
check_topdomain(char *str)
|
check_topdomain(char *str)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
if(str[0] == '.') /* special case */
|
if(str[0] == '.') /* special case */
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
for( i = 0; i < strlen(str); i++) {
|
for(int i = 0; i < strlen(str); i++) {
|
||||||
if( isalpha(str[i]) || isdigit(str[i]) || str[i] == '-' || str[i] == '.' )
|
if( isalpha(str[i]) || isdigit(str[i]) || str[i] == '-' || str[i] == '.' )
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
|
@ -407,8 +403,7 @@ int recent_seqno(int ourseqno, int gotseqno)
|
||||||
Return 0 if gotseqno is new (or very old).
|
Return 0 if gotseqno is new (or very old).
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
int i;
|
for (int i = 0; i < 4; i++, ourseqno--) {
|
||||||
for (i = 0; i < 4; i++, ourseqno--) {
|
|
||||||
if (ourseqno < 0)
|
if (ourseqno < 0)
|
||||||
ourseqno = 7;
|
ourseqno = 7;
|
||||||
if (gotseqno == ourseqno)
|
if (gotseqno == ourseqno)
|
||||||
|
|
|
@ -508,11 +508,10 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||||
char names[250][QUERY_NAME_SIZE];
|
char names[250][QUERY_NAME_SIZE];
|
||||||
char *rdatastart;
|
char *rdatastart;
|
||||||
short pref;
|
short pref;
|
||||||
int i;
|
|
||||||
int offset;
|
int offset;
|
||||||
|
|
||||||
memset(names, 0, sizeof(names));
|
memset(names, 0, sizeof(names));
|
||||||
|
int i;
|
||||||
for (i=0; i < ancount; i++) {
|
for (i=0; i < ancount; i++) {
|
||||||
readname(packet, packetlen, &data, name, sizeof(name));
|
readname(packet, packetlen, &data, name, sizeof(name));
|
||||||
CHECKLEN(12);
|
CHECKLEN(12);
|
||||||
|
|
|
@ -37,10 +37,8 @@ void fw_query_put(struct fw_query *fw_query)
|
||||||
|
|
||||||
void fw_query_get(unsigned short query_id, struct fw_query **fw_query)
|
void fw_query_get(unsigned short query_id, struct fw_query **fw_query)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
*fw_query = NULL;
|
*fw_query = NULL;
|
||||||
for (i = 0; i < FW_QUERY_CACHE_SIZE; i++) {
|
for (int i = 0; i < FW_QUERY_CACHE_SIZE; i++) {
|
||||||
if (fwq[i].id == query_id) {
|
if (fwq[i].id == query_id) {
|
||||||
*fw_query = &(fwq[i]);
|
*fw_query = &(fwq[i]);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -35,7 +35,6 @@ login_calculate(char *buf, int buflen, const char *pass, int seed)
|
||||||
unsigned char temp[32];
|
unsigned char temp[32];
|
||||||
md5_state_t ctx;
|
md5_state_t ctx;
|
||||||
int *ix;
|
int *ix;
|
||||||
int i;
|
|
||||||
int k;
|
int k;
|
||||||
|
|
||||||
if (buflen < 16)
|
if (buflen < 16)
|
||||||
|
@ -44,7 +43,7 @@ login_calculate(char *buf, int buflen, const char *pass, int seed)
|
||||||
memcpy(temp, pass, 32);
|
memcpy(temp, pass, 32);
|
||||||
ix = (int*) temp;
|
ix = (int*) temp;
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
k = ntohl(*ix);
|
k = ntohl(*ix);
|
||||||
k ^= seed;
|
k ^= seed;
|
||||||
*ix++ = htonl(k);
|
*ix++ = htonl(k);
|
||||||
|
|
|
@ -181,14 +181,13 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
|
||||||
* right order.
|
* right order.
|
||||||
*/
|
*/
|
||||||
const md5_byte_t *xp = data;
|
const md5_byte_t *xp = data;
|
||||||
int i;
|
|
||||||
|
|
||||||
# if BYTE_ORDER == 0
|
# if BYTE_ORDER == 0
|
||||||
X = xbuf; /* (dynamic only) */
|
X = xbuf; /* (dynamic only) */
|
||||||
# else
|
# else
|
||||||
# define xbuf X /* (static only) */
|
# define xbuf X /* (static only) */
|
||||||
# endif
|
# endif
|
||||||
for (i = 0; i < 16; ++i, xp += 4)
|
for (int i = 0; i < 16; ++i, xp += 4)
|
||||||
xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
|
xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -367,16 +366,15 @@ md5_finish(md5_state_t *pms, md5_byte_t digest[16])
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
};
|
};
|
||||||
md5_byte_t data[8];
|
md5_byte_t data[8];
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Save the length before padding. */
|
/* Save the length before padding. */
|
||||||
for (i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
|
data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
|
||||||
/* Pad to 56 bytes mod 64. */
|
/* Pad to 56 bytes mod 64. */
|
||||||
md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
|
md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
|
||||||
/* Append the length. */
|
/* Append the length. */
|
||||||
md5_append(pms, data, 8);
|
md5_append(pms, data, 8);
|
||||||
for (i = 0; i < 16; ++i)
|
for (int i = 0; i < 16; ++i)
|
||||||
digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
|
digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -437,7 +437,6 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
|
||||||
char cmdline[512];
|
char cmdline[512];
|
||||||
int netmask;
|
int netmask;
|
||||||
struct in_addr net;
|
struct in_addr net;
|
||||||
int i;
|
|
||||||
#ifndef LINUX
|
#ifndef LINUX
|
||||||
int r;
|
int r;
|
||||||
#endif
|
#endif
|
||||||
|
@ -450,7 +449,7 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
|
||||||
const char *display_ip;
|
const char *display_ip;
|
||||||
|
|
||||||
netmask = 0;
|
netmask = 0;
|
||||||
for (i = 0; i < netbits; i++) {
|
for (int i = 0; i < netbits; i++) {
|
||||||
netmask = (netmask << 1) | 1;
|
netmask = (netmask << 1) | 1;
|
||||||
}
|
}
|
||||||
netmask <<= (32 - netbits);
|
netmask <<= (32 - netbits);
|
||||||
|
|
29
src/user.c
29
src/user.c
|
@ -39,7 +39,6 @@ unsigned usercount;
|
||||||
int
|
int
|
||||||
init_users(in_addr_t my_ip, int netbits)
|
init_users(in_addr_t my_ip, int netbits)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int skip = 0;
|
int skip = 0;
|
||||||
char newip[16];
|
char newip[16];
|
||||||
|
|
||||||
|
@ -49,7 +48,7 @@ init_users(in_addr_t my_ip, int netbits)
|
||||||
struct in_addr net;
|
struct in_addr net;
|
||||||
struct in_addr ipstart;
|
struct in_addr ipstart;
|
||||||
|
|
||||||
for (i = 0; i < netbits; i++) {
|
for (int i = 0; i < netbits; i++) {
|
||||||
netmask = (netmask << 1) | 1;
|
netmask = (netmask << 1) | 1;
|
||||||
}
|
}
|
||||||
netmask <<= (32 - netbits);
|
netmask <<= (32 - netbits);
|
||||||
|
@ -60,7 +59,7 @@ init_users(in_addr_t my_ip, int netbits)
|
||||||
usercount = MIN(maxusers, USERS);
|
usercount = MIN(maxusers, USERS);
|
||||||
|
|
||||||
users = calloc(usercount, sizeof(struct tun_user));
|
users = calloc(usercount, sizeof(struct tun_user));
|
||||||
for (i = 0; i < usercount; i++) {
|
for (int i = 0; i < usercount; i++) {
|
||||||
in_addr_t ip;
|
in_addr_t ip;
|
||||||
users[i].id = i;
|
users[i].id = i;
|
||||||
snprintf(newip, sizeof(newip), "0.0.0.%d", i + skip + 1);
|
snprintf(newip, sizeof(newip), "0.0.0.%d", i + skip + 1);
|
||||||
|
@ -92,11 +91,9 @@ users_get_first_ip(void)
|
||||||
int
|
int
|
||||||
users_waiting_on_reply(void)
|
users_waiting_on_reply(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = 0;
|
||||||
int i;
|
|
||||||
|
|
||||||
ret = 0;
|
for (int i = 0; i < usercount; i++) {
|
||||||
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].last_pkt + 60 > time(NULL) &&
|
||||||
users[i].q.id != 0 && users[i].conn == CONN_DNS_NULL) {
|
users[i].q.id != 0 && users[i].conn == CONN_DNS_NULL) {
|
||||||
|
@ -110,11 +107,9 @@ users_waiting_on_reply(void)
|
||||||
int
|
int
|
||||||
find_user_by_ip(uint32_t ip)
|
find_user_by_ip(uint32_t ip)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = -1;
|
||||||
int i;
|
|
||||||
|
|
||||||
ret = -1;
|
for (int i = 0; i < usercount; i++) {
|
||||||
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].last_pkt + 60 > time(NULL) &&
|
||||||
ip == users[i].tun_ip) {
|
ip == users[i].tun_ip) {
|
||||||
|
@ -134,12 +129,10 @@ all_users_waiting_to_send(void)
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
time_t now;
|
time_t now;
|
||||||
int ret;
|
int ret = 1;
|
||||||
int i;
|
|
||||||
|
|
||||||
ret = 1;
|
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
for (i = 0; i < usercount; i++) {
|
|
||||||
|
for (int i = 0; i < usercount; i++) {
|
||||||
if (users[i].active && !users[i].disabled &&
|
if (users[i].active && !users[i].disabled &&
|
||||||
users[i].last_pkt + 60 > now &&
|
users[i].last_pkt + 60 > now &&
|
||||||
((users[i].conn == CONN_RAW_UDP) ||
|
((users[i].conn == CONN_RAW_UDP) ||
|
||||||
|
@ -162,8 +155,8 @@ int
|
||||||
find_available_user(void)
|
find_available_user(void)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int i;
|
|
||||||
for (i = 0; i < usercount; i++) {
|
for (int i = 0; i < usercount; i++) {
|
||||||
/* Not used at all or not used in one minute */
|
/* Not used at all or not used in one minute */
|
||||||
if ((!users[i].active || users[i].last_pkt + 60 < time(NULL)) && !users[i].disabled) {
|
if ((!users[i].active || users[i].last_pkt + 60 < time(NULL)) && !users[i].disabled) {
|
||||||
users[i].active = 1;
|
users[i].active = 1;
|
||||||
|
|
Loading…
Reference in a new issue