aboutsummaryrefslogtreecommitdiff
path: root/nix/libstore/.gitignore
diff options
context:
space:
mode:
authorVincent Legoll <vincent.legoll@gmail.com>2020-12-23 18:14:25 +0100
committerLeo Famulari <leo@famulari.name>2020-12-24 15:19:02 -0500
commitfcdf4b4ec6192a81dd2a8b8fb58e1c0f3e91a4d9 (patch)
tree3ac9b78152b71d581230882017b9727d9a332c0e /nix/libstore/.gitignore
parentc9120aa101cd4b881ac078acd6484bf3c5c431cc (diff)
downloadguix-fcdf4b4ec6192a81dd2a8b8fb58e1c0f3e91a4d9.tar.gz
guix-fcdf4b4ec6192a81dd2a8b8fb58e1c0f3e91a4d9.zip
gnu: Add libinih.
* gnu/packages/linux.scm (libinih): New variable. Signed-off-by: Leo Famulari <leo@famulari.name>
Diffstat (limited to 'nix/libstore/.gitignore')
0 files changed, 0 insertions, 0 deletions
ROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * This is a simple helper program for testing our resolver.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+
+#include <unbound.h>
+
+/* examine the result structure in detail */
+void examine_result(const char *query, struct ub_result *result)
+{
+ int i;
+ int num;
+
+ printf("The query is for: %s\n", query);
+ printf("The result has:\n");
+ printf("qname: %s\n", result->qname);
+ printf("qtype: %d\n", result->qtype);
+ printf("qclass: %d\n", result->qclass);
+ if(result->canonname)
+ printf("canonical name: %s\n",
+ result->canonname);
+ else printf("canonical name: <none>\n");
+
+ if(result->havedata)
+ printf("has data\n");
+ else printf("has no data\n");
+
+ if(result->nxdomain)
+ printf("nxdomain (name does not exist)\n");
+ else printf("not an nxdomain (name exists)\n");
+
+ if(result->secure)
+ printf("validated to be secure\n");
+ else printf("not validated as secure\n");
+
+ if(result->bogus)
+ printf("a security failure! (bogus)\n");
+ else printf("not a security failure (not bogus)\n");
+
+ printf("DNS rcode: %d\n", result->rcode);
+
+ if(!result->havedata)
+ return;
+
+ num = 0;
+ for(i=0; result->data[i]; i++) {
+ printf("result data element %d has length %d\n",
+ i, result->len[i]);
+ printf("result data element %d is: %s\n",
+ i, inet_ntoa(*(struct in_addr*)result->data[i]));
+ num++;
+ }
+ printf("result has %d data element(s)\n", num);
+}
+
+struct ub_ctx *create_ub_context(int debuglevel) {
+ int rc;
+ struct ub_ctx* ctx;
+ char *error_message_format;
+
+ ctx = ub_ctx_create();
+ if (!ctx) {
+ fprintf(stderr, "Couldn't create libunbound context.\n");
+ return NULL;
+ }
+
+ error_message_format = "Couldn't set forwarder: %s\n";
+ rc = ub_ctx_set_fwd(ctx, "127.0.0.1");
+ if (rc)
+ goto out;
+
+ error_message_format = "Couldn't set debuglevel: %s\n";
+ rc = ub_ctx_debuglevel(ctx, debuglevel);
+
+out:
+ if (rc) {
+ fprintf(stderr, error_message_format, ub_strerror(rc));
+ ub_ctx_delete(ctx);
+ return NULL;
+ }
+
+ return ctx;
+}
+
+void ztdns_try_resolve(struct ub_ctx *ctx, const char *name) {
+ struct ub_result* result;
+ int rc;
+ rc = ub_resolve(ctx, name,
+ 1 /* TYPE A (IPv4 address) */,
+ 1 /* CLASS IN (internet) */, &result);
+ if(rc)
+ printf("resolve error: %s\n", ub_strerror(rc));
+ else {
+ examine_result(name, result);
+ ub_resolve_free(result);
+ }
+}
+
+int main(int argc, char** argv)
+{
+ struct ub_ctx *ctx;
+
+ if (argc < 2) {
+ printf("Usage: %s DOMAINNAME\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ ctx = create_ub_context(3);
+ if (!ctx)
+ return EXIT_FAILURE;
+
+ ztdns_try_resolve(ctx, argv[1]);
+
+ ub_ctx_delete(ctx);
+
+ return EXIT_SUCCESS;
+}