Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <arpa/inet.h>
- #include <ifaddrs.h>
- #include <string.h>
- #include <string> //c++
- #include <iostream>
- using namespace std;
- int main ()
- {
- struct ifaddrs *ifap, *ifa;
- std::string addr,mask;
- getifaddrs (&ifap);
- for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
- if (ifa->ifa_addr->sa_family==AF_INET && strcmp (ifa->ifa_name ,"lo")!=0) {
- addr = inet_ntoa( ((struct sockaddr_in *) ifa->ifa_addr)->sin_addr);
- mask = inet_ntoa( ((struct sockaddr_in *) ifa->ifa_netmask)->sin_addr);
- cout <<"Interface :"<<ifa->ifa_name<<" : " <<addr<<endl;
- cout <<"mask :"<<mask<<" : " <<endl;
- //freeifaddrs(ifap);
- }
- }
- freeifaddrs(ifap);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement