How to do raw Ethernet under Win32?

G

Grant Edwards

How does one do raw Ethernet under Win32? Ultimately, I want
to do it in a Python program, but if somebody can point me to a
clue on how to do it from C, I could probably figure out the
rest.

I want to:

1) Send an arbitrary Ethernet packet. [Well, not completely
arbitrary, the source MAC will be "right", but the protocol
number is a proprietary (not IP) one, and the packet isn't
anything standard.

2) Receive any incoming packets with a specified protocl
number -- same proto number as in 1) above.

I've got a program that works under Linux, and I'd like to be
able to port it to Win32...
 
G

Grant Edwards

How does one do raw Ethernet under Win32? Ultimately, I want
to do it in a Python program, but if somebody can point me to a
clue on how to do it from C, I could probably figure out the
rest.

It looks like I can _almost_ do what I want with the python
wrapper around the windows pcap lib. WinPcap has a
sendpacket() funcation which doesn't seem to be made visible by
the Windows version of pylibpcap, so that's something I'll have
to look into.

It's probably not the optimal way to receive packets, but I
only have to do a few.
 
L

Leopold Faschalek

Grant Edwards said:
How does one do raw Ethernet under Win32? Ultimately, I want
to do it in a Python program, but if somebody can point me to a
clue on how to do it from C, I could probably figure out the
rest.

I want to:

1) Send an arbitrary Ethernet packet. [Well, not completely
arbitrary, the source MAC will be "right", but the protocol
number is a proprietary (not IP) one, and the packet isn't
anything standard.

2) Receive any incoming packets with a specified protocl
number -- same proto number as in 1) above.

I've got a program that works under Linux, and I'd like to be
able to port it to Win32...

the new winsock2.h supports more socket types:
/*
* Types
*/
#define SOCK_STREAM 1 /* stream socket */
#define SOCK_DGRAM 2 /* datagram socket */
#define SOCK_RAW 3 /* raw-protocol interface */
#define SOCK_RDM 4 /* reliably-delivered message */
#define SOCK_SEQPACKET 5 /* sequenced packet stream */

so you have only to define 3 as type in the socket() call

greetings
Leopold Faschalek
 
G

Grant Edwards

the new winsock2.h supports more socket types:
/*
* Types
*/
#define SOCK_STREAM 1 /* stream socket */
#define SOCK_DGRAM 2 /* datagram socket */
#define SOCK_RAW 3 /* raw-protocol interface */
#define SOCK_RDM 4 /* reliably-delivered message */
#define SOCK_SEQPACKET 5 /* sequenced packet stream */

so you have only to define 3 as type in the socket() call

I've seen vague references to this in some FAQs but could never
find out if it actually worked or how to specified what
Ethernet protocol you wanted to receive on the socket.
 
G

Grant Edwards

The guy you got this from used MINGW, the free GNU compiler for Windows
to do the original port:

http://mingw.sourceforge.net/

:)

Cool! Be sure to thank him for the work if you see him.

I've never done any SWIG stuff before, but it looks like all I
have to do is add some stuff to the .i file to export the
pcap_sendpacket() function.
 
?

=?ISO-8859-1?Q?Gerhard_H=E4ring?=

Grant said:
I've never done any SWIG stuff before, but it looks like all I
have to do is add some stuff to the .i file to export the
pcap_sendpacket() function.

I haven't done any SWIG work, either (apart from unsuccessful tries at
adding something to wxPython once). Instead I directly hacked the SWIG
generated C code, so my patch is little but a quick hack.

It's also some time ago and I never used the thing myself, so don't ask
me about details :)

-- Gerhard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top