究竟是什么意味着iOS网络接口名称?什么是pdp_ip?什么是ap?

Ala*_*din 12 iphone mac-address objective-c ios network-interface

我使用以下代码打印所有接口及其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;
}
Run Code Online (Sandbox Code Playgroud)

我在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
Run Code Online (Sandbox Code Playgroud)

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

我发现en0是wifi硬件mac地址

ap1和en1是虚拟接口吗?

谢谢!

Ama*_*ulo 9

ap1,en0,en1是iOS和Mac上的接口名称.如果您在Mac上键入终端,ifconfig您将获得相同的,en0,en1等.

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

  • en代表以太网,什么是ap代表什么?我在我的mac上尝试ifconfig,没有ap接口名称.为什么这么多pdp系列接口?它确实意味着有多个蜂窝数据硬件,不是吗?谢谢 ! (2认同)

BBQ*_*eve 8

lo = localhost
en = ethernet
ap =可能是接入点(如果你是一个wifi主机)

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