めも
/////////////// ネットワークインターフェイスの取得 /////////////// int socketFD,length, lastLength; char *buffer; struct ifconf ifc; socketFD = socket(AF_INET, SOCK_DGRAM, 0); lastLength = 0; length = sizeof(struct ifreq) * 100; NSLog(@"length:%d",length); for (; ;) { buffer = (char *)calloc(length, sizeof(char)); ifc.ifc_len = length; ifc.ifc_ifcu.ifcu_buf = buffer; if ( ioctl(socketFD, SIOCGIFCONF, &ifc) < 0) { int erroNumber = errno; NSLog(@"%s",strerror(erroNumber)); } else { if (ifc.ifc_len == lastLength) { break; } lastLength = ifc.ifc_len; } length += sizeof(struct ifreq) * 10; free(buffer); } struct ifreq *ifr = (struct ifreq *)buffer; int next = 0; /////////////// 表示してみる /////////////// while (ifr < (struct ifreq *)(buffer + lastLength)) { ifr = (struct ifreq *)(buffer + next); NSLog(@"interface:%s",ifr->ifr_name); next += IFNAMSIZ + ifr->ifr_ifru.ifru_addr.sa_len; } free(buffer); close(socketFD);同じのがいっぱい出た。
0 件のコメント:
コメントを投稿