Skip to content

Commit f3752b1

Browse files
committed
Add README, LICENSE
1 parent 28b8875 commit f3752b1

File tree

6 files changed

+89
-41
lines changed

6 files changed

+89
-41
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Serhii Pievniev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
SRC_DIR := src
2-
OUT_DIR := build
3-
EXTERNAL_DIR := external
4-
1+
SRC_DIR := src
2+
OUT_DIR := build
3+
EXTERNAL_DIR := external
4+
INSTALL_DIR ?= /usr/local/bin
55
TEST_COMMON_DIR := tests/common
66
TEST_MOCK_DIR := tests/mock
77
BIND_CASES_DIR := tests/cases/bind
@@ -12,23 +12,24 @@ BIN_PATH := $(OUT_DIR)/$(BIN_NAME)
1212

1313
CC := g++
1414
CFLAGS := -O2 -std=c++23 -Wall -Wextra -pedantic -I $(SRC_DIR) -MMD -MP
15-
LDFLAGS := $(shell pkg-config --libs openssl)
1615
DEBUG_CFLAGS := -g3 -fsanitize=address,leak,undefined
16+
LDFLAGS := $(shell pkg-config --libs "openssl >= 3.0")
1717

18-
ifeq ($(DEBUG), 1)
19-
CFLAGS += $(DEBUG_CFLAGS)
20-
endif
18+
BIN_CFLAGS := $(CFLAGS)
19+
BIND_TEST_CFLAGS := $(CFLAGS) $(DEBUG_CFLAGS)
20+
# Mock tests must not include debug flags because libasan(enable by `fsanitize`) intercepts the
21+
# required functions(recvfrom and sendto) thus preventing the mocked functions from being used.
22+
MOCK_TEST_CFLAGS := $(CFLAGS)
2123

22-
# Disable optimizations to speed up CI
23-
ifdef CI
24-
CFLAGS += -O0
24+
ifeq ($(DEBUG), 1)
25+
BIN_CFLAGS += $(DEBUG_CFLAGS)
2526
endif
2627

2728
BIN_SRCS := $(shell find $(SRC_DIR) -type f -name '*.cc')
2829
BIN_OBJS := $(patsubst %.cc, $(OUT_DIR)/%.o, $(BIN_SRCS))
2930
BIN_DEPS := $(patsubst %.o, %.d, $(BIN_OBJS))
3031

31-
TEST_COMMON_SRCS := $(shell find $(TEST_COMMON_DIR) -type f -name '*.cc') $(filter-out $(SRC_DIR)/main.cc, $(BIN_SRCS))
32+
TEST_COMMON_SRCS := $(filter-out $(SRC_DIR)/main.cc, $(BIN_SRCS))
3233
BIND_COMMON_OBJ_DIR := $(OUT_DIR)/$(TEST_COMMON_DIR)/bind
3334
BIND_COMMON_OBJS := $(patsubst %.cc, $(BIND_COMMON_OBJ_DIR)/%.o, $(TEST_COMMON_SRCS))
3435
BIND_COMMON_DEPS := $(patsubst %.o, %.d, $(BIND_COMMON_OBJS))
@@ -59,43 +60,49 @@ clean:
5960

6061
build: $(BIN_PATH)
6162

63+
install: build
64+
install -D -m755 $(BIN_PATH) $(INSTALL_DIR)/$(BIN_NAME)
65+
66+
uninstall:
67+
rm $(INSTALL_DIR)/$(BIN_NAME)
68+
6269
$(BIN_PATH): $(BIN_OBJS)
6370
@mkdir -p $(@D)
64-
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
71+
$(CC) $(BIN_CFLAGS) -o $@ $^ $(LDFLAGS)
6572

6673
$(OUT_DIR)/%.o: %.cc
6774
@mkdir -p $(@D)
68-
$(CC) $(CFLAGS) -I $(EXTERNAL_DIR)/cxxopts -o $@ -c $<
75+
$(CC) $(BIN_CFLAGS) -I $(EXTERNAL_DIR)/cxxopts -o $@ -c $<
6976

7077
test: $(BIND_CASES) $(MOCK_CASES)
7178
@./tests/test.sh
7279

7380
$(BIND_CASES_OUT_DIR)/%: $(BIND_CASES_OUT_DIR)/%.o $(BIND_COMMON_OBJS)
7481
@mkdir -p $(@D)
75-
$(CC) $(CFLAGS) $(DEBUG_CFLAGS) -o $@ $^ $(LDFLAGS)
82+
$(CC) $(BIND_TEST_CFLAGS) -o $@ $^ $(LDFLAGS)
7683

7784
$(BIND_CASES_OUT_DIR)/%.o: $(BIND_CASES_DIR)/%.cc
7885
@mkdir -p $(@D)
79-
$(CC) $(CFLAGS) $(DEBUG_CFLAGS) -I $(TEST_COMMON_DIR) -o $@ -c $<
86+
$(CC) $(BIND_TEST_CFLAGS) -I $(TEST_COMMON_DIR) -o $@ -c $<
8087

8188
$(BIND_COMMON_OBJ_DIR)/%.o: %.cc
8289
@mkdir -p $(@D)
83-
$(CC) $(CFLAGS) $(DEBUG_CFLAGS) -o $@ -c $<
90+
$(CC) $(BIND_TEST_CFLAGS) -o $@ -c $<
8491

