Extract version checking to function

This commit is contained in:
Erik Ekman 2007-12-01 21:46:13 +00:00
parent b55c3f432b
commit 212a3b93e6

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)); write_dns(fd, &u->q, out, sizeof(out));
} }
static int static void
tunnel_dns(int tun_fd, int dns_fd) 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 unpacked[64*1024];
char *tmp[2]; struct user dummy;
int userid;
int touser;
int version;
int read; int read;
int code; int version;
int userid;
userid = -1; read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), len - 1, b32);
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);
/* Version greeting, compare and send ack/nak */ /* Version greeting, compare and send ack/nak */
if (read > 4) { if (read > 4) {
/* Received V + 32bits version */ /* Received V + 32bits version */
@ -174,6 +160,31 @@ tunnel_dns(int tun_fd, int dns_fd)
} else { } else {
send_version_response(dns_fd, VERSION_NACK, VERSION, &dummy); 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') { } else if(in[0] == 'L' || in[0] == 'l') {
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), read - 1, b32); read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), read - 1, b32);
/* Login phase, handle auth */ /* Login phase, handle auth */