dinoco

Query DNS records
git clone git://git.relim.de/dinoco.git
Log | Files | Refs | README | LICENSE

commit 37cd24103a4af78555a69b61c41c0250928140c4
parent 9004dee3609ee850ea8a508e7009d5f9b5da1481
Author: Nibo <kroekerrobin@gmail.com>
Date:   Mon, 13 Nov 2023 15:45:47 +0100

Change argument handling of domain

Diffstat:
MMakefile | 2+-
Mdinoco.c | 36+++++++++++++++++++++++-------------
Mdinoco.h | 2+-
3 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile @@ -2,7 +2,7 @@ PREFIX = /usr/local MANPREFIX = $(PREFIX)/share/man all: - $(CC) -g -O -Werror -o dinoco dinoco.c + $(CC) -g -O -Wall -Werror -o dinoco dinoco.c clean: rm dinoco install: all diff --git a/dinoco.c b/dinoco.c @@ -8,6 +8,7 @@ #include <sys/socket.h> #include <netdb.h> #include <arpa/inet.h> +#include <inttypes.h> #include "dinoco.h" inline char *stringCat(char *str1, char *str2) @@ -61,7 +62,7 @@ char *getDNSServerIP() FILE *fp = popen(cmd, "r"); char *buf = malloc(16 * sizeof(char)); size_t bytesRead = fread(buf, 1, 15, fp); - fclose(fp); + pclose(fp); if (bytesRead >= MIN_IP_LENGTH) { buf[bytesRead] = 0; @@ -723,7 +724,7 @@ void printAnswers case TYPE_MINFO: break; case TYPE_MX: - size_t longestMailDomain = 0; + int longestMailDomain = 0; size_t len = 0; for (int i=0; i<answerCount; i++) { @@ -835,7 +836,6 @@ bool isValidResponse(struct dns_header *reqHeader, struct dns_header *resHeader) int main(int argc, char *argv[]) { static struct option options[] = { - { "domain", required_argument, 0, 'd' }, { "type", required_argument, 0, 't' }, { "header", no_argument, 0, 'h' }, { 0, 0, 0, 0 } @@ -843,19 +843,13 @@ int main(int argc, char *argv[]) int optionIndex = 0; int o = 0; char *domain; - char *type; - bool isDomain = false; + char *type = NULL; bool isType = false; bool disableHeader = false; - while ((o = getopt_long(argc, argv, "d:t:h", options, &optionIndex)) != -1) + while ((o = getopt_long(argc, argv, "t:h", options, &optionIndex)) != -1) { switch (o) { - case 'd': - domain = malloc((strlen(optarg) + 1) * sizeof(char)); - strcpy(domain, optarg); - isDomain = true; - break; case 't': type = malloc((strlen(optarg)+1) * sizeof(char)); strcpy(type, optarg); @@ -866,15 +860,31 @@ int main(int argc, char *argv[]) break; } } - if (!isDomain || !isType) + if (argc == optind) + { + fprintf(stderr, "Provide a domain!\n"); + free(type); + return -1; + } + if (argc > optind+1) { - printf("You have to set both the domain (-d/--domain) and the type (-t/--type).\n"); + fprintf(stderr, "Provide only one domain!\n"); + free(type); return -1; } + domain = malloc((strlen(argv[optind])+1) * sizeof(char)); + strcpy(domain, argv[optind]); + if (!isType) + { + fprintf(stderr, "Provide a type (-t/--type)!\n"); + free(domain); + return -1; + } short tp = parseType(toUpper(type)); if (tp == -1) { printf("You provided an invalid type.\n"); + free(domain); return -1; } enum type t = tp; diff --git a/dinoco.h b/dinoco.h @@ -126,7 +126,7 @@ struct dns_resource_record char *domain; enum type type; enum class class; - uint32_t ttl; + int32_t ttl; uint16_t rdlength; struct byte_array *rdata; };