X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_66,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org MIME-Version: 1.0 Date: Fri, 12 Jun 2009 14:30:29 +0200 Message-ID: Subject: ioctl(sock, SIOCGIFHWADDR, &ifr) fails with 1.7 From: =?UTF-8?B?RnLDqWTDqXJpYyBCcm9u?= To: cygwin Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com I used the following program to obtain mac address and ip of network adpaters. It works fine with 1.5 but not with 1.7. Output with 1.5: sock=3D3 trying eth0 mac: 00.1f.3c.57.XX.XX, ip: XXX.XXX.XXX.XXX trying eth1 mac: 00.1d.09.df.XX.XX, ip: XXX.XXX.XXX.XXX trying eth2 mac: 08.00.27.00.XX.XX, ip: XXX.XXX.XXX.XXX trying eth3 ... Output with 1.7: sock=3D3 trying eth0 trying eth1 trying eth2 trying eth3 ... Any clue? Fr=C3=A9d=C3=A9ric #include #include #include #include #include void read_hwaddr(const struct ifreq &ifr) { std::cout << "mac: " ; const struct sockaddr &hwaddr=3Difr.ifr_hwaddr ; for (size_t k=3D0 ; k<6 ; ++k) { if (k) std::cout << '.' ; unsigned int v=3Dstatic_cast(hwaddr.sa_data[= k]) ; std::cout << std::hex << std::setw(2) << std::setfill('0') << static_cast(v) ; } } void read_ip(const struct ifreq &ifr) { std::cout << "ip: " ; const struct sockaddr &addr=3Difr.ifr_addr ; for (size_t k=3D0 ; k<4 ; ++k) { unsigned int v=3Dstatic_cast(addr.sa_data[k+= 2]) ; if (k) std::cout << '.' ; std::cout << std::dec << static_cast(v) ; } } int main() { std::string eth("eth") ; struct protoent *proto=3DNULL ; if (proto=3Dgetprotobyname("tcp")) { int sock=3Dsocket(PF_INET, SOCK_STREAM, proto->p_proto) ; std::cout << "sock=3D" << sock << '\n' ; struct ifreq ifr ; for (char k=3D'0' ; k<=3D'9' ; ++k) { std::cout << "trying " << (eth+k) << '\n' ; std::memset(&ifr, 0, sizeof(struct ifreq)) ; std::strcpy(ifr.ifr_name, (eth+k).c_str()) ; // MAC address if (ioctl(sock, SIOCGIFHWADDR, &ifr)!=3D0) continue= ; read_hwaddr(ifr) ; std::cout << ", " ; // IP address if (ioctl(sock, SIOCGIFADDR, &ifr)=3D=3D0) read_ip(= ifr) ; std::cout << '\n' ; } close(sock) ; } return 0 ; } -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/