diff --git a/dns.c b/dns.c index 3a74e1f..11dabfc 100644 --- a/dns.c +++ b/dns.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -286,7 +287,7 @@ int dns_parse_reply(char *outbuf, int buflen, char *packet, int packetlen) { int rv; - long ttl; + uint32_t ttl; short rlen; short type; short class; diff --git a/read.c b/read.c index 832af41..1e40dba 100644 --- a/read.c +++ b/read.c @@ -15,7 +15,7 @@ */ #include -#include +#include static int readname_loop(char *packet, int packetlen, char **src, char *dst, size_t length, size_t loop) @@ -95,19 +95,20 @@ readshort(char *packet, char **src, short *dst) } int -readlong(char *packet, char **src, long *dst) +readlong(char *packet, char **src, uint32_t *dst) { + // A long as described in dns protocol is always 32 bits unsigned char *p; p = *src; - *dst = ((long)p[0] << 24) - | ((long)p[1] << 16) - | ((long)p[2] << 8) - | ((long)p[3]); + *dst = ((uint32_t)p[0] << 24) + | ((uint32_t)p[1] << 16) + | ((uint32_t)p[2] << 8) + | ((uint32_t)p[3]); - (*src) += sizeof(long); - return sizeof(long); + (*src) += sizeof(uint32_t); + return sizeof(uint32_t); } int @@ -147,8 +148,9 @@ putshort(char **dst, short value) } int -putlong(char **dst, long value) +putlong(char **dst, uint32_t value) { + // A long as described in dns protocol is always 32 bits unsigned char *p; p = *dst; @@ -159,7 +161,7 @@ putlong(char **dst, long value) *p++ = (value); (*dst) = p; - return sizeof(long); + return sizeof(uint32_t); } int diff --git a/read.h b/read.h index 27b0cbf..d695a7e 100644 --- a/read.h +++ b/read.h @@ -19,12 +19,12 @@ int readname(char *, int, char **, char *, size_t); int readshort(char *, char **, short *); -int readlong(char *, char **, long *); +int readlong(char *, char **, uint32_t *); int readdata(char *, char **, char *, size_t); int putbyte(char **, char); int putshort(char **, short); -int putlong(char **, long); +int putlong(char **, uint32_t); int putdata(char **, char *, size_t); #endif diff --git a/test.c b/test.c index d9545e2..ee1eb63 100644 --- a/test.c +++ b/test.c @@ -23,6 +23,7 @@ #include #endif #include +#include #include #include #include @@ -73,10 +74,10 @@ static void test_readputlong() { char buf[4]; - long putint; - long tempi; - long tint; - long *l; + uint32_t putint; + uint32_t tempi; + uint32_t tint; + uint32_t *l; char* p; int i; @@ -89,13 +90,13 @@ test_readputlong() p = buf; putlong(&p, tint); l = &putint; - memcpy(l, buf, sizeof(int)); + memcpy(l, buf, sizeof(uint32_t)); if (putint != tempi) { printf("Bad value on putlong for %d\n", i); exit(2); } l = &tempi; - memcpy(buf, l, sizeof(int)); + memcpy(buf, l, sizeof(uint32_t)); p = buf; readlong(NULL, &p, &tempi); if (tempi != tint) {