views:

64

answers:

2

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? ;-)

+1  A: 

Different 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.

ChrisW
So are you saying that all operating systems that do not require drivers installed for a network card already have all drivers of all existing network cards?
Neo_b
There are a lot of these drivers; e.g. 20 pages of Intel drivers at http://drivers.softpedia.com/get/NETWORK-CARD/INTEL/
ChrisW
I bought my copy of Windows preinstalled when I bought this computer. The computer manufacturer ("OEM"), who installed the O/S, knew what kind of network card they had put in this machine, and was therefore able to install the right driver.
ChrisW
Otherwise, if you buy a network card as an aftermarket add-on, then I think you'll find included in its box the card-specific device drivers for various O/Ses.
ChrisW
There are some "generic" APIs, more or less old (and possibly obsolete now), which may or may not be supported by any given card: e.g. [NE2000](http://en.wikipedia.org/wiki/NE2000).
ChrisW
+1  A: 

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.

Jerry Coffin