The need for connect/listen on raw sockets?

Sage
Posts: 1,403
Joined: 2005.07
Post: #16
'SYN's can be blindly spoofed'
what the heck are you doing, and does this work on mac os x?

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 277
Joined: 2004.10
Post: #17
Steven Wrote:BinarySpike: Have you tried using something like Ethereal (now WireShark?)

It can be invaluable to see both if the packet actually gets on the wire and then it will show you how it interprets the packet (so you can see if it is valid)

Just tried, I put it on lo0 using MacSniffer, whenever I tried "sudo ./throw" stuff appeared, but when I did "sudo -s" and then tried nothing appeared, so simply speaking, localhost packets are being sent when I sudo, and ./throw isn't throwing anything...

Zekaric Wrote:I don't know if this will help any. In the past we've been bitten by this at work. Structures may not be as compact as you have declared them. There may be padding inside that allows the values to be aligned on byte boundaries. This may be an issue if you are sending the raw structure over the wire and the other end is expecting a certain values at certain byte locations other than byte boundaries.

Just in case, you might want to look for a #pragma pack() sort of preprocessor command that will ensure the byte ordering of the structures.

This is on top of making sure the values are in network order because everything inbetween the send and recieve (OS, Internet) is expecting network order. But then OSC has pretty much berrated you on that point.

I see, I revised my code to to put *all* unsigned shorts and longs in correct order, I didn't know what to do about the 4 bit variables, or the chars (cause the chars and one byte they shouldn't be ordered specially...)

unknown Wrote:'SYN's can be blindly spoofed'
what the heck are you doing, and does this work on mac os x?

Idk what a SYN is... but that was left over from some code I grabbed...
(which I based this version off of)

I'm gonna go checkout SDL

Global warming is caused by hobos and mooses
Quote this message in a reply
Member
Posts: 277
Joined: 2004.10
Post: #18
*edit*
PowerPC runs big endian *and* little endian... idk how exactly this all fits together but that is what the source said (aka, OSC was right)

MacSniffer running off lo0 saw the packets just fine without the DONTROUTE setting.
(Go MacSniffer!)
*/edit*


Success!

I looked up the SYN spoofing thing... kinda scary Sad

So anyway, I found a great resource (old e-mail to a linux community) and finally figured out the headers required to work it all, but the major thing that both I and the old e-mail had in common, is that they didn't work till we added the bind function.

I also found the IP headers... for future reference here's a list of headers and why they are required.
Code:
#include <stdlib.h>
#include <stdio.h>
// required for sys/socket.h and sys/types.h

#include <sys/socket.h>
#include <sys/types.h>
// the main socket headers dupid silly person!

#include <netinet/in_systm.h> // defines n_long for netinet/ip.h
#include <netinet/in.h> // defines IPPROTO_IP and IP_HDRINCL IIRC
#include <netinet/ip.h> // defines struct ip (mac) for IP headers
// note some resources use iphdr, you could always typedef struct iphdr to struct ip for portability

I haven't tested the headers netinet/tcp.h or netinet/udp.h
tcp.h should have the TCP header struct and udp.h should have the UDP header struct... I have not tested to see what other headers they require...

on mac you only need include libstdc++

Please note this is as of 10.2.8, dev tools... I haven't upgraded any of my netinet so far, if I find source code to update my sockets stuff I would gladly upgrade Smile

