Bonjour is a very complicated system.
The daemon process which sets the hostname is "configd". If there is no dedicated DNS server on your network, then configd will use mdns/Bonjour to determine the hostname. I don't know any detail of Bonjour; the followings are just my guess.
On my home network, I have a wireless router which also has some ethernet ports. I first connected my iMac to the network via AirPort. The hostname is set to "iMac.local", where 'iMac" is the name I set in the Sharing Preference pane. The ".local" indicates this is a Bonjour name. Then I connected the iMac also via Ethernet cable (AirPort is still on, and the ethernet interface has a different IP address from AirPort). The log from configd reads:
Mon Jul 13 22:47:55 iMac configd[14] <Info>: network configuration changed.
Mon Jul 13 22:47:55 iMac configd[14] <Info>: hostname (multicast DNS) = iMac
and the hostname remains "iMac.local".
When the ethernet cable is connected, the iMac starts to use it instead of AirPort since it has higher precedence than AirPort in the Network Preference. The first thing the iMac does is to multicast that it wants to use "iMac" as the hostname and confirm that there is no other host (or interface) which uses the same name. At this point, the AirPort interface responds that it also use the name "iMac". But both packets (from Ether and Air) seem to have Kerberos ID which identifies their origin. These IDs agree with each other, so I
guess Bonjour software decides that it is OK to use the same name for the two interfaces. Only my guess.
You can watch the packets by using tcpdump, for example:
$ sudo tcpdump -vvv -s 0 port mdns
In order to read the log from configd, you need some trick.
configd sends the info to syslogd with facility/level = Daemon/Info, but they are ignored by syslogd by default, as seen from the following:
$ syslog -c syslogd
ASL Data Store filter mask: Emergency - Notice
this means the level Info (lower than Notice) is filtered out (ignored). To tell syslogd to accept all the levels:
$ sudo syslog -c syslod -d
Then you can watch the log from configd by
$ syslog -w -k Sender configd
This will print the last 10 messages (if there are), and wait for new messages. Hit ctrl-C to quit.
Be sure to set the filter level back to the original:
$ sudo syslog -c syslogd -n
See manpages for syslog(1) and syslogd(8) for more info. Or you can edit /etc/syslog.conf if you are familiar with the "ordinary (=non Apple)" syslogd.