mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-22 16:25:45 +08:00
Changed network interface detection
Added Nextion HMI files
This commit is contained in:
108
Network.cpp
108
Network.cpp
@@ -36,59 +36,79 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
|
|||||||
{
|
{
|
||||||
#define IFLISTSIZ 25
|
#define IFLISTSIZ 25
|
||||||
|
|
||||||
LogInfo("Interfaces Info");
|
LogInfo("Interfaces Info");
|
||||||
struct ifaddrs *ifaddr, *ifa;
|
struct ifaddrs *ifaddr, *ifa;
|
||||||
int family, s, n, ifnr;
|
int family, s, n, ifnr;
|
||||||
char host[NI_MAXHOST];
|
char host[NI_MAXHOST];
|
||||||
char text[50+INET6_ADDRSTRLEN];
|
char interfacelist[IFLISTSIZ][50+INET6_ADDRSTRLEN];
|
||||||
char interfacelist[IFLISTSIZ][50+INET6_ADDRSTRLEN];
|
char *dflt, *p;
|
||||||
char *p;
|
FILE *f;
|
||||||
|
char line[100];
|
||||||
|
|
||||||
strcpy(text,"(interface lookup failed)");
|
dflt=NULL;
|
||||||
for(n=0;n<IFLISTSIZ;n++) {
|
f = fopen("/proc/net/route" , "r");
|
||||||
interfacelist[n][0]=0;
|
|
||||||
|
while(fgets(line , 100 , f))
|
||||||
|
{
|
||||||
|
dflt = strtok(line , " \t");
|
||||||
|
p = strtok(NULL , " \t");
|
||||||
|
|
||||||
|
if(dflt!=NULL && p!=NULL)
|
||||||
|
{
|
||||||
|
if(strcmp(p , "00000000") == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ifnr=0;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(n=0;n<IFLISTSIZ;n++) {
|
||||||
|
interfacelist[n][0]=0;
|
||||||
|
}
|
||||||
|
ifnr=0;
|
||||||
if (getifaddrs(&ifaddr) == -1) {
|
if (getifaddrs(&ifaddr) == -1) {
|
||||||
strcpy((char*)info,"getifaddrs failure");
|
strcpy((char*)info,"getifaddrs failure");
|
||||||
} else {
|
} else {
|
||||||
for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) {
|
for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) {
|
||||||
if (ifa->ifa_addr == NULL)
|
if (ifa->ifa_addr == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
family = ifa->ifa_addr->sa_family;
|
family = ifa->ifa_addr->sa_family;
|
||||||
|
|
||||||
if (family == AF_INET || family == AF_INET6) {
|
if (family == AF_INET || family == AF_INET6) {
|
||||||
s = getnameinfo(ifa->ifa_addr,
|
s = getnameinfo(ifa->ifa_addr,
|
||||||
(family == AF_INET) ? sizeof(struct sockaddr_in) :
|
(family == AF_INET) ? sizeof(struct sockaddr_in) :
|
||||||
sizeof(struct sockaddr_in6),
|
sizeof(struct sockaddr_in6),
|
||||||
host, NI_MAXHOST,
|
host, NI_MAXHOST,
|
||||||
NULL, 0, NI_NUMERICHOST);
|
NULL, 0, NI_NUMERICHOST);
|
||||||
if (s != 0) {
|
if (s != 0) {
|
||||||
LogInfo("getnameinfo() failed: %s\n", gai_strerror(s));
|
LogInfo("getnameinfo() failed: %s\n", gai_strerror(s));
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
if (family == AF_INET) {
|
|
||||||
sprintf(interfacelist[ifnr], "%s: %s", ifa->ifa_name,host);
|
|
||||||
LogInfo(" IPv4: %s", interfacelist[ifnr] );
|
|
||||||
} else {
|
|
||||||
sprintf(interfacelist[ifnr], "%s: %s", ifa->ifa_name,host);
|
|
||||||
LogInfo(" IPv6: %s", interfacelist[ifnr] );
|
|
||||||
}
|
|
||||||
ifnr++;
|
|
||||||
}
|
}
|
||||||
}
|
if (family == AF_INET) {
|
||||||
freeifaddrs(ifaddr);
|
sprintf(interfacelist[ifnr], "%s: %s", ifa->ifa_name,host);
|
||||||
for(n=0;n<(ifnr);n++) {
|
LogInfo(" IPv4: %s", interfacelist[ifnr] );
|
||||||
p=strchr(interfacelist[n],'%');
|
} else {
|
||||||
if (p!=NULL) *p=0;
|
sprintf(interfacelist[ifnr], "%s: %s", ifa->ifa_name,host);
|
||||||
if (strstr(interfacelist[n],"lo")==NULL) {
|
LogInfo(" IPv6: %s", interfacelist[ifnr] );
|
||||||
strcpy((char*)info,interfacelist[n]);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
ifnr++;
|
||||||
}
|
}
|
||||||
LogInfo(" IP to show: %s", info );
|
|
||||||
}
|
}
|
||||||
|
freeifaddrs(ifaddr);
|
||||||
|
|
||||||
|
|
||||||
|
LogInfo(" Default interface is : %s" , dflt);
|
||||||
|
|
||||||
|
for(n=0;n<(ifnr);n++) {
|
||||||
|
p=strchr(interfacelist[n],'%');
|
||||||
|
if (p!=NULL) *p=0;
|
||||||
|
if(strstr(interfacelist[n], dflt) != 0)
|
||||||
|
{
|
||||||
|
strcpy((char*)info,interfacelist[n]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LogInfo(" IP to show: %s", info );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Nextion_ON7LDS/NX3224T024-ON7LDS.HMI
Normal file
BIN
Nextion_ON7LDS/NX3224T024-ON7LDS.HMI
Normal file
Binary file not shown.
Binary file not shown.
BIN
Nextion_ON7LDS/NX3224T028-ON7LDS.HMI
Normal file
BIN
Nextion_ON7LDS/NX3224T028-ON7LDS.HMI
Normal file
Binary file not shown.
BIN
Nextion_ON7LDS/NX3224T028-ON7LDS.tft
Normal file
BIN
Nextion_ON7LDS/NX3224T028-ON7LDS.tft
Normal file
Binary file not shown.
BIN
Nextion_ON7LDS/NX4024T032-ON7LDS.HMI
Normal file
BIN
Nextion_ON7LDS/NX4024T032-ON7LDS.HMI
Normal file
Binary file not shown.
BIN
Nextion_ON7LDS/NX4024T032-ON7LDS.tft
Normal file
BIN
Nextion_ON7LDS/NX4024T032-ON7LDS.tft
Normal file
Binary file not shown.
BIN
Nextion_ON7LDS/NX4832T035-ON7LDS.HMI
Normal file
BIN
Nextion_ON7LDS/NX4832T035-ON7LDS.HMI
Normal file
Binary file not shown.
BIN
Nextion_ON7LDS/NX4832T035-ON7LDS.tft
Normal file
BIN
Nextion_ON7LDS/NX4832T035-ON7LDS.tft
Normal file
Binary file not shown.
Reference in New Issue
Block a user