X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fdns.cpp;h=0e0f3287466e3931c003febfc1917e903fac6091;hb=6f4bf8ffd367f35b96265fea1ad01fb1acf2adcd;hp=4248affaef9bb2beecd220e0ce095b7c2a602f16;hpb=193b540aa750446bf67dcad132773541214c296d;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/dns.cpp b/src/dns.cpp index 4248affae..0e0f32874 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -94,12 +94,12 @@ class DNSHeader class DNSRequest { public: - unsigned char id[2]; /* Request id */ - unsigned char* res; /* Result processing buffer */ + unsigned char id[2]; /* Request id */ + unsigned char* res; /* Result processing buffer */ unsigned int rr_class; /* Request class */ - QueryType type; /* Request type */ + QueryType type; /* Request type */ insp_inaddr myserver; /* DNS server address*/ - DNS* dnsobj; /* DNS caller (where we get our FD from) */ + DNS* dnsobj; /* DNS caller (where we get our FD from) */ DNSRequest(InspIRCd* Instance, DNS* dns, insp_inaddr server, int id, requestlist &requests); ~DNSRequest(); @@ -468,10 +468,15 @@ int DNS::GetName(const insp_inaddr *ip) int length; #ifdef IPV6 - DNS::MakeIP6Int(query, (in6_addr*)ip); + unsigned char* c = (unsigned char*)&ip->s6_addr; + if (c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0 && + c[4] == 0 && c[5] == 0 && c[6] == 0 && c[7] == 0 && + c[8] == 0 && c[9] == 0 && c[10] == 0xFF && c[11] == 0xFF) + sprintf(query,"%d.%d.%d.%d.in-addr.arpa",c[15],c[14],c[13],c[12]); + else + DNS::MakeIP6Int(query, (in6_addr*)ip); #else unsigned char* c = (unsigned char*)&ip->s_addr; - sprintf(query,"%d.%d.%d.%d.in-addr.arpa",c[3],c[2],c[1],c[0]); #endif @@ -726,7 +731,11 @@ DNSInfo DNSRequest::ResultIsReady(DNSHeader &header, int length) int curanswer, o; ResourceRecord rr; unsigned short ptr; - + + /* This is just to keep _FORTIFY_SOURCE happy */ + rr.type = DNS_QUERY_NONE; + rr.rdlength = 0; + if (!(header.flags1 & FLAGS_MASK_QR)) return std::make_pair((unsigned char*)NULL,"Not a query result"); @@ -865,7 +874,7 @@ DNS::~DNS() } /** High level abstraction of dns used by application at large */ -Resolver::Resolver(InspIRCd* Instance, const std::string &source, QueryType qt) : ServerInstance(Instance), input(source), querytype(qt) +Resolver::Resolver(InspIRCd* Instance, const std::string &source, QueryType qt, Module* creator) : ServerInstance(Instance), Creator(creator), input(source), querytype(qt) { ServerInstance->Log(DEBUG,"Instance: %08x %08x",Instance, ServerInstance); @@ -943,6 +952,11 @@ int Resolver::GetId() return this->myid; } +Module* Resolver::GetCreator() +{ + return this->Creator; +} + /** Process a socket read event */ void DNS::HandleEvent(EventType et, int errornum) { @@ -1020,6 +1034,22 @@ bool DNS::AddResolverClass(Resolver* r) } } +void DNS::CleanResolvers(Module* module) +{ + for (int i = 0; i < MAX_REQUEST_ID; i++) + { + if (Classes[i]) + { + if (Classes[i]->GetCreator() == module) + { + Classes[i]->OnError(RESLOVER_FORCEUNLOAD, "Parent module is unloading"); + delete Classes[i]; + Classes[i] = NULL; + } + } + } +} + /** Generate pseudo-random number */ unsigned long DNS::PRNG() {