-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move DNS related code to subdirectory
- Loading branch information
Showing
13 changed files
with
102 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,3 @@ | |
/[Bb]uild/ | ||
*.[od] | ||
/callback | ||
/dns-test | ||
/dns-test-afl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,17 @@ | ||
AFL_CXX ?= afl-g++ | ||
CXX ?= g++ | ||
CPPFLAGS ?= -isystem $(HOME)/git/GSL/include | ||
CXXFLAGS ?= -Wall -Wextra -Werror -std=c++17 -O3 -ggdb3 -fstack-protector-strong -fsanitize=address,undefined | ||
|
||
BIN = callback dns-test dns-test-afl | ||
dns_test_SRC = dns-test.cpp dns.cpp | ||
DEP = callback.d $(dns_test_SRC:.cpp=.d) | ||
OBJ = $(dns_test_SRC:.cpp=.o) $(dns_test_SRC:.cpp=.afl.o) | ||
TEST_CASES_BIN = $(patsubst test-cases/%.bm,test-cases-bin/%.bin,$(wildcard test-cases/*.bm)) | ||
BIN = callback | ||
DEP = callback.d | ||
|
||
all: $(BIN) $(TEST_CASES_BIN) | ||
all: $(BIN) | ||
|
||
clean: | ||
$(RM) $(DEP) $(OBJ) $(BIN) $(TEST_CASES_BIN) | ||
|
||
%.o: %.cpp | ||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MD -MT $@ -MF $(@:.o=.d) -o $@ -c $< | ||
|
||
%.afl.o: %.cpp | ||
AFL_HARDEN=1 $(AFL_CXX) $(CPPFLAGS) $(CXXFLAGS) -MD -MT $@ -MF $(@:.afl.o=.d) -o $@ -c $< | ||
$(RM) $(DEP) $(BIN) | ||
|
||
callback: callback.hpp | ||
$(CXX) $(CPPFLAGS) -DTEST -x c++ $(CXXFLAGS) -MD -MT $@ -MF $(@).d -o $@ $< | ||
|
||
test-cases-bin: | ||
mkdir test-cases-bin | ||
|
||
test-cases-bin/%.bin: test-cases/%.bm test-cases-bin | ||
binmake $< $@ | ||
|
||
dns-test: $(dns_test_SRC:.cpp=.o) | ||
$(CXX) $(CXXFLAGS) -o $@ $^ | ||
|
||
dns-test-afl: $(dns_test_SRC:.cpp=.afl.o) | ||
AFL_HARDEN=1 $(AFL_CXX) $(CXXFLAGS) -o $@ $^ | ||
|
||
.PHONY: all clean | ||
|
||
-include $(DEP) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/parse-test | ||
/parse-test-afl | ||
/test-cases-bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
AFL_CXX ?= afl-g++ | ||
CXX ?= g++ | ||
CPPFLAGS ?= -isystem $(HOME)/git/GSL/include -I.. | ||
CXXFLAGS ?= -Wall -Wextra -Werror -std=c++17 -O3 -ggdb3 -fstack-protector-strong -fsanitize=address,undefined | ||
|
||
BIN = parse-test parse-test-afl | ||
parse_test_SRC = parse-test.cpp parser.cpp | ||
DEP = $(parse_test_SRC:.cpp=.d) | ||
OBJ = $(parse_test_SRC:.cpp=.o) $(parse_test_SRC:.cpp=.afl.o) | ||
TEST_CASES_BIN = $(patsubst test-cases/%.bm,test-cases-bin/%.bin,$(wildcard test-cases/*.bm)) | ||
|
||
all: $(BIN) $(TEST_CASES_BIN) | ||
|
||
clean: | ||
$(RM) $(DEP) $(OBJ) $(BIN) $(TEST_CASES_BIN) | ||
|
||
%.o: %.cpp | ||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MD -MT $@ -MF $(@:.o=.d) -o $@ -c $< | ||
|
||
%.afl.o: %.cpp | ||
AFL_HARDEN=1 $(AFL_CXX) $(CPPFLAGS) $(CXXFLAGS) -MD -MT $@ -MF $(@:.afl.o=.d) -o $@ -c $< | ||
|
||
test-cases-bin: | ||
mkdir test-cases-bin | ||
|
||
test-cases-bin/%.bin: test-cases/%.bm test-cases-bin | ||
binmake $< $@ | ||
|
||
parse-test: $(parse_test_SRC:.cpp=.o) | ||
$(CXX) $(CXXFLAGS) -o $@ $^ | ||
|
||
parse-test-afl: $(parse_test_SRC:.cpp=.afl.o) | ||
AFL_HARDEN=1 $(AFL_CXX) $(CXXFLAGS) -o $@ $^ | ||
|
||
.PHONY: all clean | ||
|
||
-include $(DEP) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "dns.hpp" | ||
#include <dns/parser.hpp> | ||
#include "overload.hpp" | ||
#include <fstream> | ||
#include <iomanip> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (C) 2018 Giel van Schijndel | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this program. If not, see | ||
* <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef INCLUDED_DNS_PARSER_HPP | ||
#define INCLUDED_DNS_PARSER_HPP | ||
|
||
#include "dns.hpp" | ||
#include "expected.hpp" | ||
#include <gsl/span> | ||
#include <iterator> | ||
#include <utility> | ||
|
||
namespace dns | ||
{ | ||
expected<message> parse(gsl::span<const std::uint8_t> frame); | ||
|
||
inline expected<std::pair<message, const std::uint8_t*>> | ||
parse(const std::uint8_t* const first, const std::uint8_t* const last) | ||
{ | ||
using ::util::unexpected; | ||
|
||
if (std::distance(first, last) < 2) | ||
return unexpected(parser_error::not_enough_data); | ||
const std::uint16_t len = *first << 8U | (*std::next(first) & 0xffU); | ||
if (std::distance(first, last) < 2 + len) | ||
return unexpected(parser_error::not_enough_data); | ||
const auto next = std::next(first, 2 + len); | ||
if (auto msg = parse(gsl::span{std::next(first, 2), next}); msg) | ||
return std::make_pair(std::move(*msg), next); | ||
else | ||
return unexpected(std::move(msg).error()); | ||
} | ||
} | ||
|
||
#endif /* INCLUDED_DNS_PARSER_HPP */ |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.