farp: use watcher instead of dedicated receiver thread
This commit is contained in:
@@ -96,20 +96,16 @@ static void send_arp(private_farp_spoofer_t *this,
|
|||||||
/**
|
/**
|
||||||
* ARP request receiving
|
* ARP request receiving
|
||||||
*/
|
*/
|
||||||
static job_requeue_t receive_arp(private_farp_spoofer_t *this)
|
static bool receive_arp(private_farp_spoofer_t *this)
|
||||||
{
|
{
|
||||||
struct sockaddr_ll addr;
|
struct sockaddr_ll addr;
|
||||||
socklen_t addr_len = sizeof(addr);
|
socklen_t addr_len = sizeof(addr);
|
||||||
arp_t arp;
|
arp_t arp;
|
||||||
int oldstate;
|
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
host_t *local, *remote;
|
host_t *local, *remote;
|
||||||
|
|
||||||
oldstate = thread_cancelability(TRUE);
|
len = recvfrom(this->skt, &arp, sizeof(arp), MSG_DONTWAIT,
|
||||||
len = recvfrom(this->skt, &arp, sizeof(arp), 0,
|
|
||||||
(struct sockaddr*)&addr, &addr_len);
|
(struct sockaddr*)&addr, &addr_len);
|
||||||
thread_cancelability(oldstate);
|
|
||||||
|
|
||||||
if (len == sizeof(arp))
|
if (len == sizeof(arp))
|
||||||
{
|
{
|
||||||
local = host_create_from_chunk(AF_INET,
|
local = host_create_from_chunk(AF_INET,
|
||||||
@@ -124,12 +120,13 @@ static job_requeue_t receive_arp(private_farp_spoofer_t *this)
|
|||||||
remote->destroy(remote);
|
remote->destroy(remote);
|
||||||
}
|
}
|
||||||
|
|
||||||
return JOB_REQUEUE_DIRECT;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(farp_spoofer_t, destroy, void,
|
METHOD(farp_spoofer_t, destroy, void,
|
||||||
private_farp_spoofer_t *this)
|
private_farp_spoofer_t *this)
|
||||||
{
|
{
|
||||||
|
lib->watcher->remove(lib->watcher, this->skt);
|
||||||
close(this->skt);
|
close(this->skt);
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
@@ -183,10 +180,8 @@ farp_spoofer_t *farp_spoofer_create(farp_listener_t *listener)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
lib->processor->queue_job(lib->processor,
|
lib->watcher->add(lib->watcher, this->skt, WATCHER_READ,
|
||||||
(job_t*)callback_job_create_with_prio((callback_job_cb_t)receive_arp,
|
(watcher_cb_t)receive_arp, this);
|
||||||
this, NULL, (callback_job_cancel_t)return_false, JOB_PRIO_CRITICAL));
|
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user