Michael Schroeder wrote:
On Thu, Feb 28, 2008 at 02:25:25PM -0700, John Calcote wrote:
After analyzing this trace I can see by mapping the write(3, ...) calls to my source code that this code is failing:
// cache our (primary?) ip address in binary and string format if (getifaddrs(&ifa) == 0) { u_int setflags = IFF_UP | IFF_RUNNING; u_int clrflags = IFF_LOOPBACK; struct ifaddrs * ifcur = ifa;
// locate the first proper AF_NET address in our interface list while (ifcur && (ifcur->ifa_addr->sa_family != AF_INET || (ifcur->ifa_flags & setflags) != setflags || (ifcur->ifa_flags & clrflags) != 0)) ifcur = ifcur->ifa_next;
if (ifcur) { // cache binary and presentation (string) versions of the ip address iwlm->myipaddr = (unsigned long) ((struct sockaddr_in *)ifcur->ifa_addr)->sin_addr.s_addr; inet_ntop(ifcur->ifa_addr->sa_family, &((struct sockaddr_in *)ifcur->ifa_addr)->sin_addr, iwlm->myipaddrstr, sizeof iwlm->myipaddrstr); } freeifaddrs(ifa); }
Does this tell you guys anything? I can't really see why it would fail.
It's looking your a network interface that is not loopback. We don't have that on the build clients, we have just a single loopback interface.
Cheers, Michael.
Hi Michael, I realize this list is probably not the place to discuss this problem, but I don't get a chance to chat with you very often. :) I'll make this my last post on this subject. I'm thinking the right change here is to use the loopback address as a fallback. Normally, I'd want to identify myself to my server by a non-local address - it's silly to send 127.0.0.1 to a server to identify yourself - unless of course that really is your only address! I think I'll change this code so that it uses the first non-loopback address it finds, but if none exists, then it falls back to the loopback address. This way it can assume that if loopback is the only one it can find, then the server must also be local. Does this sound reasonable? Also, I've been wondering about this sort of code for years. I mean, if you're multi-homed, then which non-local address do you tell your server about? Clearly the right way is to calculate the route to your server, and ensure you're telling the server that your name is some address by which he really can reach you. In this case, it doesn't matter, as we're using this address more as a human-readable indication of which machine is processing the server's data, but in a more rigorous environment, where the address might be used by the server to return information to the client, you'd want to pick an address with a proper route. Is there some example code of doing this sort of thing that you're aware of? Regards, John --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-buildservice+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-buildservice+help@opensuse.org