getting the examples into the build, dns validator needs finished

This commit is contained in:
Meredith L. Patterson 2012-05-24 12:43:32 +02:00
parent 13fab7e49c
commit 8e7a5cc2d3
3 changed files with 40 additions and 22 deletions

View file

@ -3,7 +3,7 @@
# and kick off a recursive make # and kick off a recursive make
# Also, "make src/all" turns into "make -C src all" # Also, "make src/all" turns into "make -C src all"
SUBDIRS = src SUBDIRS = src examples
.DEFAULT_GOAL := all .DEFAULT_GOAL := all

15
examples/Makefile Normal file
View file

@ -0,0 +1,15 @@
OUTPUTS := dns.o \
dns
TOPLEVEL := ../
include ../common.mk
all: dns
dns: dns.o
$(call hush, "Linking $@") $(CC) -o $@ $^ $(LDFLAGS)
dns.o: ../src/hammer.h

View file

@ -1,4 +1,7 @@
#include "../hammer.h" #include "../src/hammer.h"
#define false 0
#define true 1
bool is_zero(parse_result_t *p) { bool is_zero(parse_result_t *p) {
if (TT_UINT != p->ast->token_type) if (TT_UINT != p->ast->token_type)
@ -10,7 +13,7 @@ bool is_zero(parse_result_t *p) {
* A label can't be more than 63 characters. * A label can't be more than 63 characters.
*/ */
bool validate_label(parse_result_t *p) { bool validate_label(parse_result_t *p) {
if (TT_SEQ != p->ast->token_type) if (TT_SEQUENCE != p->ast->token_type)
return 0; return 0;
return (64 > p->ast->seq->used); return (64 > p->ast->seq->used);
} }
@ -21,23 +24,23 @@ bool validate_label(parse_result_t *p) {
* *
*/ */
bool validate_dns(parse_result_t *p) { bool validate_dns(parse_result_t *p) {
if (TT_SEQ != p->ast->token_type) if (TT_SEQUENCE != p->ast->token_type)
return 0; return 0;
// The header holds the counts as its last 4 elements. // The header holds the counts as its last 4 elements.
parsed_token_t *header = p->ast->seq->elements[0]; parsed_token_t *header = p->ast->seq->elements[0];
size_t qd = header->seq->elements[8]; size_t qd = ((parsed_token_t*)header->seq->elements[8])->uint;
size_t an = header->seq->elements[9]; size_t an = ((parsed_token_t*)header->seq->elements[9])->uint;
size_t ns = header->seq->elements[10]; size_t ns = ((parsed_token_t*)header->seq->elements[10])->uint;
size_t ar = header->seq->elements[11]; size_t ar = ((parsed_token_t*)header->seq->elements[11])->uint;
parsed_token_t *questions = p->ast->seq->elements[1]; parsed_token_t *questions = p->ast->seq->elements[1];
if (questions->seq->used != qd) if (questions->seq->used != qd)
return false; return 0;
parsed_token_t *rrs = p->ast->seq->elements[2]; parsed_token_t *rrs = p->ast->seq->elements[2];
if (an+ns+ar != rrs->seq->used) if (an+ns+ar != rrs->seq->used)
return false; return 0;
} }
parser_t init_parser() { parser_t* init_parser() {
static parser_t *dns_message = NULL; static parser_t *dns_message = NULL;
if (dns_message) if (dns_message)
return dns_message; return dns_message;
@ -62,12 +65,12 @@ parser_t init_parser() {
uint16(), // QCLASS uint16(), // QCLASS
NULL); NULL);
const parser_t *letter = choice(range('a', 'z'), const parser_t *letter = choice(ch_range('a', 'z'),
range('A', 'Z'), ch_range('A', 'Z'),
NULL); NULL);
const parser_t *let_dig = choice(letter, const parser_t *let_dig = choice(letter,
range('0', '9'), ch_range('0', '9'),
NULL); NULL);
const parser_t *ldh_str = many1(choice(let_dig, const parser_t *ldh_str = many1(choice(let_dig,
@ -95,7 +98,7 @@ parser_t init_parser() {
* ... but this is easier and equivalent * ... but this is easier and equivalent
*/ */
parser_t *subdomain = sepBy1(label, ch('.')); const parser_t *subdomain = sepBy1(label, ch('.'));
const parser_t *domain = choice(subdomain, const parser_t *domain = choice(subdomain,
ch(' '), ch(' '),
@ -105,16 +108,16 @@ parser_t init_parser() {
uint16(), // TYPE uint16(), // TYPE
uint16(), // CLASS uint16(), // CLASS
uint32(), // TTL uint32(), // TTL
length_value(uint16(), uint8()) // RDLENGTH+RDATA length_value(uint16(), uint8()), // RDLENGTH+RDATA
NULL); NULL);
dns_message = attr_bool(sequence(dns_header, dns_message = (parser_t*)attr_bool(sequence(dns_header,
many(dns_question), many(dns_question),
many(dns_rr), many(dns_rr),
end_p(), end_p(),
NULL), NULL),
validate_dns); validate_dns);
return dns_message; return dns_message;
} }