Changed network interface detection

Added Nextion HMI files
This commit is contained in:
ON7LDS
2017-10-17 20:42:38 +02:00
parent 8f5d691006
commit 8c9afa6862
13 changed files with 65 additions and 45 deletions

View File

@@ -40,25 +40,40 @@ void CNetworkInfo::getNetworkInterface(unsigned char* 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 *p; char *dflt, *p;
FILE *f;
char line[100];
dflt=NULL;
f = fopen("/proc/net/route" , "r");
while(fgets(line , 100 , f))
{
dflt = strtok(line , " \t");
p = strtok(NULL , " \t");
if(dflt!=NULL && p!=NULL)
{
if(strcmp(p , "00000000") == 0)
{
break;
}
}
}
strcpy(text,"(interface lookup failed)");
for(n=0;n<IFLISTSIZ;n++) { for(n=0;n<IFLISTSIZ;n++) {
interfacelist[n][0]=0; interfacelist[n][0]=0;
} }
ifnr=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) :
@@ -80,10 +95,15 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
} }
} }
freeifaddrs(ifaddr); freeifaddrs(ifaddr);
LogInfo(" Default interface is : %s" , dflt);
for(n=0;n<(ifnr);n++) { for(n=0;n<(ifnr);n++) {
p=strchr(interfacelist[n],'%'); p=strchr(interfacelist[n],'%');
if (p!=NULL) *p=0; if (p!=NULL) *p=0;
if (strstr(interfacelist[n],"lo")==NULL) { if(strstr(interfacelist[n], dflt) != 0)
{
strcpy((char*)info,interfacelist[n]); strcpy((char*)info,interfacelist[n]);
break; break;
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -19,6 +19,6 @@
#if !defined(VERSION_H) #if !defined(VERSION_H)
#define VERSION_H #define VERSION_H
const char* VERSION = "20170719"; const char* VERSION = "20171003_ON7LDS";
#endif #endif