mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-27 03:55:09 +00:00
We can send data
This commit is contained in:
parent
ecb97656ab
commit
f9381aa723
52
dns.c
52
dns.c
@ -140,11 +140,13 @@ close_dns(int fd)
|
|||||||
void
|
void
|
||||||
dns_ping(int dns_fd)
|
dns_ping(int dns_fd)
|
||||||
{
|
{
|
||||||
dns_query(dns_fd, "4.kryo.se", 1);
|
dns_write(dns_fd, dns_fd,
|
||||||
|
"AAAAAAAAAAAKRYOAAAAAAAAAAAKRYOAAAAAAAAAAAAAKRYOAAAAAAAAAAAAAKRYOAAAAAAAAAAAAAAAKRYOAAAAAAAAAAAAAKRYOAAAAAAAAAAAAAAAAAAB",
|
||||||
|
119);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dns_query(int fd, char *host, int type)
|
dns_query(int fd, int id, char *host, int type)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
int len;
|
int len;
|
||||||
@ -157,7 +159,7 @@ dns_query(int fd, char *host, int type)
|
|||||||
|
|
||||||
header = (HEADER*)buf;
|
header = (HEADER*)buf;
|
||||||
|
|
||||||
header->id = 0;
|
header->id = id;
|
||||||
header->qr = 0;
|
header->qr = 0;
|
||||||
header->opcode = 0;
|
header->opcode = 0;
|
||||||
header->aa = 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);
|
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
|
int
|
||||||
dns_read(int fd, char *buf, int buflen)
|
dns_read(int fd, char *buf, int buflen)
|
||||||
{
|
{
|
||||||
|
3
dns.h
3
dns.h
@ -23,7 +23,8 @@ int open_dns(const char *, const char *);
|
|||||||
void close_dns(int);
|
void close_dns(int);
|
||||||
|
|
||||||
void dns_ping(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);
|
int dns_read(int, char *, int);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user