Zend certified PHP/Magento developer

What does the underlying process of sending a packet look like before it goes through Ethernet / Wi-Fi?

Just to be clear, I’m talking about everything that happens before it’s on its way to the router and we start talking about topologies, routing, etc.

So for my Data Networks class we were assigned a task to write a server and client in C using socket(). After somehow stringing together a working solution, I’m still confused. What exactly happens in send()? What exactly is doing the job of turning data into packets? Are we already at the lower levels where we’re communicating with, what I assume is, the network card in a PC? And how does this process differ when we’re only communicating on localhost? It all seems so abstract to me, and I apologize if the title is unclear as to what I’m trying to ask.

Maybe these questions could’ve been answered already if I took a C class before this.