mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Fixed bug in DNS triggered when adding two records for the same domain name.
This commit is contained in:
37
Makefile.in
37
Makefile.in
@@ -1,13 +1,27 @@
|
|||||||
|
BASENAME=libtins.so
|
||||||
|
MAJOR=0
|
||||||
|
MINOR=2
|
||||||
|
|
||||||
|
SONAME=$(BASENAME).$(MAJOR)
|
||||||
|
|
||||||
CXX=@CXX@
|
CXX=@CXX@
|
||||||
CFLAGS=-c -Wall -fPIC @CFLAGS@ -DTINS_VERSION=@PACKAGE_VERSION@
|
CFLAGS=-c -Wall -fPIC @CFLAGS@ -DTINS_VERSION=@PACKAGE_VERSION@
|
||||||
LDFLAGS=-lpcap -shared -Wl,-soname,libtins.so -Wl,-z,defs
|
LDFLAGS=-lpcap -shared -Wl,-soname,$(SONAME) -Wl,-z,defs
|
||||||
SOURCES=$(wildcard src/*.cpp)
|
SOURCES=$(wildcard src/*.cpp)
|
||||||
|
|
||||||
OBJECTS=$(SOURCES:.cpp=.o)
|
OBJECTS=$(SOURCES:.cpp=.o)
|
||||||
INCLUDE=-Iinclude/
|
INCLUDE=-Iinclude/
|
||||||
EXECUTABLE=libtins.so
|
EXECUTABLE=$(BASENAME).$(MAJOR).$(MINOR)
|
||||||
DEPS = $(SOURCES:.cpp=.d)
|
DEPS = $(SOURCES:.cpp=.d)
|
||||||
|
|
||||||
|
prefix = /usr/local
|
||||||
|
exec_prefix = $(prefix)
|
||||||
|
|
||||||
|
bindir = $(exec_prefix)/bin
|
||||||
|
libdir = $(exec_prefix)/lib
|
||||||
|
includedir = $(prefix)/include
|
||||||
|
|
||||||
|
|
||||||
all: $(SOURCES) $(EXECUTABLE)
|
all: $(SOURCES) $(EXECUTABLE)
|
||||||
|
|
||||||
compile: $(OBJECTS)
|
compile: $(OBJECTS)
|
||||||
@@ -30,15 +44,22 @@ $(EXECUTABLE): $(OBJECTS)
|
|||||||
$(CXX) $(CXXFLAGS) $(INCLUDE) -MG -MM -MP -MT"$(<:.cpp=.o)" $< >> depends.d
|
$(CXX) $(CXXFLAGS) $(INCLUDE) -MG -MM -MP -MT"$(<:.cpp=.o)" $< >> depends.d
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(OBJECTS) $(EXECUTABLE)
|
rm -f $(OBJECTS) $(EXECUTABLE)
|
||||||
|
|
||||||
install:
|
install:
|
||||||
install -d /usr/include/tins/
|
install -d $(DESTDIR)$(includedir)/tins/
|
||||||
install -t /usr/include/tins/ include/*
|
install -m 644 -t $(DESTDIR)$(includedir)/tins/ include/*
|
||||||
install $(EXECUTABLE) /usr/lib/
|
install -d $(DESTDIR)$(libdir)
|
||||||
|
install -m 644 $(EXECUTABLE) $(DESTDIR)$(libdir)/
|
||||||
|
if [ -f $(DESTDIR)$(libdir)/$(BASENAME) ]; then rm $(DESTDIR)$(libdir)/$(BASENAME); fi
|
||||||
|
if [ -f $(DESTDIR)$(libdir)/$(SONAME) ]; then rm $(DESTDIR)$(libdir)/$(SONAME); fi
|
||||||
|
ln -s $(EXECUTABLE) $(DESTDIR)$(libdir)/$(BASENAME)
|
||||||
|
ln -s $(EXECUTABLE) $(DESTDIR)$(libdir)/$(SONAME)
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -r /usr/include/tins/
|
rm -r $(DESTDIR)$(includedir)/tins/
|
||||||
rm /usr/lib/$(EXECUTABLE)
|
rm $(DESTDIR)$(libdir)/$(EXECUTABLE)
|
||||||
|
rm $(DESTDIR)$(libdir)/$(BASENAME)
|
||||||
|
rm $(DESTDIR)$(libdir)/$(SONAME)
|
||||||
|
|
||||||
-include depends.d
|
-include depends.d
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ void DNS::add_suffix(uint32_t index, const uint8_t *data, uint32_t sz) const {
|
|||||||
uint32_t DNS::build_suffix_map(uint32_t index, const ResourcesType &lst) const {
|
uint32_t DNS::build_suffix_map(uint32_t index, const ResourcesType &lst) const {
|
||||||
const string *str;
|
const string *str;
|
||||||
for(ResourcesType::const_iterator it(lst.begin()); it != lst.end(); ++it) {
|
for(ResourcesType::const_iterator it(lst.begin()); it != lst.end(); ++it) {
|
||||||
str = it->dname();
|
str = it->has_domain_name() ? it->dname() : 0;
|
||||||
if(str) {
|
if(str) {
|
||||||
add_suffix(index, (uint8_t*)str->c_str(), str->size());
|
add_suffix(index, (uint8_t*)str->c_str(), str->size());
|
||||||
index += str->size() + 1;
|
index += str->size() + 1;
|
||||||
@@ -374,7 +374,9 @@ void DNS::compose_name(const uint8_t *ptr, uint32_t sz, std::string &out) const
|
|||||||
index &= 0x3fff;
|
index &= 0x3fff;
|
||||||
SuffixMap::iterator it(suffixes.find(index));
|
SuffixMap::iterator it(suffixes.find(index));
|
||||||
SuffixIndices::iterator suff_it(suffix_indices.find(index));
|
SuffixIndices::iterator suff_it(suffix_indices.find(index));
|
||||||
if(it == suffixes.end() || suff_it == suffix_indices.end())
|
// We need at least a suffix or a suffix index to compose
|
||||||
|
// the domain name
|
||||||
|
if(it == suffixes.end() && suff_it == suffix_indices.end())
|
||||||
throw std::runtime_error("Malformed DNS packet");
|
throw std::runtime_error("Malformed DNS packet");
|
||||||
bool first(true);
|
bool first(true);
|
||||||
do {
|
do {
|
||||||
|
|||||||
@@ -221,4 +221,17 @@ TEST_F(DNSTest, Answers) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(DNSTest, AnswersWithSameName) {
|
||||||
|
DNS dns;
|
||||||
|
dns.add_answer("www.example.com", DNS::make_info(DNS::A, DNS::IN, 0x762), IPv4Address("127.0.0.1"));
|
||||||
|
dns.add_answer("www.example.com", DNS::make_info(DNS::A, DNS::IN, 0x762), IPv4Address("127.0.0.2"));
|
||||||
|
ASSERT_EQ(dns.answers_count(), 2);
|
||||||
|
DNS::resources_type resources = dns.answers();
|
||||||
|
for(DNS::resources_type::const_iterator it = resources.begin(); it != resources.end(); ++it) {
|
||||||
|
EXPECT_TRUE(it->data() == "127.0.0.1" || it->data() == "127.0.0.2");
|
||||||
|
EXPECT_EQ(it->dname(), "www.example.com");
|
||||||
|
EXPECT_EQ(it->type(), DNS::A);
|
||||||
|
EXPECT_EQ(it->ttl(), 0x762);
|
||||||
|
EXPECT_EQ(it->query_class(), DNS::IN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user