This question already has an answer here:
这个问题在这里已有答案:
- NSNetService works fine, but can't get hostName, resolve causes error 3 answers
- NSNetService工作正常,但无法获取hostName,解决导致错误3的答案
I'm not sure how to get the hostname of my iOS device? I'd like to compare NSNetServices against it, to ensure that it doesn't include its own hostname in the list of available services.
我不知道如何获取我的iOS设备的主机名?我想将NSNetServices与它进行比较,以确保它在可用服务列表中不包含自己的主机名。
1 个解决方案
#1
1
In <unistd.h>
, you can find the function gethostname()
which takes an argument for a char pointer, and sadly enough, a length. It null terminates if the second argument provided is too long (it defines HOST_NAME_MAX
as 255, so that would be your best bet), so you can use some huge int value and still get a valid result.
在
#1
1
In <unistd.h>
, you can find the function gethostname()
which takes an argument for a char pointer, and sadly enough, a length. It null terminates if the second argument provided is too long (it defines HOST_NAME_MAX
as 255, so that would be your best bet), so you can use some huge int value and still get a valid result.
在