Netzwerk Interface Netmask bestimmen
-
Hallo
Ich möchte in einem C++ Programm Informationen zu den Vorhandenen Netzwerkinterfaces auslesen.
Es sollen der Name, die IP-Adresse und die Netzmaske ausgegeben werden.mit folgendem code erhale ich alle Schnittstellen mit zugehöriger IP-Adresse:
char ipaddress[128];
char buf[64 * sizeof(struct ifreq)]; //will hold upto 64 ifaces
int last_buflen;
int sock;
struct ifconf ifc;
struct ifreq *ifr;
struct sockaddr_in *ipaddr;sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
ifc.ifc_buf = buf;
ifc.ifc_len = 1020;
// this keeps track of how many interfaces discovered
ifcount = 0;if (ioctl(sock, SIOCGIFCONF, &ifc) >= 0) {
while((ifcount * sizeof(struct ifreq)) < ifc.ifc_len) {
ifr = (struct ifreq *)(buf + ( ifcount * sizeof(struct ifreq) ) );ipaddr = (struct sockaddr_in
&ifr->ifr_addr;
sprintf( (char *)&ipaddress, "%s", inet_ntoa( ipaddr->sin_addr ) );
printf("%s = %s\n", ifr->ifr_name, ipaddress);ifcount++;
};
} else { // ioclt call failed - abort
//close( sock );}
Wie ist es möglich jetzt auch noch die Netmask zu bekommen?
Grüße
Lummi