永发信息网

如何从IOS10.3中得到Ethernet?谢谢

答案:1  悬赏:40  手机版
解决时间 2021-03-02 02:47
如何从IOS10.3中得到Ethernet?谢谢
最佳答案
以下两个Class IPAddress.h  #define MAXADDRS 32  extern char *if_names[MAXADDRS];  extern char *ip_names[MAXADDRS];  extern char *hw_addrs[MAXADDRS];  extern unsigned long ip_addrs[MAXADDRS];  // Function prototypes  void InitAddresses();  void FreeAddresses();  void GetIPAddresses();  void GetHWAddresses();  IPAddress.c  #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "IPAddress.h"#define min(a,b) ((a) < (b) ? (a) : (b))#define max(a,b) ((a) > (b) ? (a) : (b))#define BUFFERSIZE 4000char *if_names[MAXADDRS];char *ip_names[MAXADDRS];char *hw_addrs[MAXADDRS];unsigned long ip_addrs[MAXADDRS];static int nextAddr = 0;void InitAddresses(){int i;for (i=0; iifr_addr.sa_len);ptr += sizeof(ifr->ifr_name) + len; // for next one in bufferif (ifr->ifr_addr.sa_family != AF_INET){continue; // ignore if not desired address family}if ((cptr = (char *)strchr(ifr->ifr_name, ':')) != NULL){*cptr = 0; // replace colon will null}if (strncmp(lastname, ifr->ifr_name, IFNAMSIZ) == 0){continue; }memcpy(lastname, ifr->ifr_name, IFNAMSIZ);ifrcopy = *ifr;ioctl(sockfd, SIOCGIFFLAGS, &ifrcopy);flags = ifrcopy.ifr_flags;if ((flags & IFF_UP) == 0){continue; // ignore if interface not up}if_names[nextAddr] = (char *)malloc(strlen(ifr->ifr_name)+1);if (if_names[nextAddr] == NULL){return;}strcpy(if_names[nextAddr], ifr->ifr_name);sin = (struct sockaddr_in *)&ifr->ifr_addr;strcpy(temp, inet_ntoa(sin->sin_addr));ip_names[nextAddr] = (char *)malloc(strlen(temp)+1);if (ip_names[nextAddr] == NULL){return;}strcpy(ip_names[nextAddr], temp);ip_addrs[nextAddr] = sin->sin_addr.s_addr;++nextAddr;}close(sockfd);}void GetHWAddresses(){struct ifconf ifc;struct ifreq *ifr;int i, sockfd;char buffer[BUFFERSIZE], *cp, *cplim;char temp[80];for (i=0; iifr_addr.sa_family == AF_LINK){struct sockaddr_dl *sdl = (struct sockaddr_dl *)&ifr->ifr_addr;int a,b,c,d,e,f;int i;strcpy(temp, (char *)ether_ntoa((const struct ether_addr *)LLADDR(sdl)));sscanf(temp, "%x:%x:%x:%x:%x:%x", &a, &b, &c, &d, &e, &f);sprintf(temp, "%02X:%02X:%02X:%02X:%02X:%02X",a,b,c,d,e,f);for (i=0; iifr_name, if_names[i]) == 0)){if (hw_addrs[i] == NULL){hw_addrs[i] = (char *)malloc(strlen(temp)+1);strcpy(hw_addrs[i], temp);break;}}}}cp += sizeof(ifr->ifr_name) + max(sizeof(ifr->ifr_addr), ifr->ifr_addr.sa_len);}close(sockfd);}  使用的方法  - (void)getIPAddress{InitAddresses();GetIPAddresses();GetHWAddresses();int i;NSString *deviceIP = nil;for (i=0; i
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