From 005e91ef7a7087ded8343d394ae75aed7c7fdbc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Va=C5=A1ek?= Date: Fri, 18 Jun 2021 20:11:52 +0200 Subject: [PATCH] backup: print the full network hostname in the label file --- src/knot/zone/backup.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/knot/zone/backup.c b/src/knot/zone/backup.c index 41ea622b0d..64f807ddc0 100644 --- a/src/knot/zone/backup.c +++ b/src/knot/zone/backup.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -71,8 +72,6 @@ static const char *label_file_head = LABEL_FILE_HEAD; static int make_label_file(zone_backup_ctx_t *ctx, char *full_path) { - int ret; - FILE *file = fopen(full_path, "w"); if (file == NULL) { return knot_map_errno(); @@ -80,9 +79,19 @@ static int make_label_file(zone_backup_ctx_t *ctx, char *full_path) // Prepare the hostname. char hostname[HOSTNAME_MAX]; - gethostname(hostname, HOSTNAME_MAX); + int ret = gethostname(hostname, HOSTNAME_MAX); // When the name doesn't fit, the \0 terminator isn't always guaranteed. hostname[HOSTNAME_MAX - 1] = '\0'; + char *netname = hostname; + if (ret == 0) { + struct hostent* h; + h = gethostbyname(hostname); + if (h != NULL) { + netname = h->h_name; + } + } else { + netname = ""; + } // Prepare the timestamps. char started_time[64], finished_time[64]; @@ -107,7 +116,7 @@ static int make_label_file(zone_backup_ctx_t *ctx, char *full_path) "+backupdir %s\n" "zone_count: %d\n", label_file_head, - BACKUP_VERSION, hostname, started_time, finished_time, PACKAGE_VERSION, + BACKUP_VERSION, netname, started_time, finished_time, PACKAGE_VERSION, ctx->backup_zonefile ? "" : "no", ctx->backup_journal ? "" : "no", ctx->backup_timers ? "" : "no",