Click to See Complete Forum and Search --> : One socket two protocols


mikescham
August 6th, 2002, 08:55 AM
Anyone know of a way to get one socket to send on one protocol, for instance UDP, and receive on another protocol like ICMP.

If that's not possible then how about a way to use two sockets with different protocol types that share the same localendpoint???

jparsons
August 6th, 2002, 10:09 AM
Originally posted by mikescham
Anyone know of a way to get one socket to send on one protocol, for instance UDP, and receive on another protocol like ICMP.

If that's not possible then how about a way to use two sockets with different protocol types that share the same localendpoint???

You can't mix protocols on a single socket. I beliebe that it is possible to have two sockets listen on two sockets on the same local end point though. Not entirely positive.

Either way you shouldn't have a problem mixing and matching ICMP and UDP. UDP and ICMP can never have the same local end point. UDP end point is defined by an IP address and a port. ICMP just goes to a host.

mikescham
August 6th, 2002, 02:32 PM
Thanks again for your reply.

I haven't had much experience with sockets. The msdn documentation isn't too clear about mixing and matching different socket options, endpoints etc...

I tried the following

(i don't remember the params clearly)
Socket UdpSock = new Socket(Internetwork, Raw, Udp);
Socket IcmpSock = new Socket(Internetwork, Raw, Icmp);

UdpSock.SendTo(packet_with_bad_port_number, length, socketflags.none, endpoint);

IcmpSock.Bind(UdpSock.LocalEndPoint);
IcmpSock.ReceiveFrom(buffer, length, socketflags.none, ref tempEP);

But the Icmp sock times out on the receive. According to my packet sniffer though I am getting a Destination Port Unreachable ICMP error back from the target.

I finally switched the code to just use Icmp and it works fine but I kind of want to keep experimenting with mixing the protocols around.

mikescham
August 6th, 2002, 11:50 PM
Thanks again. I tried once more with two sockets - different protocols and it worked!

This time I created a seperate local endpoint for the icmp socket using the local ip and a port of 0.

Anyway, thanks for the pointers.

jparsons
August 7th, 2002, 02:29 AM
Originally posted by mikescham
Thanks again. I tried once more with two sockets - different protocols and it worked!

This time I created a seperate local endpoint for the icmp socket using the local ip and a port of 0.

Anyway, thanks for the pointers.

I think this goes back to the idea that ICMP doesn't have a port. Haven't really played around with ICMP though.