Extract version checking to function

This commit is contained in:
Erik Ekman 2007-12-01 21:46:13 +00:00 committed by Erik Ekman
parent bebdb6086b
commit 998b944225

View file

@ -124,30 +124,16 @@ send_version_response(int fd, version_ack_t ack, uint32_t payload, struct user *
write_dns(fd, &u->q, out, sizeof(out));
}
static int
tunnel_dns(int tun_fd, int dns_fd)
static void
handle_version(int dns_fd, char *in, int len)
{
struct in_addr tempip;
struct user dummy;
struct ip *hdr;
unsigned long outlen;
char logindata[16];
char out[64*1024];
char in[64*1024];
char unpacked[64*1024];
char *tmp[2];
int userid;
int touser;
int version;
struct user dummy;
int read;
int code;
int version;
int userid;
userid = -1;
if ((read = read_dns(dns_fd, &(dummy.q), in, sizeof(in))) <= 0)
return 0;
if(in[0] == 'V' || in[0] == 'v') {
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), read - 1, b32);
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), len - 1, b32);
/* Version greeting, compare and send ack/nak */
if (read > 4) {
/* Received V + 32bits version */
@ -174,6 +160,31 @@ tunnel_dns(int tun_fd, int dns_fd)
} else {
send_version_response(dns_fd, VERSION_NACK, VERSION, &dummy);
}
}
static int
tunnel_dns(int tun_fd, int dns_fd)
{
struct in_addr tempip;
struct user dummy;
struct ip *hdr;
unsigned long outlen;
char logindata[16];
char out[64*1024];
char in[64*1024];
char unpacked[64*1024];
char *tmp[2];
int userid;
int touser;
int read;
int code;
userid = -1;
if ((read = read_dns(dns_fd, &(dummy.q), in, sizeof(in))) <= 0)
return 0;
if(in[0] == 'V' || in[0] == 'v') {
handle_version(dns_fd, in, read);
} else if(in[0] == 'L' || in[0] == 'l') {
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), read - 1, b32);
/* Login phase, handle auth */