8592
$(MOCK_CASES_OUT_DIR)/%: $(MOCK_CASES_OUT_DIR)/%.o $(TEST_MOCK_OBJS) $(MOCK_COMMON_OBJS)
8693
@mkdir -p $(@D)
87-
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
94+
$(CC) $(MOCK_TEST_CFLAGS) -o $@ $^ $(LDFLAGS)
8895

8996
$(MOCK_CASES_OUT_DIR)/%.o: $(MOCK_CASES_DIR)/%.cc
9097
@mkdir -p $(@D)
91-
$(CC) $(CFLAGS) -I $(TEST_COMMON_DIR) -I $(TEST_MOCK_DIR) -o $@ -c $<
98+
$(CC) $(MOCK_TEST_CFLAGS) -I $(TEST_COMMON_DIR) -I $(TEST_MOCK_DIR) -o $@ -c $<
9299

93100
$(MOCK_COMMON_OBJ_DIR)/%.o: %.cc
94101
@mkdir -p $(@D)
95-
$(CC) $(CFLAGS) -o $@ -c $<
102+
$(CC) $(MOCK_TEST_CFLAGS) -o $@ -c $<
96103

97104
$(TEST_MOCK_OBJ_DIR)/%.o: %.cc
98105
@mkdir -p $(@D)
99-
$(CC) $(CFLAGS) -I $(TEST_COMMON_DIR) -o $@ -c $<
106+
$(CC) $(MOCK_TEST_CFLAGS) -I $(TEST_COMMON_DIR) -o $@ -c $<
100107

101108
-include $(BIN_DEPS) $(BIND_COMMON_DEPS) $(MOCK_COMMON_DEPS) $(TEST_MOCK_DEPS) $(BIND_CASES_DEPS) $(MOCK_CASES_DEPS)

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Iterative DNS Resolver CLI
2+
3+
## Dependencies
4+
5+
- Make >= 4.3
6+
- pkg-config >= 1.8.1
7+
- OpenSSL >= 3.0.14
8+
- g++ >= 15
9+
- libstdc++ (comes with g++) >= 15
10+
11+
## Implemented RFCs
12+
- [RFC1034](https://www.rfc-editor.org/rfc/rfc1034): DOMAIN NAMES - CONCEPTS AND FACILITIES
13+
- [RFC1035](https://www.rfc-editor.org/rfc/rfc1035): DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION
14+
- [RFC4033](https://www.rfc-editor.org/rfc/rfc4033): DNS Security Introduction and Requirements
15+
- [RFC4034](https://www.rfc-editor.org/rfc/rfc4034): Resource Records for the DNS Security Extensions
16+
- [RFC4035](https://www.rfc-editor.org/rfc/rfc4035): Protocol Modifications for the DNS Security Extensions
17+
- [RFC5155](https://www.rfc-editor.org/rfc/rfc5155): DNS Security (DNSSEC) Hashed Authenticated Denial of Existence
18+
- [RFC5702](https://www.rfc-editor.org/rfc/rfc5702): Use of SHA-2 Algorithms with RSA in DNSKEY and RRSIG Resource Records for DNSSEC
19+
- [RFC6605](https://www.rfc-editor.org/rfc/rfc6605): Elliptic Curve Digital Signature Algorithm (DSA) for DNSSEC
20+
- [RFC6840](https://www.rfc-editor.org/rfc/rfc6840): Clarifications and Implementation Notes for DNS Security (DNSSEC)
21+
- [RFC6891](https://www.rfc-editor.org/rfc/rfc6891): Extension Mechanisms for DNS (EDNS(0))
22+
- [RFC7129](https://www.rfc-editor.org/rfc/rfc7129): Authenticated Denial of Existence in the DNS
23+
- [RFC7873](https://www.rfc-editor.org/rfc/rfc7873): Domain Name System (DNS) Cookies
24+
- [RFC8080](https://www.rfc-editor.org/rfc/rfc8080): Edwards-Curve Digital Security Algorithm (EdDSA) for DNSSEC

src/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ std::istream &operator>>(std::istream &is, FeatureState &out) {
5555

5656
int main(int argc, char **argv) {
5757
try {
58-
cxxopts::Options options{"resolver", "CLI DNS resolver"};
58+
cxxopts::Options options{"resolver", "Iterative DNS Resolver CLI"};
5959
options.custom_help("[options]");
6060
options.positional_help("<domain>");
6161

tests/common/common.cc

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/common/common.hh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include <arpa/inet.h>
44
#include <netinet/in.h>
55
#include <sys/socket.h>
6+
#include <cassert>
67
#include <cstdlib>
8+
#include <cstring>
79
#include <print> // IWYU pragma: keep
810

911
#define ASSERT(condition) \
@@ -14,5 +16,16 @@
1416
} \
1517
} while (0)
1618

17-
in_addr_t get_ip4(const char *ip_str);
18-
bool ip6_equals(struct in6_addr address, const char *ip_str);
19+
inline in_addr_t get_ip4(const char *ip_str) {
20+
in_addr_t ip_addr;
21+
auto result = inet_pton(AF_INET, ip_str, &ip_addr);
22+
assert(result == 1);
23+
return ip_addr;
24+
}
25+
26+
inline bool ip6_equals(struct in6_addr address_a, const char *ip_str) {
27+
struct in6_addr address_b;
28+
auto result = inet_pton(AF_INET6, ip_str, &address_b);
29+
assert(result == 1);
30+
return std::memcmp(&address_a, &address_b, sizeof(address_a)) == 0;
31+
}

0 commit comments

Comments
 (0)