1
0
mirror of https://github.com/yarrick/iodine.git synced 2024-11-22 13:06:06 +03:00

We can send data

This commit is contained in:
Erik Ekman 2006-06-05 18:36:34 +00:00
parent ecb97656ab
commit f9381aa723
2 changed files with 51 additions and 4 deletions

52
dns.c
View File

@ -140,11 +140,13 @@ close_dns(int fd)
void
dns_ping(int dns_fd)
{
dns_query(dns_fd, "4.kryo.se", 1);
dns_write(dns_fd, dns_fd,
"AAAAAAAAAAAKRYOAAAAAAAAAAAKRYOAAAAAAAAAAAAAKRYOAAAAAAAAAAAAAKRYOAAAAAAAAAAAAAAAKRYOAAAAAAAAAAAAAKRYOAAAAAAAAAAAAAAAAAAB",
119);
}
void
dns_query(int fd, char *host, int type)
dns_query(int fd, int id, char *host, int type)
{
char *p;
int len;
@ -157,7 +159,7 @@ dns_query(int fd, char *host, int type)
header = (HEADER*)buf;
header->id = 0;
header->id = id;
header->qr = 0;
header->opcode = 0;
header->aa = 0;
@ -179,6 +181,50 @@ dns_query(int fd, char *host, int type)
sendto(fd, buf, len+1, 0, (struct sockaddr*)&peer, peerlen);
}
int
dns_write(int fd, int id, char *buf, int len)
{
int avail;
int i;
int parts;
int p;
char data[256];
char *d;
#define CHUNK 31
// 31 bytes expands to 62 chars in domain
// We just use hex as encoding right now
avail = 0xFF - strlen(topdomain) - 2;
avail /= 2; // use two chars per byte in encoding
avail -= (avail/CHUNK); // make space for parts
avail = MIN(avail, len); // do not use more bytes than is available;
d = data;
parts = avail / CHUNK;
for (p = 0; p < parts; p++) {
for (i = 0; i < CHUNK; i++) {
sprintf(d, "%02X", buf[p*CHUNK + i]);
d += 2;
}
*d++ = '.';
strcpy(d, topdomain);
}
parts = avail % CHUNK;
for (i = 0; i < parts; i++) {
sprintf(d, "%02X", buf[p*CHUNK + i]);
d += 2;
}
*d++ = '.';
strcpy(d, topdomain);
printf("Resolving %s\n", data);
dns_query(fd, id, data, T_A);
return avail;
}
int
dns_read(int fd, char *buf, int buflen)
{

3
dns.h
View File

@ -23,7 +23,8 @@ int open_dns(const char *, const char *);
void close_dns(int);
void dns_ping(int);
void dns_query(int, char *, int);
void dns_query(int, int, char *, int);
int dns_write(int, int, char *, int);
int dns_read(int, char *, int);