Global warming is caused by hobos and mooses
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #19
Just FYI, the G4 has a little endian mode, but the G5 does not. (that's the main reason why VirtualPC took so long to port to the G5)
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #20
As akb825 nearly says, little-endian mode was an optional feature of PowerPC processors, could only be switched to by a privileged process, and wasn't quite full-featured, IIRC -- some instructions weren't available in little-endian mode or something. G3s and G4s had it, G5s didn't.

IOW, you can basically ignore the idea that PowerPCs are little-endian. For all intents and purposes, they're always big-endian.
Quote this message in a reply
Member
Posts: 277
Joined: 2004.10
Post: #21
Ok thanks...

I tried to get my program working on different ports... it only runs on port 0, any other port fails at bind...
Btw this is with and without the UDP header (I've gotten it to work)

anybody know why it would do this?

Global warming is caused by hobos and mooses
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #22
you need root to bind to ports <= 1024

Just use UDP and TCP you can bind them to any port (in my experience), dont use RAW sockets.
Unless you have a specific need for RAW sockets which I would be interested to hear if you did.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 277
Joined: 2004.10
Post: #23
You need root to use RAW Sockets, so it doesn't matter I would suppose what port you used.
(At least you can't set IP_HDRINCL without being root)

My UDP header seems to be working, but bind doesn't even see the headers, only sendto does...

*edit*
I have several needs for RAW sockets, raw sockets improve on memory usage, while increase CPU usage, so theirs a gain for using raw sockets or not...

Only port 0 binds, I've tried 5555, 3333, 20000 and 1000
all while under root (sudo -s)

I'm gonna try to see if they send out without binding (or at least not exit when binding fails)

Global warming is caused by hobos and mooses
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #24
Correct me if I'm wrong, but isn't the port a property of the TCP or UDP packet? (Ex: port makes no sense on an ICMP packet?)

Therefore, binding to a specific port on a raw socket makes no sense?

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #25
To be honest I think you should just save yourself a huge amount of bother and use TCP/UDP instead of IP. There is really no advantage to filling in your own TCP headers in any normal situation.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #26
Raw sockets are *only* useful for implementing things like ICMP pingers and port scanners. If you're fighting with them out of some misplaced idea that you can somehow write a better UDP stack than Apple it's time to get realistic Rasp

Of course, if you're just messing with them because you think they're cool and want to know how they work, fine Smile
Quote this message in a reply
Member
Posts: 277
Joined: 2004.10
Post: #27
OneSadCookie Wrote:Raw sockets are *only* useful for implementing things like ICMP pingers and port scanners. If you're fighting with them out of some misplaced idea that you can somehow write a better UDP stack than Apple it's time to get realistic Rasp

Of course, if you're just messing with them because you think they're cool and want to know how they work, fine Smile

Exactly Smile
No use using something I don't know how it works Wacko

for example, I had no clue why connect, listen, or accept were required... it was just soooo complicated, then I learned it's part of the proccess of getting a connection and requires many behind the scenes packets.


Steven Wrote:Correct me if I'm wrong, but isn't the port a property of the TCP or UDP packet? (Ex: port makes no sense on an ICMP packet?)

Therefore, binding to a specific port on a raw socket makes no sense?

That's the problem if I didn't bind the packets, it wouldn't work Sad
sendto would not register in either en0 or lo0 on tcpdump (I'm using MacSniffer)

Unknown Wrote:To be honest I think you should just save yourself a huge amount of bother and use TCP/UDP instead of IP. There is really no advantage to filling in your own TCP headers in any normal situation.

I understand that, and I would rather use something like HawkNL or raknet to run my networking (or SDL_net). I'm making this a requirement of myself to run a working raw sockets program.

I re-wrote everything from scratch, this *should* work... but it doesn't...
I'm not pressing anybody to take a look, but I will say, it's super organized...
http://pastebin.ca/209566

Thanks Cool
BinarySpike

Global warming is caused by hobos and mooses
Quote this message in a reply
Member
Posts: 116
Joined: 2002.04
Post: #28
Quote:for example, I had no clue why connect, listen, or accept were required... it was just soooo complicated, then I learned it's part of the proccess of getting a connection and requires many behind the scenes packets.

If you don't understand the purpose of listen, connect and accept, your chances of understanding it by writing raw sockets code is slim. That's like not understanding how a C if statement works, and learning assembler to find out.

Go get a good basic network programming book. Get several. Study the code of others.

But really they're not that complex:

Listen: listens for incoming connections
Connect: attempts a connection
Accept: accepts an incoming connection
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #29
I'm thinking he meant when he began with sockets, not now.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Connect to Server from Iphone BugSniper 6 9,478 Jul 15, 2009 04:57 PM
Last Post: BugSniper
  Cocoa/Objective-C and TCP Sockets... TimMcD 2 6,199 Jun 13, 2009 06:15 PM
Last Post: TimMcD
  Server/database interaction in C++ using sockets wyrmmage 2 5,263 Jan 20, 2007 02:17 PM
Last Post: wyrmmage
  Using threads to set a timeout on a connect() call SOUR-Monkey 6 7,583 Feb 13, 2005 09:59 PM
Last Post: ggadwa