c++ - Raw ICMP WInsock, asynchronous I/O -


i'm doing program permit me ping lot of different ips simultaneously (around 50-70).

i need delay sending of each packet 1 ms, multiple reasons, notably not getting packets dropped routers drop icmp packets when there's sent @ once (which mine does, on sending machine, not receiving one).

so did in separate thread bit :

// send thread (;;) {    [...]    (int = 0; < ip_count; i++)    {       // send() calls sendto()       send(m_socket, ip_array[i]);       [...]       sleep(1); // delay 1 ms    }    [...]    lock_until_new_send_operation(); } 

and in thread, thread receive packets select(), that

// receive thread fd_zero(&m_fdset_read); fd_set(m_socket, &m_fdset_read); int rds_count = select(0, &m_fdset_read, 0, 0, &tvtimeout); if (rds_count > 0)     processreadysocket(); // calls recv() , stuff else {     // timed out     m_bsendgrapedone = true; } 

the problem approach since both calls select() , sento() use same non-blocking socket m_socket, calls sendto() later block because select() makes sendto() block when both called simultaneously (for strange reason... dont see such logic there, since socket non blocking, still does, ugly).

so decided use 1 socket exclusively sending , replaced line

send(m_socket, ip_array[i]); 

with

send(m_sendsock, ip_array[i]); // m_sendsock dedicated sending 

i read on msdn raw sockets each socket receives packets protocol socket set (mine ipproto_icmp ofc). here quote :

there further limitations applications use socket of type sock_raw. example, applications listening specific protocol receive packets received protocol

so thought though packets sent m_sendsock, still receive them using select()/recv() on m_socket, turns out can't, select() never returns socket readable. i'm kind of stuck, cannot use select() , send() @ same time. there i'm doing wrong?

(by way want use raw sockets, not builtin windows icmp functions)

tl;dr how can send() , select() simultaneously? because on send thread, send() blocks select() gets called on receive thread, if used fionbio on (non blocking). if use 2 different sockets, 1 sending , 1 destined receive, receive nothing on receiving socket...

thanks!


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -