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
3d3ed7c0
Commit
3d3ed7c0
authored
27 years ago
by
Fredrik Hübinette (Hubbe)
Browse files
Options
Downloads
Patches
Plain Diff
completely untested async_client added
Rev: lib/modules/Protocols.pmod/DNS.pmod:1.2
parent
bb02cca1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/Protocols.pmod/DNS.pmod
+88
-9
88 additions, 9 deletions
lib/modules/Protocols.pmod/DNS.pmod
with
88 additions
and
9 deletions
lib/modules/Protocols.pmod/DNS.pmod
+
88
−
9
View file @
3d3ed7c0
...
@@ -36,14 +36,11 @@ class protocol
...
@@ -36,14 +36,11 @@ class protocol
return sprintf("%c%s",strlen(s),s);
return sprintf("%c%s",strlen(s),s);
}
}
// This will have to be generalized for
string low_mkquery(int id,
// the server part...
string dname,
string mkquery(string dname,
int cl,
int cl,
int type)
int type)
{
{
int id=random(65536); // make spoofing harder
return sprintf("%2c%c%c%2c%2c%2c%2c%s\000%2c%2c",
return sprintf("%2c%c%c%2c%2c%2c%2c%s\000%2c%2c",
id,
id,
1,0,
1,0,
...
@@ -56,6 +53,15 @@ class protocol
...
@@ -56,6 +53,15 @@ class protocol
}
}
// This will have to be generalized for
// the server part...
string mkquery(string dname,
int cl,
int type)
{
return low_mkquery(random(65536),dname,cl,type);
}
string decode_domain(string msg, int *n)
string decode_domain(string msg, int *n)
{
{
string *domains=({});
string *domains=({});
...
@@ -319,9 +325,82 @@ class client {
...
@@ -319,9 +325,82 @@ class client {
class async_client
class async_client
{
{
inherit client;
inherit client;
inherit spider.dumUDP;
int id;
mapping requests=([]);
class Request
class request
{
{
string req;
function success;
function fail;
int retries;
mixed *args;
};
};
static private mapping requests=([]);
static private void remove(object(Request) r)
{
if(!r) return;
sscanf(r->req,"%2c",int id);
function f=r->fail;
mixed *args=r->args;
m_delete(requests,id);
destruct(r);
f(@args);
}
void retry(object(Request) r)
{
if(!r) return;
if(r->retries > 6)
{
call_out(remove,120,r);
}else{
send(nameserver,53,r->req);
}
}
void do_query(string domain, int cl, int type,
function callback,
function fail_callback,
mixed ... args)
{
id++;
id&=65535;
string req=low_mkquery(id,domain,cl,type);
if(requests[id])
throw(({"Cannot find an empty request slot.\n",backtrace()}));
object r=Request();
r->req=req;
r->success=callback;
r->fail=fail_callback;
requests[id]=r;
call_out(retry,5,r);
send(nameserver,53,r->req);
}
static private void rec_data()
{
mapping m=read();
if(m->port != 53 || m->ip != nameserver) return;
sscanf(m->data,"%2c",int id);
object r=requests[id];
if(!r) return;
function f=r->success;
mixed *args=r->args;
m_delete(requests,id);
destruct(r);
f(decode_res(m->data),@args);
}
void creat(string server)
{
bind(0);
set_read_callback(rec_data);
::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