Posted: Thu Apr 26, 2007 7:06 pm
It actually all starts at the frame level or also called the data-link layer.so i could just set the IP to anything and packets would just make it to my emulated OS somehow ?
The little electrical pulses are translated into a string of eight bit values. The first six are the destination media access control address. The next six are the source media access control address. Then comes two more bytes which are used for encapsulation.
You know six bytes in hex look something like:
00:03:45:FE:0A:99
Every network card has a built-in media access control address or also called a "MAC" address. Normally the card will only receive frames that have the first six bytes matching their internal MAC address. Any other packet is always ignored. A exception is that they will also listen for a MAC address of ff:ff:ff:ff:ff:ff which is considered a broadcast address.
No two network cards in the entire world should ever have the same media access control address or MAC. If you researched it you might have a screw up by a company somewhere in the past years where somehow two cards did get the same address. This is not intended to happen just note for you.
You will have to look up some documentation on how to read the MAC from the network card to find out what it is. You may also in some network cards or at least all modern ones change the MAC address if you like.
hint: You will talk to the network card with MMIO and I/O instructions like: in, and out.
What happens in a emulated state is that QEMU or BOCHS will open you're network adapter or all adapters in promiscuous mode in Windows Or Linux depending on which or what you are using. In a normal situation like (above) only listen to frames that have the first six bytes matching their own internal address or have all binary ones which make the ff:ff:ff:ff:ff:ff address. However, in promiscuous mode the network card will ignore nothing and instead listen to every frame regardless of the destination address (or the first six bytes). The kernel will normally do extra filtering in the event that a program turns on the promiscuous mode for a network card, but will still provide all the frames in a unfiltered manner.
This is what QEMU and BOCHS depend on. They will listen on the network adapter in promiscuous mode. This will work on Windows and Linux. QEMU and BOCHS will listen for packets matching their emulated network card's MAC address and once found will do the magic of emulating the network card you're emulated kernel is listening for as being received.
QEMU and BOCHS should also emulate their own network cards being in promiscuous mode. Where they will emulate frames straight from the Linux or Windows kernel into the virtual computer where you kernel is running.
The network card knows nothing and does not care anything about a IP address. It has absolutely no idea what a IP address is.
You could actually test receiving packets by starting you're kernel in QEMU or BOCHS and letting it initialize the network card and wait for packets then:
- if you are using Linux or Windows.
Find you're IP address.
Change the last number of you're IP address to another number.
Then ping this new ip address.
If everything goes okay. You're network card will receive a frame. This frame will have the first six bytes of ff:ff:ff:ff:ff:ff. This is the broadcast address and if you want to further study it you will need to google for "arp header".
What you are doing is trying to use a IP address on you're local subnet. One in which does not get forwarded to you're gateway (or entrance onto the internet). You also need a IP address that Windows Or Linux has never seen which will cause them to generate a ARP packet with a broadcast destination MAC address. The computer owning the IP address will normaly respond with a ARP reply.
Just imagine trying to send information to a certain IP address and not knowing the six byte media access control address. How could you send it if any network card will ignore any frame that does not match it's own?
That is what ARP is for and the MAC broadcast.