-
Notifications
You must be signed in to change notification settings - Fork 2
/
InterfacesUnix.cpp
51 lines (37 loc) · 1.03 KB
/
InterfacesUnix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "SoapyNetSDR.hpp"
std::vector<interfaceInformation> interfaceList()
{
std::vector<interfaceInformation> list;
interfaceInformation c1;
struct ifaddrs *addrs,*iloop;
char buf[INET_ADDRSTRLEN],buf2[INET_ADDRSTRLEN];
struct sockaddr_in *s4;
getifaddrs(&addrs);
for (iloop = addrs; iloop != NULL; iloop = iloop->ifa_next)
{
if (iloop->ifa_addr == NULL)
continue;
if (iloop->ifa_addr->sa_family != AF_INET) continue; //just IPv4
s4 = (struct sockaddr_in *)(iloop->ifa_addr);
buf[0]=0;
if(s4){
inet_ntop(iloop->ifa_addr->sa_family, (void *)&(s4->sin_addr), buf, sizeof(buf));
}else{
continue;
}
s4 = (struct sockaddr_in *)(iloop->ifa_dstaddr);
buf2[0]=0;
if(s4){
inet_ntop(iloop->ifa_dstaddr->sa_family, (void *)&(s4->sin_addr), buf2, sizeof(buf2));
}else{
continue;
}
if(!(iloop->ifa_flags & IFF_UP) || !(iloop->ifa_flags & IFF_BROADCAST))continue;
c1.name = iloop->ifa_name;
c1.address = buf;
c1.broadcast = buf2;
list.push_back(c1);
}
freeifaddrs(addrs);
return list;
}