LINK = $(CC) $(CFLAGS) $(LDFLAGS) $(LIBS)
HEADER = config.h
-PROGRAMS = ldns-read-zone \
- ldns-mx \
- ldns-chaos \
- ldns-update \
- ldns-keygen \
- ldns-key2ds \
- ldns-signzone \
- ldns-version \
- ldns-rrsig
+SOURCES = ldns-read-zone.c \
+ ldns-mx.c \
+ ldns-chaos.c \
+ ldns-update.c \
+ ldns-keygen.c \
+ ldns-key2ds.c \
+ ldns-signzone.c \
+ ldns-version.c \
+ ldns-rrsig.c
+PROGRAMS=$(SOURCES:.c=)
.PHONY: all clean realclean
$(LINK) -o $@ $+
## implicit rule
-%.o:
- $(COMPILE) -c $(srcdir)/$*.c
+%.o: $(srcdir)/%.c
+ $(COMPILE) -c $(srcdir)/$<
clean:
rm -f *.o
readable form
.SH SYNOPSIS
.B ldns-rrsig
-.IR [
--t
+.IR domain
+[
+.IR type
]
-.IR DOMAIN
-
.SH DESCRIPTION
\fBldns-rrsig\fR is used to print the expiration and inception date of
-a RRSIG
-
-.SH OPTIONS
-\fB-t\fR use the RRSIG which covers this type instead of SOA.
+a RRSIG. The first argument is a domain name. \fBldns-rrsig\fR will
+query the authoritative servers for that domain to get a list of RRSIGs.
+It will then print out the inception and experiration dates for the RRSIG
+covering the SOA record.
+.PP
+If the second argument \fBtype\fR is given the RRSIG covering that type will be shown.
.SH AUTHOR
Written by the ldns team as an example for ldns usage.
int
usage(FILE *fp, char *prog) {
- fprintf(fp, "%s domain\n", prog);
+ fprintf(fp, "%s domain [type]\n", prog);
fprintf(fp, " print out the inception and expiration dates\n");
fprintf(fp, " in a more human readable form\n");
- fprintf(fp, " -t <type>\tquery for RRSIG(<type>)\n");
+ fprintf(fp, " <type>\tquery for RRSIG(<type>), defaults to SOA\n");
return 0;
}
ldns_rr_list *ns_ip;
uint8_t i, j;
ldns_rr_type t;
+ char * type_name;
time_t incep, expir;
char incep_buf[26];
char expir_buf[26];
domain = NULL;
res = NULL;
localres = NULL;
- t = LDNS_RR_TYPE_SOA; /* can be overruled on the cmd line, -t switch */
/* option parsing */
- if (argc != 2) {
+ if (argc < 2) {
usage(stdout, argv[0]);
exit(EXIT_FAILURE);
} else {
}
}
+ if (argc == 3) {
+ /* optional type arg */
+ type_name = strdup(argv[2]);
+ t = ldns_rdf2rr_type(
+ ldns_rdf_new_frm_str(LDNS_RDF_TYPE_TYPE, type_name));
+ if (t == 0) {
+ fprintf(stderr, " *** %s is not a valid RR type\n", type_name);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ t = LDNS_RR_TYPE_SOA;
+ type_name = "SOA";
+ }
+
/* create a new resolver from /etc/resolv.conf */
localres = ldns_resolver_new_frm_file(NULL);
} else {
rrsig_type = ldns_rr_list_new();
- /* okay, this needs to be doctered out, the rdf type
- * is LDNS_RDF_TYPE_TYPE, but I need to compare it
- * with LDNS_RR_TYPEs. How to convert, do we want to
- * convert? XXX */
- /*
for(i = 0; i < ldns_rr_list_rr_count(rrsig); i++) {
- if (ldns_rr_get_type(
+ if (ldns_rdf2rr_type(
ldns_rr_rrsig_typecovered(
ldns_rr_list_rr(rrsig, i))) == t) {
ldns_rr_list_push_rr(rrsig_type,
ldns_rr_list_rr(rrsig, i));
}
}
- */
- /* FOR NOW TAKE ONLY THE FIRST ONE */
- ldns_rr_list_push_rr(rrsig_type,
- ldns_rr_list_rr(rrsig, 0));
-
+ if (ldns_rr_list_rr_count(rrsig_type) == 0) {
+ fprintf(stderr, " *** No RRSIG(%S) type found\n",
+ type_name);
+ exit(EXIT_FAILURE);
+ }
+
for(i = 0; i < ldns_rr_list_rr_count(rrsig_type); i++) {
incep = ldns_rdf2native_time_t(
ldns_rr_rrsig_inception(
incep_buf[24] = '\0';
expir_buf[24] = '\0';
- /* assume SOA XXX*/
- fprintf(stdout, "%s RRSIG(SOA): %s - %s\n",
- argv[1], incep_buf, expir_buf);
-
-
+ fprintf(stdout, "%s RRSIG(%s): %s - %s\n",
+ argv[1], type_name, incep_buf, expir_buf);
}
}
* \param[in] rd the ldns_rdf to operate on
* \return uint8_t the value extracted
*/
-uint8_t ldns_rdf2native_int8(ldns_rdf *rd);
+uint8_t ldns_rdf2native_int8(const ldns_rdf *rd);
/**
* returns the native uint16_t representation from the rdf.
* \param[in] rd the ldns_rdf to operate on
* \return uint16_t the value extracted
*/
-uint16_t ldns_rdf2native_int16(ldns_rdf *rd);
+uint16_t ldns_rdf2native_int16(const ldns_rdf *rd);
/**
* returns the native uint32_t representation from the rdf.
* \param[in] rd the ldns_rdf to operate on
* \return uint32_t the value extracted
*/
-uint32_t ldns_rdf2native_int32(ldns_rdf *rd);
+uint32_t ldns_rdf2native_int32(const ldns_rdf *rd);
/**
* returns the native time_t representation from the rdf.
* \param[in] rd the ldns_rdf to operate on
* \return time_t the value extracted (32 bits currently)
*/
-time_t ldns_rdf2native_time_t(ldns_rdf *rd);
+time_t ldns_rdf2native_time_t(const ldns_rdf *rd);
/**
* converts a ttl value (like 5d2h) to a long.
* \return struct sockaddr* the address in the format so other
* functions can use it (sendto)
*/
-struct sockaddr_storage * ldns_rdf2native_sockaddr_storage(ldns_rdf *rd, uint16_t port, size_t *size);
+struct sockaddr_storage * ldns_rdf2native_sockaddr_storage(const ldns_rdf *rd, uint16_t port, size_t *size);
/**
* returns an rdf with the sockaddr info. works for ip4 and ip6
*/
ldns_rr_list *ldns_rr_list_subtype_by_rdf(ldns_rr_list *l, ldns_rdf *r, size_t pos);
+/**
+ * convert an rdf of type LDNS_RDF_TYPE_TYPE to an actual
+ * LDNS_RR_TYPE. This is usefull in the case when inspecting
+ * the rrtype covered field of an RRSIG.
+ * \param[in] rd the rdf to look at
+ * \return a ldns_rr_type with equivalent LDNS_RR_TYPE
+ *
+ */
+ldns_rr_type ldns_rdf2rr_type(const ldns_rdf *rd);
+
/* added while doing lua */
bool ldns_rr_list_insert_rr(ldns_rr_list *rr_list, ldns_rr *r, size_t count);
/* for types that allow it, return
* the native/host order type */
uint8_t
-ldns_rdf2native_int8(ldns_rdf *rd)
+ldns_rdf2native_int8(const ldns_rdf *rd)
{
uint8_t data;
-
- switch(ldns_rdf_get_type(rd)) {
- case LDNS_RDF_TYPE_CLASS:
- case LDNS_RDF_TYPE_ALG:
- case LDNS_RDF_TYPE_INT8:
- memcpy(&data, ldns_rdf_data(rd), sizeof(data));
- return data;
- default:
- return 0;
+
+ /* only allow 8 bit rdfs */
+ if (ldns_rdf_size(rd) != LDNS_RDF_SIZE_BYTE) {
+ return 0;
}
+
+ memcpy(&data, ldns_rdf_data(rd), sizeof(data));
+ return data;
}
uint16_t
-ldns_rdf2native_int16(ldns_rdf *rd)
+ldns_rdf2native_int16(const ldns_rdf *rd)
{
uint16_t data;
-
- switch(ldns_rdf_get_type(rd)) {
- case LDNS_RDF_TYPE_INT16:
- memcpy(&data, ldns_rdf_data(rd), sizeof(data));
- return ntohs(data);
- default:
- return 0;
+
+ /* only allow 16 bit rdfs */
+ if (ldns_rdf_size(rd) != LDNS_RDF_SIZE_WORD) {
+ return 0;
}
+
+ memcpy(&data, ldns_rdf_data(rd), sizeof(data));
+ return ntohs(data);
}
uint32_t
-ldns_rdf2native_int32(ldns_rdf *rd)
+ldns_rdf2native_int32(const ldns_rdf *rd)
{
uint32_t data;
-
- switch(ldns_rdf_get_type(rd)) {
- case LDNS_RDF_TYPE_INT32:
- memcpy(&data, ldns_rdf_data(rd), sizeof(data));
- return ntohl(data);
- default:
- return 0;
+
+ /* only allow 32 bit rdfs */
+ if (ldns_rdf_size(rd) != LDNS_RDF_SIZE_DOUBLEWORD) {
+ return 0;
}
+
+ memcpy(&data, ldns_rdf_data(rd), sizeof(data));
+ return ntohl(data);
}
time_t
-ldns_rdf2native_time_t(ldns_rdf *rd)
+ldns_rdf2native_time_t(const ldns_rdf *rd)
{
uint32_t data;
}
struct sockaddr_storage *
-ldns_rdf2native_sockaddr_storage(ldns_rdf *rd, uint16_t port, size_t *size)
+ldns_rdf2native_sockaddr_storage(const ldns_rdf *rd, uint16_t port, size_t *size)
{
struct sockaddr_storage *data;
struct sockaddr_in *data_in;
ldns_rdf *
ldns_native2rdf_int8(ldns_rdf_type type, uint8_t value)
{
- return ldns_rdf_new_frm_data(type, 1, &value);
+ return ldns_rdf_new_frm_data(type, LDNS_RDF_SIZE_BYTE, &value);
}
ldns_rdf *
{
uint16_t *rdf_data = LDNS_XMALLOC(uint16_t, 1);
ldns_write_uint16(rdf_data, value);
- return ldns_rdf_new(type, 2, rdf_data);
+ return ldns_rdf_new(type, LDNS_RDF_SIZE_WORD, rdf_data);
}
ldns_rdf *
{
uint32_t *rdf_data = LDNS_XMALLOC(uint32_t, 1);
ldns_write_uint32(rdf_data, value);
- return ldns_rdf_new(type, 4, rdf_data);
+ return ldns_rdf_new(type, LDNS_RDF_SIZE_DOUBLEWORD, rdf_data);
}
ldns_rdf *
}
}
}
-
-
LDNS_FREE(rd);
ldns_buffer_free(rd_buf);
ldns_buffer_free(rr_buf);
return 0;
}
+
+ldns_rr_type
+ldns_rdf2rr_type(const ldns_rdf *rd)
+{
+ ldns_rr_type r;
+
+ if (!rd) {
+ return 0;
+ }
+
+ if (ldns_rdf_get_type(rd) != LDNS_RDF_TYPE_TYPE) {
+ return 0;
+ }
+
+ r = (ldns_rr_type) ldns_rdf2native_int16(rd);
+ return r;
+}