bzs@bu-cs.bu.EDU (02/22/87)
The route program will always call gethostbyname(), even if you provide numeric internet addresses. This can be a problem if you use some form of name server and/or yellow pages distributed service. How do you fix a route to the name server? Anyhow, it can even be a nuisance if things are very slow for some reason and it's particularly insidious when used in rc boot files as the name server may be on the same machine and initializing which can really slow down a simple request to poke a default route or some such, or worse. You get the picture. I threw together a version of route I call nroute which is very simple, assumes only d.d.d.d format addresses and AF_INET thus never needing to speak to anyone to just poke a route (use the inet(3) routines to xlate the numbers.) Unfortunately it's hugely ripped out of the 4.2 route.c source so I am loathe to just send it out, but perhaps the thought was worthwhile and it would be simple to write the same thing with or without sources (hint: see net/route.h, fill in the rt_gateway, rt_dst stuff and the rt_flags field [with at least RTF_UP and either |RTF_GATEWAY (metric > 0) or |RTF_HOST] of an rtentry struct and then call ioctl on an AF_INET,SOCK_RAW socket with either SIOCADDRT or SIOCDELRT [add/delete respectively] and the address of the rt_entry.]) By the way, anyone else notice that, (both 4.2, 4.3 if I read right), the metric is only checked for zero/gtr-zero to set the RTF_GATEWAY flag? Interesting. The documentation alludes to this but the term 'metric' might be misleading (hop count?) -Barry Shein, Boston University
narten@purdue.EDU (02/23/87)
Gethostbyname() is where the fix should be. Anyone who has used networking software extensively knows that there are times when using a dotted Internet address instead of a host name is useful (and necessary!) It is extremely annoying and often tragic that the acceptance of dotted numbers is application specific. Predictable and uniform behavior is a desirable feature. Some programs take dotted names, others do not. Of those that do, some call gethostbyname first, checking whether or not the name is in dotted notation only as a last resort. When a nameserver is involved, gethostbyname doesn't return quickly (if at all). The algorithm should be: If in the Internet domain, is the host name in dotted notation? If so, return the internet address right away. If the name is not in dotted form, THEN do what gethostbyname currently does. Using this algorithm lets all networking software take dotted names. (e.g. the code resides in library routines.) Furthermore, neither the nameserver or host table is consulted in doing translations that it wouldn't perform anyway. The only problem I see is that for gethostbyname to return "hostent"s for addresses in dotted notation, a "fake" entry must be created with some sort of bogus Official name. This will undoubtably break existing programs in silly ways. Thomas
treese@bacchus.UUCP (02/24/87)
We modified gethostbyname() to first check to see if the name is a valid dotted quad Internet address. If it is, the function constructs the appropriate structure with the name as the string dotted quad. A nice side effect of this is that now all programs understand addresses and can deal with them. Another solution to Barry's problem is to simply compile those few programs that really need to work without the nameserver (e.g., /etc/route, /etc/ifconfig) with the libhostlib.a library that still reads /etc/hosts. Win Treese MIT Project Athena Internet: treese@athena.MIT.EDU