low-level C++, please direct me.

Hi,
i want to use the network adapter in a low level way using a c++ program.
i mean:
i want to specify an exact message to be sent via that adapter, and monitor it for messages, but like in really low level, i want to simulate a networking protocol myself, not just use a black box that implements a protocol and provide an interface for using it.
i think a solution might be in streams:
maybe i can connect a file stream to the network adapter, then insert data into it, simply like:
1
2
fstream netowrk_out(/*some address*/);
network_out<<0xcc;

i don't know if this would work, that's why i'm asking:
please direct me to the proper way of achieving this goal.

i hope i was clear enough.
Last edited on
i think that in OS the lowest you can get is application layer (considering OSI model) like BSD sockets. Going any lower would require to write custom drivers for your ethernet card and that still would be maybe up to network layer max.

How low would you like to go? TCP/IP protocol? or even lower?
I fear, Rechard3 you will have to write a device driver or a filter driver on top of one already in place. You need I/O permissions granted by executive to write to a HW port. If you find a simpler way, please tell me. Have the impression that since Vista Microsoft provides a Device Driver framework that makes, they claim, the whole thing easier that it was before. It could be considered not difficult rather painful like any function controlling hardware can be. I never tried the framework myself.
i don't know how much down i should go in OSI.

let me explain a bit more:
one day i read in this forum that someone wants to make a port scanner.
he used a library to achieve this goal:
"try to connect to the port, if didn't connect, then the port is closed."
he said.
this operation might take relatively long time.
if i want to make a port scanner, i'd go in another approach:
i'd send the connect request, and rather than complete the protocol, i'd send other connect requests, while another thread in my program shall monitor for replies.
this way you can scan so many ports in a short time.
this approach requires that i don't use a premade function to connect to a port, but to send a specific binary message of my desire.
maybe this won't work for this specific example, but you can imagine the domain i can use this technique in.

i don't need a function to complete a connection protocol for me, i want to write this function.

this is how low i need to get, can this be done in native C++, if not, is there some library that contains basic communication functions ( sendMessage(char*), ...etc).

i'm learning right now about OpenGL, it looks like the VGA driver implements it, doesn't the network adapter definition implement some similar API ??

PS: i'm a beginner, but i'm ready to put effort in learning.
closed account (Dy7SLyTq)
i know linux has termios.h
Sorry for the misunderstanding, I had taken port as a hardware port (because Rechard3 referred to network adapter) instead of a TCP port.
@Auribau
i'm still a beginner, i can make mistakes :)
@Rechard3
I don't think this being an actual mistake. It's simply that we made assumptions we didn't verified before asserting. Very usual in our work. It happens to me as well.
thanks everyone, your contributions are much appreciated.

maybe i should take a look at that socket stuff.
it'd be helpful if someone mentions a good networking library, and even better if you include a tutorial as-well.

again thanks.
SDL & SFML have a good one. Winsock is good too if you're a windows-only kind of guy.
Last edited on by Fredbill30
Topic archived. No new replies allowed.