Hello. I wish to write a bootable program in assembler that would be capable of sending and receiving network packets. I do not wish to use any libraries, I'd like to create it all by myself (and also learn while doing so). Unfortunately, I was unable to find any information regarding communication with the network card on the lowest level (sending raw sockets). I believe it's necessary to use OUT
and IN
instructions, although I couldn't find any information about the port that is assigned to the network card (or how to find it, if it's not always the same). Could anybody point me in the right direction? ;-)
views:
64answers:
2Different network cards have different hardware interfaces (which is why they have different device drivers).
You might get information about the hardware from the device manufacturer (or you might not: they might regard that as proprietary information, and write their own device drivers).
You might also get that information by looking at the source code of open source network cards: for example, I'd guess, for Linux; or, perhaps, the Crynwr packet drivers.
This is quite a large problem to solve. Even getting to the point of "raw sockets" is going to be quite a bit of work.
First, with a modern BIOS, your network card won't normally be configured by default, so you'll need to deal with PCI configuration to configure it to have some ports that are visible to the processor. This will give you the basic capability of getting the CPU to actually talk to the network card.
Second, you'll have to find some documentation on the particular chipset it happens to use so you'll know how to read and write network data. With some older cards this was pretty easy, but most newer ones act as bus masters with scatter/gather hardware. Programming them to do even a simple transfer can be non-trivial. This depends completely on the hardware though.
Third, you'll need to develop a substantial part of an IP stack to be able to use even raw sockets. At the hardware level, you basically have two capabilities: receive whatever packets happen to arrive, and send packets to specified MAC addresses -- or other hardware addresses, if your card isn't (and doesn't look/act like) Ethernet.
The next couple of layers on top of that would be an ARP resolver (to let you use IP addresses instead of MAC addresses) and a DNS client (so you can use normal address names instead of something like dotted quads. Along with that, you'll probably want to build software that knows how to create/understand IP datagrams.