From: Charles Sharp (charles.sharp at domain sun.com)
Date: Fri 22 Jun 2001 - 13:51:49 IST
Hi Kate,
A guess at the problem is embedded:
"John P. Looney" wrote:
>
> I'm using the following function to return an array of ifreq structs,
> which I use for various reasons. But, for some reason, this doesn't work
> on interfaces which are down, and have an IP set to 0.0.0.0 - any idea why
> ?
>
> struct ifreq *get_if_info(int skfd, int *num_interfaces, char **old_ifc_bufp)
> {
> struct ifconf ifconf;
> int if_increments=10;
> int result;
>
> if (skfd == -1) {
> syslog(LOG_INFO, "af_get_if_info: Invalid socket. [%s]", strerror(errno));
> return NULL;
> }
> ifconf.ifc_buf = NULL;
> ifconf.ifc_len = sizeof(struct ifreq) * if_increments;
> if(!(ifconf.ifc_buf = malloc(ifconf.ifc_len))) {
> syslog(LOG_INFO, "Malloc failed in af_get_if_info");
> return NULL;
> }
>
> for(ever) {
(Could I encourage you to use ";;" vis a vis a #define?)
> ifconf.ifc_len = sizeof(struct ifreq) * if_increments;
> if(!(ifconf.ifc_buf = realloc(ifconf.ifc_buf, ifconf.ifc_len))) {
> syslog(LOG_INFO, "Realloc failed in af_get_if_info");
> return NULL;
> }
> if ((result = ioctl(skfd, SIOCGIFCONF, &ifconf)) < 0) {
> if (!(errno == ENODEV)) {
> syslog(LOG_INFO, "Network information check failed %d (%s)", errno, strerror(errno));
}
Concerning your problem - I suspect this is it. I would
suggest putting an else clause here, like:
else {
syslog(LOG_INFO, "Got some other error from ioctl:
%d (%s)",
errno, strerror(errno));
}
> break;
Ah! Do you really want to set your return values and exit via this
break or do you want to "return EXIT_FAILURE;" or some other status.
As it is, you're going to break and go set your num_interfaces with
something _unknown_ (like whatever you had in if_conf at the time of
the error) if the ioctl returns with an error besides ENODEV.
> }
> if (ifconf.ifc_len == sizeof(struct ifreq) * if_increments) {
(an aside) Why wouldn't this always be true -- does the ioctl manipulate
ifc_len? This is the condition you establish at the top of the loop...
> if_increments += 10;
> continue;
> }
> break;
> }
> *num_interfaces=ifconf.ifc_len/sizeof(struct ifreq);
> *old_ifc_bufp=ifconf.ifc_buf;
> return(ifconf.ifc_req);
> }
>
> --
> When I say 'free', I mean 'free': free from bond, of chain or command:
> to go where you will, even to Mordor, Saruman, if you desire. "
> -- Gandalf, paraphrasing the choice between Free and Non-free software
>
> --
> Irish Linux Users' Group: ilug at domain linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
> List maintainer: listmaster at domain linux.ie
rgds,
cas
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:10:49 GMT