Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
f971bd7b
Commit
f971bd7b
authored
27 years ago
by
Fredrik Hübinette (Hubbe)
Browse files
Options
Downloads
Patches
Plain Diff
fixed a bunch of bugs
Rev: lib/modules/Protocols.pmod/DNS.pmod:1.3
parent
8af96b0a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/Protocols.pmod/DNS.pmod
+63
-25
63 additions, 25 deletions
lib/modules/Protocols.pmod/DNS.pmod
with
63 additions
and
25 deletions
lib/modules/Protocols.pmod/DNS.pmod
+
63
−
25
View file @
f971bd7b
...
@@ -279,12 +279,20 @@ class client {
...
@@ -279,12 +279,20 @@ class client {
});
});
}
}
string arpa_from_ip(string ip)
{
return reverse(ip/".")*"."+".IN-ADDR.ARPA";
}
string ip_from_arpa(string arpa)
{
return reverse(arpa/".")[2..]*".";
}
// Warning: NO TIMEOUT
// Warning: NO TIMEOUT
mixed *gethostbyaddr(string s)
mixed *gethostbyaddr(string s)
{
{
mapping m=do_sync_query(mkquery(reverse(s/".")*"."+".IN-ADDR.ARPA",
mapping m=do_sync_query(mkquery(arpa_from_ip(s), C_IN, T_PTR));
C_IN,
T_PTR));
string *names=({});
string *names=({});
string *ips=({});
string *ips=({});
foreach(m->an, mapping x)
foreach(m->an, mapping x)
...
@@ -294,7 +302,7 @@ class client {
...
@@ -294,7 +302,7 @@ class client {
if(x->name)
if(x->name)
{
{
ips+=({
reverse(x->name/".")[2..]*"."
});
ips+=({
ip_from_arpa(x->name)
});
}
}
}
}
return ({
return ({
...
@@ -325,46 +333,44 @@ class client {
...
@@ -325,46 +333,44 @@ class client {
class async_client
class async_client
{
{
inherit client;
inherit client;
inherit spider.dumUDP;
inherit spider.dumUDP
: udp
;
int id;
int id;
class Request
class Request
{
{
string req;
string req;
function success
;
string domain
;
function
fail
;
function
callback
;
int retries;
int retries;
mixed *args;
mixed *args;
};
};
static private
mapping requests=([]);
mapping requests=([]);
static private void remove(object(Request) r)
static private void remove(object(Request) r)
{
{
if(!r) return;
if(!r) return;
sscanf(r->req,"%2c",int id);
sscanf(r->req,"%2c",int id);
function f=r->fail;
mixed *args=r->args;
m_delete(requests,id);
m_delete(requests,id);
r->callback(r->domain,0,@r->args);
destruct(r);
destruct(r);
f(@args);
}
}
void retry(object(Request) r)
void retry(object(Request) r)
{
{
if(!r) return;
if(!r) return;
if(r->retries >
6
)
if(r->retries
++
>
12
)
{
{
call_out(remove,120,r);
call_out(remove,120,r);
}else{
}else{
call_out(retry,5,r);
send(nameserver,53,r->req);
send(nameserver,53,r->req);
}
}
}
}
void do_query(string domain, int cl, int type,
void do_query(string domain, int cl, int type,
function callback,
function(string,mapping,mixed...:void) callback,
function fail_callback,
mixed ... args)
mixed ... args)
{
{
id++;
id++;
...
@@ -376,31 +382,63 @@ class async_client
...
@@ -376,31 +382,63 @@ class async_client
object r=Request();
object r=Request();
r->req=req;
r->req=req;
r->success=callback;
r->domain=domain;
r->fail=fail_callback;
r->callback=callback;
r->args=args;
requests[id]=r;
requests[id]=r;
call_out(retry,5,r);
call_out(retry,5,r);
send(nameserver,53,r->req);
udp::
send(nameserver,53,r->req);
}
}
static private void rec_data()
static private void rec_data()
{
{
mapping m=read();
mapping m=
udp::
read();
if(m->port != 53 || m->ip != nameserver) return;
if(m->port != 53 || m->ip != nameserver) return;
sscanf(m->data,"%2c",int id);
sscanf(m->data,"%2c",int id);
object r=requests[id];
object r=requests[id];
if(!r) return;
if(!r) return;
function f=r->success;
mixed *args=r->args;
m_delete(requests,id);
m_delete(requests,id);
r->callback(r->domain,decode_res(m->data),@r->args);
destruct(r);
destruct(r);
f(decode_res(m->data),@args);
}
}
void creat(string server)
static private void generic_get(string d,
mapping answer,
string field,
string domain,
function callback,
mixed ... args)
{
if(!answer || !answer->an || !sizeof(answer->an))
{
{
bind(0);
callback(domain,0,@args);
set_read_callback(rec_data);
}else{
callback(domain,answer->an[0][field],@args);
}
}
void host_to_ip(string host, function callback, mixed ... args)
{
do_query(host, C_IN, T_A,
generic_get,"a",
host, callback,
@args );
}
void ip_to_host(string ip, function callback, mixed ... args)
{
do_query(arpa_from_ip(ip), C_IN, T_PTR,
generic_get, "ptr",
ip, callback,
@args);
}
void create(void|string server)
{
if(!udp::bind(0))
throw(({"DNS: failed to bind a port.\n",backtrace()}));
udp::set_read_callback(rec_data);
::create(server);
::create(server);
}
}
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment