While building a particular packet to be sent across or outside the network, the host, at a certain point, needs to specify the MAC address of the interface through which the packet is going to be sent. To know this address, the host checks its routing table for a network that includes the IP address of the destination node and retrieves the IP address of the interface through which packets to that network are supposed to be sent. My question is concerning the step that happens after this. How does the host translate the IP address of one of its interfaces to the corresponding MAC address? Does it check its MAC address table or are these correspondances stored in some global data structure that the host can access independently of its MAC address table?
1It's part of the network interface configuration, just like the layer-3 address. If not specified by the user (and rarely is), it's read from the NIC hardware by the driver at startup. It's physically stored in the NIC's flash/eeprom, which many be an external chip, or internal to the NIC. (Old Sun Sparc hardware stored it with the openboot ("bios") persistent variables -- the machine had a MAC, not each NIC.)– RickyOct 27, 2022 at 19:50
Every operating system is potentially completely different and may do more than one thing in regard to this question. The operating system may store its various interface MAC addresses at some location in a configuration file on disk, or simply store it in RAM on start up, or in a database of some kind. It is up to the operating system to do so.
Or it may not store it at all and may simply rely on the network interface driver software to inject such information in packets/frames as needed when they are encapsulated and put 'on the wire'. Technically the operating system (and certainly the application on a device) does not need to 'know' the MAC address of a given network interface in order to send or receive data over it. The interface and its driver software do need to have that in their configuration. This kind of abstraction is key to the layered network model where each layer only needs to deal with its own function and can rely on its neighboring layers to perform their functions.
Of course, some applications may want to access information about IP addresses, MAC addresses, ARP or ND tables, etc. so that kind of information can be accessed for tools like configuration interfaces, traffic capture tools, command line tools and display, etc. But those are diagnostic applications that specifically need to access that data as part of their function. An email program, for example, can send an email without knowing the MAC address of the network interface it uses to make an SMTP connection.
You shouldn't think of the computer as a wholistic organism that has to understand its own working components to function optimally. It is a collection of connected subsystems that work together to accomplish complex tasks that are broken down into tiny mathematical functions and only look like a familiar job to us from the top down view we have as human beings.
The local IP stack binds to a local interface - it logically attaches to the NIC and uses it. If that interface is MAC based (not all are), it learns the interface's MAC address in the process. Later, when it encapsulates an IP packet in a MAC frame that address is used as source address.
Depending on the host implementation, API, driver model etc (all off topic here), that process is often completely automatic by the NIC (unless overridden). That is, the IP stack passes a an IP packet as payload (L2 SDU) to the NIC driver and just lets it do its job.
How does the local IP stack "bind" to a local interface? Can you please explain what do you mean by bind? Oct 27, 2022 at 17:15
Binding is the process of logically connecting a local interface to a network stack. E.g. in Windows GUI, binding happens by putting a check mark in front of the "TCP/IPv4" or "TCP/IPv6", or via
netsh.– Zac67 ♦Oct 27, 2022 at 17:49
I don't understand. Your answer doesn't explain how the host will use the IP address of the interface to know its MAC address. Oct 27, 2022 at 18:14
The host doesn't use an IP address of an interface to learn its MAC address (there's nothing like maybe ARP for finding that out). You add an interface to the local stack and the stack learns that MAC address. Then you bind an IP address onto that interface, making it functional for the stack.– Zac67 ♦Oct 27, 2022 at 18:28
But the host uses the routing table to know the IP address of the interface through which it's going to send the packet. So, if it doesn't use this IP address to figure out the corresponding MAC address in some way, the whole operation of checking the routing table would be pointless. Oct 27, 2022 at 18:38