【问题标题】:What exactly means iOS networking interface name? what's pdp_ip ? what's ap?iOS 网络接口名称到底是什么意思?什么是 pdp_ip ?什么是ap?
【发布时间】:2012-12-29 08:03:15
【问题描述】:

我使用下面的代码打印所有的接口和它的mac地址

- ( void )interfaceInfo{

int                 mib[6];
size_t              len;
char                *buf;
unsigned char       *ptr;
struct if_msghdr    *ifm;
struct sockaddr_dl  *sdl;

mib[0] = CTL_NET;
mib[1] = AF_ROUTE;
mib[2] = 0;
mib[3] = AF_LINK;
mib[4] = NET_RT_IFLIST;

char name[128];
memset(name, 0, sizeof(name));
for (int i=1; i<20; i ++) {
    if (if_indextoname(i, name)) {
        printf("%s ",name);            
    }else{
        continue;
    }

    if ((mib[5] = if_nametoindex(name)) == 0) {
        printf("Error: if_nametoindex error\n");
        return NULL;
    }

    if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
        printf("Error: sysctl, take 1\n");
        return NULL;
    }

    if ((buf = malloc(len)) == NULL) {
        printf("Could not allocate memory. error!\n");
        return NULL;
    }

    if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
        printf("Error: sysctl, take 2");
        free(buf);
        return NULL;
    }

        ifm = (struct if_msghdr *)buf;
        sdl = (struct sockaddr_dl *)(ifm + 1);
        ptr = (unsigned char *)LLADDR(sdl);
        NSString *macString = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X",
                       *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
        printf(" %s\n",[macString cStringUsingEncoding:NSUTF8StringEncoding]);
        free(buf);
    }
    return nil;
}

我在 iPhone 5 上运行代码,输出为

lo0  00:00:00:00:00:00
pdp_ip0  00:00:00:00:00:00
pdp_ip1  00:00:00:00:00:00
pdp_ip2  00:00:00:00:00:00
pdp_ip3  00:00:00:00:00:00
ap1  EA:8D:28:44:32:2F
en0  E8:8D:28:44:32:2F
en1  EA:8D:28:44:32:31
awdl0  4A:79:85:44:5B:4D
//I faked parts data

我想知道 pdp_ip 是什么?什么是ap1,en1?

我发现en0是wifi硬件mac地址

ap1 和 en1 是虚拟接口吗?

谢谢!

【问题讨论】:

    标签: iphone ios objective-c mac-address network-interface


    【解决方案1】:

    从我的研究看来(即我没有找到任何确认文档)如果上面的代码返回多个“awdl0”条目,则启用了 Wi-Fi。类似地,多个“pdp_ip0”条目表示启用了蜂窝数据。然后可以使用其他库(最显着的是 Reachability)来指示已使用上述任何一种方法建立了数据连接。

    【讨论】:

      【解决方案2】:

      lo = 本地主机
      zh = 以太网
      ap = 可能用于接入点(如果您充当 wifi 主机)

      pdp_ip = 可能是 PDS 数据包? PDS 是电话数据服务,是 GSM 的数据部分。由于有四个,我可以假设 PDS 有能力提供四个离散通道。

      【讨论】:

        【解决方案3】:

        ap1, en0, en1 是 iOS 和 Mac 上接口的名称。如果你在 Mac 上输入 Terminal ifconfig 你会得到同样的结果,en0、en1 等等。

        pdp_ip 接口是用于 3G 和蜂窝数据的接口,而 ap1 用于表示当前活动的数据连接、Wi-Fi、蜂窝数据或蓝牙。

        【讨论】:

        • en 代表以太网,ap 代表什么?我在我的mac上尝试ifconfig,没有ap接口名称。为什么这么多pdp家族接口?这确实意味着有不止一个蜂窝数据硬件,不是吗?谢谢!
        猜你喜欢
        • 1970-01-01
        • 2014-09-30
        • 2014-06-02
        • 2017-08-07
        • 2017-07-20
        • 2014-09-23
        • 2014-07-25
        • 2012-09-17
        • 1970-01-01
        相关资源
        最近更新 更多