如何获取iOS设备的主机名[重复]

时间:2022-01-14 07:33:22

This question already has an answer here:

这个问题在这里已有答案:

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.

中,你可以找到函数gethostname(),它接受一个char指针的参数,遗憾的是,它是一个长度。如果提供的第二个参数太长(它将HOST_NAME_MAX定义为255,那么这将是您最好的选择),它将终止,因此您可以使用一些巨大的int值并仍然获得有效的结果。

#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.

中,你可以找到函数gethostname(),它接受一个char指针的参数,遗憾的是,它是一个长度。如果提供的第二个参数太长(它将HOST_NAME_MAX定义为255,那么这将是您最好的选择),它将终止,因此您可以使用一些巨大的int值并仍然获得有效的结果。