Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: CupHead on October 14, 2003, 12:40 PM

Title: Raw Sockets
Post by: CupHead on October 14, 2003, 12:40 PM
I've been trying to create a raw socket example and have run across several problems in doing so.  The steps I followed are:

Create a raw socket (SOCK_RAW)
Set the socket options to IP_HDRINCL.
Create the IP and TCP headers.
Use sendto() to send the packet.

sendto() returns sizeof ( ipheader ) + sizeof ( tcpheader ), as it should [I think], as there is no data other than the two headers.  However, in monitoring the system (I'm sending the packet back to myself), I don't ever receive it.  None of the calls ever fail, so I assume there must be something else wrong.  Ideas, anyone?
Title: Re:Raw Sockets
Post by: Banana fanna fo fanna on October 14, 2003, 09:04 PM
Are you on windows? If so, are you administrator?
Title: Re:Raw Sockets
Post by: CupHead on October 14, 2003, 09:46 PM
Yes and yes.
Title: Re:Raw Sockets
Post by: Banana fanna fo fanna on October 14, 2003, 10:29 PM
In that case, I'm out of ideas :P
Title: Re:Raw Sockets
Post by: Grok on October 14, 2003, 10:46 PM
Run network monitor and see what's actually happening?
Title: Re:Raw Sockets
Post by: Banana fanna fo fanna on October 14, 2003, 10:49 PM
Errr....don't you have to specify the destination address in the header?? I don't think sendto will do it for you but I may be mistaken.

Also...what's the deal with SOCK_RD?
Title: Re:Raw Sockets
Post by: CupHead on October 15, 2003, 07:23 AM
Grok: sendto() returns success, but no monitoring tools that I've used have actually seen the packet be sent or received.
Title: Re:Raw Sockets
Post by: Arta on October 15, 2003, 08:30 AM
Well, that sounds like a problem with your capture tool.
Title: Re:Raw Sockets
Post by: Skywing on October 15, 2003, 08:47 AM
Quote from: CupHead on October 15, 2003, 07:23 AM
Grok: sendto() returns success, but no monitoring tools that I've used have actually seen the packet be sent or received.
Perhaps you are sending it to your own address?  Most network monitoring tools don't see traffic that doesn't reach the NIC, such as purely local sockets traffic.
Title: Re:Raw Sockets
Post by: CupHead on October 15, 2003, 11:22 AM
It is being sent back to localhost.  I guess I could try it from a different computer.
Title: Re:Raw Sockets
Post by: Grok on October 15, 2003, 11:44 AM
CupHead since you're probably on some NT variant, you might want to just add some IPs to your current adapter, or add an additional adapter.  Under NT you could add an MS Loopback Adapter.  I don't know if such an option is available under Win2000 or XP.  However, XP supports an alternate configuration for your networking.  In this way you can use DHCP for your ISP, and a fixed, local range IP for your programming.  A third option would be to install an additional adapter and configure it with private range IPs.

In any of those configurations, be sure to explicitly bind your client and server applications to different IPs.
Title: Re:Raw Sockets
Post by: Adron on October 15, 2003, 05:37 PM
And even then you might not see anything that's not routed through the real network cards. If it goes through the loopback adapter I'm not sure you'll ever see it. Send it to an internet host!
Title: Re:Raw Sockets
Post by: -Death- on October 15, 2003, 07:36 PM
What Windows are u running off of??

Win 95
Win 98
Win 2000
Win ME
Win XP Home, or Proffesional.

????????

Each system has different for solving there problems.
Title: Re:Raw Sockets
Post by: CupHead on October 15, 2003, 08:33 PM
Um...  Windows Server 2003 Enterprise Edition, not that it matters.  It's essentially XP, and I've used the most updated information I can find on the subject.
Title: Re:Raw Sockets
Post by: -Death- on October 16, 2003, 04:55 PM
Hmm...

You lost me. I am totally confused. Sorry, I can't help.

Best of Luck.