Can I write Ethernet-based networking programs in C ++?

I would like to write a program and run it on two machines and send some data from one computer to another in an Ethernet frame.

Typically, these applications are at the OSI model level 7, is there something like a kernel restriction or an API restriction that will prevent me from writing a program in which I can specify the destination MAC address, and some data sent to this MAC as an Ethernet payload? Then write a program to listen to incoming frames and capture frames from the specified source MAC address, extracting the data payload from the frame?

(Therefore, I do not need other overhead, such as IP or TCP / UDP headers, I do not want to go above level 2).

Can this be done in C ++ or all communications take place at the IP level, and can this be done on Ubuntu? Extra love for pointing or providing examples !: D

My problem, obviously, I am new to network programming in C ++, and as far as I know, if I want to communicate over the network, I have to use a call socket()or similar that works at the IP level, so I can write a C ++ program for works at the OSI 2 level, are there APIs for this, does this Linux kernel even allow this?

+5
source share
2 answers

As you mentioned sockets, maybe you just need to use a raw socket. Perhaps this page with sample C code might help.


, Ethernet, :

. , , UDP- ( , .., ).


. ,

  • root
  • root setuid
  • raw- setcap CAP_NET_RAW+ep /path/to/your/program-file

( , ..), . , "" 2.6.24 ( Ubuntu 8.04).

+7

All Articles