J
jeffburgoon
I'm having a problem opening a socket and receiving a response from a
different IP/port than what I'm sending to. Here is what I'm trying to
do:
Open Socket with IP/Port (A,B)
Send to location with IP/Port (C,D)
Immediately receive response on IP/Port (A,B) from IP/Port (X,Y), or
any IP/Port other than (C,D)
My problem is that in order for me to send to (C,D) I have to create
the socket with peer address/port (C,D), so only responses from (C,D)
are allowed. I have tried setting up the socket to use (C,D), then
tearing it down and recreating it with no peer IP/port specified but I
think this is too slow, as the response comes back almost immediately
and is missed by the recv() function. Here is what I'm trying:
$socket=new IO::Socket::INET->new(PeerPort=>$dst_port_num
,Proto=>$'udp'
,PeerAddr=>$dst_addr_str
,LocalPort=>5060
,Reuse=>1);
$socket->send($packet_text);
close($socket);
$socket->recv($response,1024);
close($socket);
The above code works as long as the response comes back from ip/port
($dst_addr_str, $dst_port_num). If a packet is received from a
different IP or port, it is ignored as the socket is only listening on
that pair. I have tried adding in the code to recreate the socket but
it appears to be too slow as the response is never received. Here is
what I add in, directly above the recv() line in the above code:
$socket=new IO::Socket::INET->new(Proto=>$protocol_str
,LocalPort=>5060);
I'm thinking what I need is to either
A) Allocate a socket with no remote port/ip and instead specify port/ip
in send()
or
B) Change peer IP/port to nothing on the fly immediately after sending
packet.
Any help would be greatly appreciated.
different IP/port than what I'm sending to. Here is what I'm trying to
do:
Open Socket with IP/Port (A,B)
Send to location with IP/Port (C,D)
Immediately receive response on IP/Port (A,B) from IP/Port (X,Y), or
any IP/Port other than (C,D)
My problem is that in order for me to send to (C,D) I have to create
the socket with peer address/port (C,D), so only responses from (C,D)
are allowed. I have tried setting up the socket to use (C,D), then
tearing it down and recreating it with no peer IP/port specified but I
think this is too slow, as the response comes back almost immediately
and is missed by the recv() function. Here is what I'm trying:
$socket=new IO::Socket::INET->new(PeerPort=>$dst_port_num
,Proto=>$'udp'
,PeerAddr=>$dst_addr_str
,LocalPort=>5060
,Reuse=>1);
$socket->send($packet_text);
close($socket);
$socket->recv($response,1024);
close($socket);
The above code works as long as the response comes back from ip/port
($dst_addr_str, $dst_port_num). If a packet is received from a
different IP or port, it is ignored as the socket is only listening on
that pair. I have tried adding in the code to recreate the socket but
it appears to be too slow as the response is never received. Here is
what I add in, directly above the recv() line in the above code:
$socket=new IO::Socket::INET->new(Proto=>$protocol_str
,LocalPort=>5060);
I'm thinking what I need is to either
A) Allocate a socket with no remote port/ip and instead specify port/ip
in send()
or
B) Change peer IP/port to nothing on the fly immediately after sending
packet.
Any help would be greatly appreciated.