国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

ios獲取ip地址

2019-11-14 20:40:31
字體:
供稿:網(wǎng)友

進(jìn)來接微信支付,后臺要傳ip地址,so~

首先要導(dǎo)這些頭文件

 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 #include <string.h> 5 #include <unistd.h> 6 #include <sys/ioctl.h> 7 #include <sys/types.h> 8 #include <sys/sysctl.h> 9 #include <sys/socket.h>10 #include <netinet/in.h>11 #include <netdb.h>12 #include <arpa/inet.h>13 #include <sys/sockio.h>14 #include <net/if.h>15 #include <net/ethernet.h>16 #include <errno.h>17 #include <net/if_dl.h>18 #include <ifaddrs.h>19 #include <mach/machine.h>

然后就是方法啦:

 1 + (NSString *)getIPAddress 2 { 3     NSString *address = @"error"; 4     struct ifaddrs *interfaces = NULL; 5     struct ifaddrs *temp_addr = NULL; 6     int success = 0; 7     // retrieve the current interfaces - returns 0 on success 8     success = getifaddrs(&interfaces); 9     if (success == 0)10     {11         // Loop through linked list of interfaces12         temp_addr = interfaces;13         while(temp_addr != NULL)14         {15             if(temp_addr->ifa_addr->sa_family == AF_INET)16             {17                 // Check if interface is en0 which is the wifi connection on the iPhone18                 if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"])19                 {20                     // Get NSString from C String21                     address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];22                 }23             }24             temp_addr = temp_addr->ifa_next;25         }26     }27     // Free memory28     freeifaddrs(interfaces);29     return address;30 }

我是給放在工具類里面了,哪里要用調(diào)哪里~so easy~


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 营口市| 江陵县| 遂宁市| 兰坪| 武山县| 贺兰县| 南乐县| 苏尼特左旗| 建湖县| 嘉黎县| 平山县| 肇州县| 资溪县| 富川| 栾城县| 阳江市| 沂南县| 潢川县| 区。| 靖安县| 兴城市| 东乡族自治县| 信宜市| 图们市| 敦煌市| 苗栗县| 榆树市| 金平| 怀安县| 鸡东县| 广昌县| 天镇县| 武宁县| 浮梁县| 镇江市| 邹平县| 重庆市| 西贡区| 南康市| 城口县| 城口县|