Split the client code out from the file with the main() func

This commit is contained in:
Erik Ekman 2009-08-16 12:30:26 +00:00 committed by Erik Ekman
parent a3757a07aa
commit 27fdc23433
8 changed files with 1259 additions and 1127 deletions

View file

@ -1,5 +1,5 @@
COMMONOBJS = tun.o dns.o read.o encoding.o login.o base32.o base64.o md5.o common.o COMMONOBJS = tun.o dns.o read.o encoding.o login.o base32.o base64.o md5.o common.o
CLIENTOBJS = iodine.o CLIENTOBJS = iodine.o client.o util.o
CLIENT = ../bin/iodine CLIENT = ../bin/iodine
SERVEROBJS = iodined.o user.o fw_query.o SERVEROBJS = iodined.o user.o fw_query.o
SERVER = ../bin/iodined SERVER = ../bin/iodined

1131
src/client.c Normal file

File diff suppressed because it is too large Load diff

33
src/client.h Normal file
View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
*
* 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.
*/
#ifndef __CLIENT_H__
#define __CLIENT_H__
void client_init();
void client_stop();
enum connection client_get_conn();
const char *client_get_raw_addr();
void client_set_nameserver(const char *cp);
void client_set_topdomain(const char *cp);
void client_set_password(const char *cp);
int client_handshake(int dns_fd, int raw_mode, int autodetect_frag_size, int fragsize);
int client_tunnel(int tun_fd, int dns_fd);
#endif

File diff suppressed because it is too large Load diff

View file

@ -29,7 +29,7 @@
* Needs a 16byte array for output, and 32 bytes password * Needs a 16byte array for output, and 32 bytes password
*/ */
void void
login_calculate(char *buf, int buflen, char *pass, int seed) 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;

View file

@ -17,7 +17,7 @@
#ifndef __LOGIN_H__ #ifndef __LOGIN_H__
#define __LOGIN_H__ #define __LOGIN_H__
void login_calculate(char *, int, char *, int); void login_calculate(char *, int, const char *, int);
#endif #endif

69
src/util.c Normal file
View file

@ -0,0 +1,69 @@
/*
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
*
* 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 <stdio.h>
#include "common.h"
char *
get_resolvconf_addr()
{
static char addr[16];
char *rv;
#ifndef WINDOWS32
char buf[80];
FILE *fp;
rv = NULL;
if ((fp = fopen("/etc/resolv.conf", "r")) == NULL)
err(1, "/etc/resolve.conf");
while (feof(fp) == 0) {
fgets(buf, sizeof(buf), fp);
if (sscanf(buf, "nameserver %15s", addr) == 1) {
rv = addr;
break;
}
}
fclose(fp);
#else /* !WINDOWS32 */
FIXED_INFO *fixed_info;
ULONG buflen;
DWORD ret;
rv = NULL;
fixed_info = malloc(sizeof(FIXED_INFO));
buflen = sizeof(FIXED_INFO);
if (GetNetworkParams(fixed_info, &buflen) == ERROR_BUFFER_OVERFLOW) {
/* official ugly api workaround */
free(fixed_info);
fixed_info = malloc(buflen);
}
ret = GetNetworkParams(fixed_info, &buflen);
if (ret == NO_ERROR) {
strncpy(addr, fixed_info->DnsServerList.IpAddress.String, sizeof(addr));
addr[15] = 0;
rv = addr;
}
free(fixed_info);
#endif
return rv;
}

6
src/util.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef __UTIL_H__
#define __UTIL_H__
char *get_resolvconf_addr();
#endif