diff --git a/src/gldns/gbuffer.h b/src/gldns/gbuffer.h index 32b3f9d1..7aa5a1b8 100644 --- a/src/gldns/gbuffer.h +++ b/src/gldns/gbuffer.h @@ -497,7 +497,7 @@ gldns_buffer_set_at(gldns_buffer *buffer, size_t at, int c, size_t count) * writes count bytes of data to the current position of the buffer * \param[in] buffer the buffer * \param[in] data the data to write - * \param[in] count the lenght of the data to write + * \param[in] count the length of the data to write */ INLINE void gldns_buffer_write(gldns_buffer *buffer, const void *data, size_t count) diff --git a/src/gldns/parse.c b/src/gldns/parse.c index d44c328e..a353c503 100644 --- a/src/gldns/parse.c +++ b/src/gldns/parse.c @@ -33,14 +33,14 @@ ssize_t gldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr) { int c, prev_c; - int p; /* 0 -> no parenthese seen, >0 nr of ( seen */ + int p; /* 0 -> no parentheses seen, >0 nr of ( seen */ int com, quoted; char *t; size_t i; const char *d; const char *del; - /* standard delimeters */ + /* standard delimiters */ if (!delim) { /* from isspace(3) */ del = GLDNS_PARSE_NORMAL; @@ -244,7 +244,7 @@ gldns_bget_token_par(gldns_buffer *b, char *token, const char *delim, size_t limit, int* par, const char* skipw) { int c, lc; - int p; /* 0 -> no parenthese seen, >0 nr of ( seen */ + int p; /* 0 -> no parentheses seen, >0 nr of ( seen */ int com, quoted; char *t; size_t i; diff --git a/src/gldns/parse.h b/src/gldns/parse.h index a62efaf5..e2ea7cb9 100644 --- a/src/gldns/parse.h +++ b/src/gldns/parse.h @@ -103,9 +103,9 @@ ssize_t gldns_bget_token(struct gldns_buffer *b, char *token, const char *delim, * after the keyword + k_del until we hit d_del * \param[in] f file pointer to read from * \param[in] keyword keyword to look for - * \param[in] k_del keyword delimeter + * \param[in] k_del keyword delimiter * \param[out] data the data found - * \param[in] d_del the data delimeter + * \param[in] d_del the data delimiter * \param[in] data_limit maximum size the the data buffer * \return the number of character read */ @@ -116,9 +116,9 @@ ssize_t gldns_fget_keyword_data(FILE *f, const char *keyword, const char *k_del, * after the keyword + k_del until we hit d_del * \param[in] f file pointer to read from * \param[in] keyword keyword to look for - * \param[in] k_del keyword delimeter + * \param[in] k_del keyword delimiter * \param[out] data the data found - * \param[in] d_del the data delimeter + * \param[in] d_del the data delimiter * \param[in] data_limit maximum size the the data buffer * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes) @@ -131,9 +131,9 @@ ssize_t gldns_fget_keyword_data_l(FILE *f, const char *keyword, const char *k_de * after the keyword + k_del until we hit d_del * \param[in] b buffer pointer to read from * \param[in] keyword keyword to look for - * \param[in] k_del keyword delimeter + * \param[in] k_del keyword delimiter * \param[out] data the data found - * \param[in] d_del the data delimeter + * \param[in] d_del the data delimiter * \param[in] data_limit maximum size the the data buffer * \return the number of character read */ diff --git a/src/gldns/parseutil.c b/src/gldns/parseutil.c index 558446cb..bc4738b9 100644 --- a/src/gldns/parseutil.c +++ b/src/gldns/parseutil.c @@ -165,20 +165,20 @@ gldns_gmtime64_r(int64_t clock, struct tm *result) #endif /* SIZEOF_TIME_T <= 4 */ static int64_t -gldns_serial_arithmitics_time(int32_t time, time_t now) +gldns_serial_arithmetics_time(int32_t time, time_t now) { int32_t offset = time - (int32_t) now; return (int64_t) now + offset; } struct tm * -gldns_serial_arithmitics_gmtime_r(int32_t time, time_t now, struct tm *result) +gldns_serial_arithmetics_gmtime_r(int32_t time, time_t now, struct tm *result) { #if SIZEOF_TIME_T <= 4 - int64_t secs_since_epoch = gldns_serial_arithmitics_time(time, now); + int64_t secs_since_epoch = gldns_serial_arithmetics_time(time, now); return gldns_gmtime64_r(secs_since_epoch, result); #else - time_t secs_since_epoch = gldns_serial_arithmitics_time(time, now); + time_t secs_since_epoch = gldns_serial_arithmetics_time(time, now); return gmtime_r(&secs_since_epoch, result); #endif } diff --git a/src/gldns/parseutil.h b/src/gldns/parseutil.h index b2b6101d..1546e8be 100644 --- a/src/gldns/parseutil.h +++ b/src/gldns/parseutil.h @@ -62,13 +62,13 @@ time_t gldns_mktime_from_utc(const struct tm *tm); * fields of RRSIG records. * * \param[in] time number of seconds since epoch (midnight, January 1st, 1970) - * to be intepreted as a serial arithmetics number relative to now. + * to be interpreted as a serial arithmetics number relative to now. * \param[in] now number of seconds since epoch (midnight, January 1st, 1970) * to which the time value is compared to determine the final value. * \param[out] result the struct with the broken-out time information * \return result on success or NULL on error */ -struct tm * gldns_serial_arithmitics_gmtime_r(int32_t time, time_t now, struct tm *result); +struct tm * gldns_serial_arithmetics_gmtime_r(int32_t time, time_t now, struct tm *result); /** * converts a ttl value (like 5d2h) to a long. diff --git a/src/gldns/str2wire.c b/src/gldns/str2wire.c index ffd3d464..8ce4b06d 100644 --- a/src/gldns/str2wire.c +++ b/src/gldns/str2wire.c @@ -836,7 +836,7 @@ const char* gldns_get_errorstr_parse(int e) } /* Strip whitespace from the start and the end of . */ -static char * +char * gldns_strip_ws(char *line) { char *s = line, *e; @@ -906,7 +906,7 @@ int gldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len, *dname_len = 0; return GLDNS_WIREPARSE_ERR_INCLUDE; } else { - return gldns_str2wire_rr_buf(line, rr, len, dname_len, + int r = gldns_str2wire_rr_buf(line, rr, len, dname_len, parse_state?parse_state->default_ttl:0, (parse_state&&parse_state->origin_len)? parse_state->origin:NULL, @@ -914,6 +914,13 @@ int gldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len, (parse_state&&parse_state->prev_rr_len)? parse_state->prev_rr:NULL, parse_state?parse_state->prev_rr_len:0); + if(r == GLDNS_WIREPARSE_ERR_OK && (*dname_len) != 0 && + parse_state && + (*dname_len) <= sizeof(parse_state->prev_rr)) { + memmove(parse_state->prev_rr, rr, *dname_len); + parse_state->prev_rr_len = (*dname_len); + } + return r; } return GLDNS_WIREPARSE_ERR_OK; } @@ -1541,7 +1548,7 @@ int gldns_str2wire_loc_buf(const char* str, uint8_t* rd, size_t* len) s = strtod(my_str, &my_str); } - /* skip blanks before norterness */ + /* skip blanks before northerness */ while (isblank((unsigned char) *my_str)) { my_str++; } @@ -1693,12 +1700,15 @@ int gldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len) struct protoent *p = getprotobyname(token); have_proto = 1; if(p) rd[0] = (uint8_t)p->p_proto; + else if(strcasecmp(token, "tcp")==0) rd[0]=6; + else if(strcasecmp(token, "udp")==0) rd[0]=17; else rd[0] = (uint8_t)atoi(token); (void)strlcpy(proto_str, token, sizeof(proto_str)); } else { int serv_port; struct servent *serv = getservbyname(token, proto_str); if(serv) serv_port=(int)ntohs((uint16_t)serv->s_port); + else if(strcasecmp(token, "domain")==0) serv_port=53; else { serv_port = atoi(token); if(serv_port == 0 && strcmp(token, "0") != 0) { diff --git a/src/gldns/str2wire.h b/src/gldns/str2wire.h index 1b7777bd..2aba0e10 100644 --- a/src/gldns/str2wire.h +++ b/src/gldns/str2wire.h @@ -554,6 +554,12 @@ int gldns_str2wire_hip_buf(const char* str, uint8_t* rd, size_t* len); */ int gldns_str2wire_int16_data_buf(const char* str, uint8_t* rd, size_t* len); +/** + * Strip whitespace from the start and the end of line. + * @param line: modified with 0 to shorten it. + * @return new start with spaces skipped. + */ +char * gldns_strip_ws(char *line); #ifdef __cplusplus } #endif diff --git a/src/gldns/wire2str.c b/src/gldns/wire2str.c index f6fda2e5..0cba52cf 100644 --- a/src/gldns/wire2str.c +++ b/src/gldns/wire2str.c @@ -255,6 +255,12 @@ int gldns_wire2str_rr_buf(uint8_t* d, size_t dlen, char* s, size_t slen) return gldns_wire2str_rr_scan(&d, &dlen, &s, &slen, NULL, 0); } +int gldns_wire2str_rrquestion_buf(uint8_t* d, size_t dlen, char* s, size_t slen) +{ + /* use arguments as temporary variables */ + return gldns_wire2str_rrquestion_scan(&d, &dlen, &s, &slen, NULL, 0); +} + int gldns_wire2str_rdata_buf(uint8_t* rdata, size_t rdata_len, char* str, size_t str_len, uint16_t rrtype) { @@ -1331,7 +1337,7 @@ int gldns_wire2str_time_scan(uint8_t** d, size_t* dl, char** s, size_t* sl) if(*dl < 4) return -1; t = gldns_read_uint32(*d); date_buf[15]=0; - if(gldns_serial_arithmitics_gmtime_r(t, time(NULL), &tm) && + if(gldns_serial_arithmetics_gmtime_r(t, time(NULL), &tm) && strftime(date_buf, 15, "%Y%m%d%H%M%S", &tm)) { (*d) += 4; (*dl) -= 4; @@ -1467,6 +1473,10 @@ int gldns_wire2str_wks_scan(uint8_t** d, size_t* dl, char** s, size_t* sl) if(protocol && (protocol->p_name != NULL)) { w += gldns_str_print(s, sl, "%s", protocol->p_name); proto_name = protocol->p_name; + } else if(protocol_nr == 6) { + w += gldns_str_print(s, sl, "tcp"); + } else if(protocol_nr == 17) { + w += gldns_str_print(s, sl, "udp"); } else { w += gldns_str_print(s, sl, "%u", (unsigned)protocol_nr); } diff --git a/src/gldns/wire2str.h b/src/gldns/wire2str.h index 2007fd8e..a7a7c930 100644 --- a/src/gldns/wire2str.h +++ b/src/gldns/wire2str.h @@ -358,6 +358,22 @@ int gldns_wire2str_edns_option_code_print(char** str, size_t* str_len, int gldns_wire2str_rr_buf(uint8_t* rr, size_t rr_len, char* str, size_t str_len); +/** + * Convert question RR to string presentation format, on one line. User buffer. + * @param rr: wireformat RR data + * @param rr_len: length of the rr wire data. + * @param str: the string buffer to write to. + * If you pass NULL as the str, the return value of the function is + * the str_len you need for the entire packet. It does not include + * the 0 byte at the end. + * @param str_len: the size of the string buffer. If more is needed, it'll + * silently truncate the output to fit in the buffer. + * @return the number of characters for this element, excluding zerobyte. + * Is larger or equal than str_len if output was truncated. + */ +int gldns_wire2str_rrquestion_buf(uint8_t* rr, size_t rr_len, char* str, + size_t str_len); + /** * 3597 printout of an RR in unknown rr format. * There are more format and comment options available for printout