Changing networks on Mac with Firefox

Not too long ago I blogged about my work to better deal with changing networks while Firefox is running. That job was basically two parts.

A) generic code to handle receiving such a network-changed event and then

B) a platform specific part that was for Windows that detected such a network change and sent the event

Today I've landed yet another fix for part B called bug 1079385, which detects network changes for Firefox on Mac OS X.

mac miniI've never programmed anything before on the Mac so this was sort of my christening in this environment. I mean, I've written countless of POSIX compliant programs including curl and friends that certainly builds and runs on Mac OS just fine, but I never before used the Mac-specific APIs to do things.

I got a mac mini just two weeks ago to work on this. Getting it up, prepared and my first Firefox built from source took all-in-all less than three hours. Learning the details of the mac API world was much more trouble and can't say that I'm mastering it now either but I did find myself at least figuring out how to detect when IP addresses on the interfaces change and a changed address is a pretty good signal that the network changed somehow.

4 thoughts on “Changing networks on Mac with Firefox”

  1. Good point, thanks Gervase. The Linux one has gotten held up a bit due to some annoying test case failures I’m fighting against but I am at least making (slow) progress there…

  2. Hi Daniel, why would you want to implement your own solution for B) on Windows? It already has NotifyAddrChange and NotifyRouteChange. You may also choose to have a service that triggers upon NETWORK_MANAGER_FIRST_IP_ADDRESS_ARRIVAL_GUID or NETWORK_MANAGER_LAST_IP_ADDRESS_REMOVAL_GUID. 😉

  3. Marc: the windows implementation uses NotifyAddrChange or NotifyIpInterfaceChange on recent enough Windows versions. The earlier API for Windows XP. We build the same binary for all windows versions so we need a little magic run-time detections. The former version does for example not support IPv6.

    And if you use NotifyIpInterfaceChange which is meant to be the modern alternative, you’ll see that it triggers on slightly too many network changes for doing this functionality, so it makes sense in trying to filter that somewhat. That’s basically what my windows adaption does.

    See http://hg.mozilla.org/mozilla-central/file/04a87b6ff211/netwerk/system/win32/nsNotifyAddrListener.cpp

Comments are closed.