@01micko
Hi Mick,
Bug report (of sort):
Currently netmon_wce contains a struct iface_info which contains char pointers to interface name (iname) and IP address (ip_address). However, no actual storage for these items has been reserved (despite the program apparently working).
As it stands, the program finds the IP address, for example, via struct iface_info now (now.ip_address) but that actually points to char array host() in memory (but since no longer in the get_info() function when used, host() no longer really exists (since local to the function) - it is still finding it, but thats just by chance that system hasn't cleared that memory area IMO. Similarly, for example, now.iname will point to addrs->ifa_name, but since struct ifaddrs *addrs was also local to function get_info(), it no longer really remains valid in memory.
One other side effect of no reserved memory actually being allocated for iname and ip_address is that the info[] array doesn't actually hold the list of interfaces/ip_addresses as I presume was intended. Thus:
Code: Select all
return info[i - 1]; //grab the first live one
doesn't actually work as it looks (as things stand, return info
for example will be found to contain exactly the same info iname and ip_addresses (which is the last one found). This causes a major side-effect:
If the active interface happens to have an IPv6 address assigned as well as an IPv4 address then the last entry found in the list is actually the IPv6 address, which then appears (undesired I expect) rather than the IPv4 address when hovering over the network tray icon with the mouse. XenialPup doesn't exhibit this effect so either the code was changed there compared to what you publish in post 1 or it only has an IPv4 address assigned. I tried netmon_wce on XenialDog with wireless connection - as on MintPup (and presumable Ubuntu and Linux Mint proper), the wifi interface has both an IPv4 and IPv6 address so latter is displayed even though actually using IPv4.
So, one way to 'fix' the needed memory storage (and thus also operation of info[] array) is to use this iface_info structure instead:
Code: Select all
//type to hold interface and ip address
struct iface_info {
// char *iname; // mcewanw
// char *ip_address; // mcewanw
char iname[IFACE_NAMELEN]; // mcewanw
char ip_address[INET6_ADDRSTRLEN]; // mcewanw
};
Then, instead of simply copying pointers, copy the actual strings across into these char strings. From get_info() function:
Code: Select all
// info[i].iname = tmp->ifa_name; // mcewanw
// info[i].ip_address = host; // mcewanw
strcpy(info[i].iname,tmp->ifa_name); // mcewanw
strcpy(info[i].ip_address, host); //mcewanw
Yes, that's a bit slower, but pointer needs to have a place to point to!
For use on systems (such as XenialDog and MintPup etc) which have IPv4 and IPv6 assigned to the active interface the problem still remains that the IPv6 address is being displayed. But because of the above alterations, I can now print the IPv4 address instead by using:
Code: Select all
return info[i - 3]; //grab the first live one
That works for XenialDog/MintPup, on my machine, because info[4] is returning the relevant IPv4 wifi info to now variable. Having said that, this is not a proper fix for that IPv4/IPv6 problem. Easier may be in fact just to use bash for IP address finding as Fred from XenialDog suggested here:
http://www.murga-linux.com/puppy/viewto ... 792#906792
fredx181 wrote:
I am really not a C programmer, but looked at the network_tray source and this seems to be how it's done for it
Code: Select all
fp = (FILE *)popen("/sbin/ifconfig|grep -iE 'Bcast|P-t-P'|tr -s ' '|tr ' ' ':'|cut -d ':' -f4" , "r");
fgets(ipa,sizeof ipa,fp);
pclose(fp);
Maybe to hackish but replacing in netmon_wce.c line 219:
Code: Select all
sprintf(ipa, "%s", now.ip_address);
with the above code from network_tray works well for me displaying the ip address
Anyway, since it works on Puppy at the moment I'm sure it isn't urgent, but for your interest I've attached my revised netmon_wce, which contains my comments and changes above (just search for mcewanw in the code).
Aside from the IPv6 issue I've had, I must say I like this program!
William