0

From my understanding, the ethernet drivers are where the rubber hits the road in terms of sending data over the network. It is where the CPU transfers bits to hardware which somehow goes over the network.

The question is how you do this at the lowest level possible, i.e. without using a unix command like netcat or something equivalent in C.

From what it sounds like, the ethernet "network card" is a piece of hardware with highly varied implementations. So each version of a MacBook might have a different network card, not to mention each PC version. So it sounds like there could be thousands of different network card implementations. Which is why the operating system like Linux has the "driver" abstraction. The driver is created by the hardware manufacturer so that it fits the ~specification~ Linux has for I'm guessing a "socket", but not sure. Please correct me if I'm wrong.

So what I'm wondering is, how I find out on my Mac how to directly connect to an ethernet driver (at the lowest-level possible), so I can then figure out how to send 1 bit into the network (not going to ask about where to send in the network, because that is probably a further complicated question).

Lance
  • 75,200
  • 93
  • 289
  • 503
  • 2
    `lspci` to scan the PCI / PCIe bus, then look up specs for the ethernet device that appears. Or look at `dmesg` output to see what driver Linux picked. There are probably at most a dozen different NIC models that have been used in recent MacBooks, with many of them sharing the same driver interface. So probably only a handful of different drivers are needed to cover any MacBook for the last few years, in case that matters at all. Obviously your MacBook will only have one. – Peter Cordes Jul 22 '18 at 22:54
  • 4
    There is a problem with sending "_1 bit into the network_." Many NICs cannot do that. For example, the IEEE network LAN protocols, e.g. ethernet, Wi-Fi, etc., must have frame headers, and the hardware plays a big part in that. Serial NICs using non-IEEE protocols, e.g. PPP, HDLC, etc., may be able to send single bits. – Ron Maupin Jul 22 '18 at 22:57
  • 2
    There arent as many vendors as you think and their implementations tend to recycle logic/register sets. Sending one bit is not a thing needs to be a packet, the mac address itself is longer than that, 64 bytes is the typical minimum packet but there are ways to send less. lspci, as mentioned is where you start, then from there simply get the linux or bsd sources and look them up. Vendors documentation if possible but for example broadcom one of the primary vendors, docs are generally not available, period. so you work from the open source drivers. – old_timer Jul 22 '18 at 23:09
  • Its not brain surgery, get the RFCs, start with the old ones that are marked obsolete, the current RFCs assume you have had that history so start with the older classic ones. which ones are they, part of the fun. good book or set is TCP/IP illustrated, all info that can be had for free, but nice to have bound up, looks like you can get one at barnes n noble for $2.99. Probably some pdfs floating around. – old_timer Jul 22 '18 at 23:12
  • At the end of the day it sounds like you are going down the wrong path or misunderstanding the path based on your question. Most of the work is getting at the hardware, are you making your own operating system, independent of the hardware what was your plan for accessing hardware directly? What is it that you are after the protocols or talking to some piece of hardware, choose one project at a time. – old_timer Jul 22 '18 at 23:14
  • If it is networking protocols the start with sockets, relative to the rest of the work the sockets interface is somewhat trivial but gets your feet wet on the details you will need later down the road. Also tools like tcpdump and wireshark. You can then attack this at the somewhat common network abstraction layer, network drivers for an operating system (linux, bsd, I would assume, likely others). you can start with pcap, before moving lower. – old_timer Jul 22 '18 at 23:18
  • DOS is not dead, if you own a PC with an x86 in it, DOS was used both in the development of that motherboard and in the testing. The crynwr drivers were a nice abstraction layer for gaining access to raw network packets, you could then take the RFCs and start to pull apart the packets and start to understand them. The linux driver layer is not much different and may have been the same person initially, one or both if you can get hardware or get access is a good way to get at the lower at least mac layer. – old_timer Jul 22 '18 at 23:20
  • then its just some ram and control registers. network cards vary but there is some ram in a circular buffer or some sort of way to hold some number of packets on board/chip then you extract them and its on you to parse, etc. Some can do the checksum checks for you some cant or wont, some can filter your ip address, some wont, these days with virtual machines one would expect all to come through. so you would need to then poke at some registers and read some buffers, receiving packets is easier at first than sending, just sniff packets like wireshark does, half the job is done. then TX. – old_timer Jul 22 '18 at 23:22
  • getting your operating system to let go of a known network card is a trick thus just using PCAP or other similar solutions. You can instead get a microcontroller board with a network interface on it, Like the cortex-m7 NUCLEO boards for example. Or the connected ti launchpad(s). With something like that you wont have the operating system in the way. Raspberry pi is a bad idea, the network is on usb, and that is a lot of baremetal to get through even for someone seasoned, it is broadcom with other third party IP. but the nanopi's perhaps or the beagle bones. – old_timer Jul 22 '18 at 23:26
  • 1
    Modern NICs are a bit complicated. If you want to know how to talk directly to your network card, try [this article](https://wiki.osdev.org/Ne2000) which explains how to program NE2000 compatible cards which were very popular and easy to program back in the day. On the bottom it says how to send an ethernet frame, which is basically what you want. – fuz Jul 23 '18 at 11:27

0 Answers0