iOS 17 - gethostname()

Seems like gethostname() is not returning host name anymore in iOS 17 beta, just localhost. Is this a bug?

What are you expecting it to return? That is, on you current product running on iOS 16, what do you do with this value?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

It used to return some readable derivative of the device name in .local domain. Since device name is not accessible anymore (without special entitlement) we used gethostname() as a "hint" reference in logs and across web UIl where long lists of enrolled devices are listed.

we used gethostname as a "hint" reference in logs and across web UI where long lists of enrolled devices are listed.

My recommendation is that you come up with an alternative technique for this. gethostname has always had very squishy semantics [1] and an implementation that always returns localhost is perfectly valid. I haven’t specifically checked on this, but I think it’s safe to assume that we made this change for privacy reasons, that is, to prevent folks from doing exactly what you’re doing. This is in line with our long-term policy on this front; see the footnote in this post.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Many folks assume that it returns a DNS name but that’s not guaranteed.

Formally "localhost" can be valid, however logically it's as meaningless as would any API returning fixed string would be. Effectively gethostname() cease to exist as a function and becomes an equivalent of string "localhost". In any case would be nice if you could confirm the change since it's not mentioned in Release Notes, as it seems.

Effectively gethostname cease to exist as a function

That happened long ago, at last to my mind. The value it returns has effectively been meaningless since the very first version of Mac OS X.

In any case would be nice if you could confirm the change since it's not mentioned in Release Notes

I can’t confirm this more ‘officially’ than I’ve done here. Still, I agree that it’d be nice if the release notes covered this and I encourage you to file a bug requesting that.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Before it was useful, since it produced an output which could be easily recognized and narrowed out of a long list of other devices. Now it's truly meaningless - perfection achieved.

Fun discussion to have in front of a fireplace with a glass of good scotch, but irrelevant to millions of user faced with amazing and very readable "localhost" or UUIDs a-la "486398F2-76EC-475A-8549-5219672CBF01" instead of awful "Joe's iPhone" or "joes-iphone.local" as it used to be.

I've filed FB12407865.

There are other situations where this makes a lot of sense and doesn't affect privacy, essentially it is a way for the user to know their phone's mDNS name, and enable network utilities.

I develop Pocket Pass Manager, an offline password manager, to be able to access your passwords from other devices the phone creates a web server, so the user can open an explorer on the local network and access their keys there without anything traveling the internet. So, how to access the web server? I just display the mDNS name (E.g., jorges-iphone.local) to the user, when is typed on a web explorer on the local network, it resolves the phone's local IP address, and access the webpage. For users this is way easier than typing the whole IP address.

Right now on iOS17 beta, the only thing the user sees can see is localhost.local, unusable.

I understand the privacy concerns, but this change affects the user negatively in many scenarios.

creates a web server, so the user can open an explorer on the local network and access their keys there without anything traveling the internet.

The technique suggested by Showing Connection Information in an iOS Server should continue to work on iOS 17 beta, but I must admit to having not tested it |-: so please let me know otherwise.

ps gethostname was never a great choice for your use case because there are situations (currently on macOS, historically on iOS) where you’d get back a DNS name that wasn’t in local.. On macOS the correct option is SCDynamicStoreCopyLocalHostName, but that’s not available on iOS and hence the technique that I suggest.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I'm using Python (=Pythonista) and would like to readout the iPhone (host)name. Python standard is to use socket.gethostname(), which worked perfectly in iOS 16 (and also on MacOS). In iOS 17 I receive now the meaningless localhost (on every device). The alternative platform.node() returns the same useless (=localhost) value.

Does someone know, how I can read out the device name ?

iOS 17 - gethostname()
 
 
Q