mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-25 07:31:27 +00:00
Refactored to make it easier to add unit tests
This commit is contained in:
parent
7e9ce2716b
commit
a1a2e3cefe
34
src/client.c
34
src/client.c
|
@ -120,7 +120,7 @@ client_get_conn()
|
|||
}
|
||||
|
||||
void
|
||||
client_set_nameserver(const char *cp)
|
||||
client_set_nameserver(const char *cp, int port)
|
||||
{
|
||||
struct in_addr addr;
|
||||
|
||||
|
@ -129,7 +129,7 @@ client_set_nameserver(const char *cp)
|
|||
|
||||
memset(&nameserv, 0, sizeof(nameserv));
|
||||
nameserv.sin_family = AF_INET;
|
||||
nameserv.sin_port = htons(53);
|
||||
nameserv.sin_port = htons(port);
|
||||
nameserv.sin_addr = addr;
|
||||
}
|
||||
|
||||
|
@ -191,36 +191,6 @@ send_raw_data(int dns_fd)
|
|||
send_raw(dns_fd, outpkt.data, outpkt.len, userid, RAW_HDR_CMD_DATA);
|
||||
}
|
||||
|
||||
static int
|
||||
build_hostname(char *buf, size_t buflen,
|
||||
const char *data, const size_t datalen,
|
||||
const char *topdomain, struct encoder *encoder)
|
||||
{
|
||||
int encsize;
|
||||
size_t space;
|
||||
char *b;
|
||||
|
||||
space = MIN(0xFF, buflen) - strlen(topdomain) - 7;
|
||||
if (!encoder->places_dots())
|
||||
space -= (space / 57); /* space for dots */
|
||||
|
||||
memset(buf, 0, buflen);
|
||||
|
||||
encsize = encoder->encode(buf, &space, data, datalen);
|
||||
|
||||
if (!encoder->places_dots())
|
||||
inline_dotify(buf, buflen);
|
||||
|
||||
b = buf;
|
||||
b += strlen(buf);
|
||||
|
||||
if (*b != '.')
|
||||
*b++ = '.';
|
||||
|
||||
strncpy(b, topdomain, strlen(topdomain)+1);
|
||||
|
||||
return space;
|
||||
}
|
||||
|
||||
static void
|
||||
send_packet(int fd, char cmd, const char *data, const size_t datalen)
|
||||
|
|
|
@ -23,7 +23,7 @@ void client_stop();
|
|||
enum connection client_get_conn();
|
||||
const char *client_get_raw_addr();
|
||||
|
||||
void client_set_nameserver(const char *cp);
|
||||
void client_set_nameserver(const char *cp, int port);
|
||||
void client_set_topdomain(const char *cp);
|
||||
void client_set_password(const char *cp);
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ extern const unsigned char raw_header[RAW_HDR_LEN];
|
|||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#define DNS_PORT 53
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
|
|
|
@ -15,8 +15,39 @@
|
|||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "common.h"
|
||||
#include "encoding.h"
|
||||
|
||||
int
|
||||
build_hostname(char *buf, size_t buflen,
|
||||
const char *data, const size_t datalen,
|
||||
const char *topdomain, struct encoder *encoder)
|
||||
{
|
||||
int encsize;
|
||||
size_t space;
|
||||
char *b;
|
||||
|
||||
space = MIN(0xFF, buflen) - strlen(topdomain) - 7;
|
||||
if (!encoder->places_dots())
|
||||
space -= (space / 57); /* space for dots */
|
||||
|
||||
memset(buf, 0, buflen);
|
||||
|
||||
encsize = encoder->encode(buf, &space, data, datalen);
|
||||
|
||||
if (!encoder->places_dots())
|
||||
inline_dotify(buf, buflen);
|
||||
|
||||
b = buf;
|
||||
b += strlen(buf);
|
||||
|
||||
if (*b != '.')
|
||||
*b++ = '.';
|
||||
|
||||
strncpy(b, topdomain, strlen(topdomain)+1);
|
||||
|
||||
return space;
|
||||
}
|
||||
|
||||
int
|
||||
unpack_data(char *buf, size_t buflen, char *data, size_t datalen, struct encoder *enc)
|
||||
|
|
|
@ -27,6 +27,7 @@ struct encoder {
|
|||
int (*blocksize_encoded)(void);
|
||||
};
|
||||
|
||||
int build_hostname(char *, size_t, const char *, const size_t, const char *, struct encoder *);
|
||||
int unpack_data(char *, size_t, char *, size_t, struct encoder *);
|
||||
int inline_dotify(char *, size_t);
|
||||
int inline_undotify(char *, size_t);
|
||||
|
|
|
@ -232,7 +232,7 @@ main(int argc, char **argv)
|
|||
}
|
||||
|
||||
if (nameserv_addr) {
|
||||
client_set_nameserver(nameserv_addr);
|
||||
client_set_nameserver(nameserv_addr, DNS_PORT);
|
||||
} else {
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
|
|
Loading…
Reference in a new issue