gethostbyname() h_addr vs. h_addr_list[0]

gethostbyname() h_addr vs. h_addr_list[0]

Post by Stephen R. van den Be » Thu, 27 Aug 1992 22:31:19



I partly have to draw upon your memory here.

While putting in some network support in a program of mine, I noticed that
in the struct hostent returned by gethostbyname() there is an entry called:

        **h_addr_list

Now, looking at the include file <netdb.h> it seems that there used to be
and entry called:

        **h_addr

in this struct, in the old days (it is marked as being needed for backward
compatibility).

Now, some questions come to mind:

        - I suppose that some old versions of UNIX did not have the h_addr_list
          member, but the h_addr member instead?

        - Is the h_addr_list list a list of pointers which is terminated with
          a null-pointer?  (the man page is not very informative regarding to
          this).

        - Can it ever happen that h_addr_list is empty?  (i.e. it will probably
          contain only a null-pointer).

        - Is there any good reason, when accessing some machine, to take any
          other address than the one pointed at by h_addr_list[0] ?

Any help would be appreciated.  Just trying to fill some undocumented
portability-caveats here.
--


"Good moaning!"

 
 
 

gethostbyname() h_addr vs. h_addr_list[0]

Post by Stephen R. van den Be » Thu, 27 Aug 1992 22:47:13


It's me again, sorry, but these portability problems always seem to
come in herds :-).

Let me explain the problem here.  I have this program (procmail) which is
trying to double as a /bin/mail substitute.  Now, the only thing that I yet
have to mimick is the biff/comsat notification which /bin/mail normally does.

Now, in order to that, I have to find out the following:

        1. gethostbyname("localhost.or.something.else")
        2. getservbyname("biff")
        3. getprotobyname("UDP")

Well, so far so good, the only trouble is, these calls are done every time
when mail arrives.  I was wondering, what is common practice in this case?

        a. Go by the book and make all three calls at runtime?
        b. Do 1. and 2. at runtime, 3. at compile time?
        c. Do 1. at runtime, 2. and 3. at compile time?
        d. Do all three at compile time?  (By compile-time I mean: compile
           a separate program that makes these calls, and then use the output
           from this program to hardcode the number(s) in the real program).

I personally like a., but I might suspect some performance penalty here
(depending on the configuration every one of these calls causes several files
to be opened and miscellaneous network-traffic to be generated).

As a reasonable compromise I suspect that b. is the most eligible, since
the protocol number for UDP is not likely to change, is it?

What would you consider acceptable practice?

Thanks.
--


"Good moaning!"

 
 
 

gethostbyname() h_addr vs. h_addr_list[0]

Post by Stephen R. van den Be » Fri, 04 Sep 1992 03:46:23


I am reposting this question because the last time it seems to have been lost
in the noise (I mistakenly posted it as a reply to some earlier question of
mine).

------------------------

It's me again, sorry, but these portability problems always seem to
come in herds :-).

Let me explain the problem here.  I have this program (procmail) which is
trying to double as a /bin/mail substitute.  Now, the only thing that I yet
have to mimick is the biff/comsat notification which /bin/mail normally does.

Now, in order to that, I have to find out the following:

        1. gethostbyname("localhost.or.something.else")
        2. getservbyname("biff")
        3. getprotobyname("udp")

Well, so far so good, the only trouble is, these calls are done every time
when mail arrives.  I was wondering, what is common practice in this case?

        a. Go by the book and make all three calls at runtime?
        b. Do 1. and 2. at runtime, 3. at compile time?
        c. Do 1. at runtime, 2. and 3. at compile time?
        d. Do all three at compile time?  (By compile-time I mean: compile
           a separate program that makes these calls, and then use the output
           from this program to hardcode the number(s) in the real program).

I personally like a., but I might suspect some performance penalty here
(depending on the configuration every one of these calls causes several files
to be opened and miscellaneous network-traffic to be generated).

As a reasonable compromise I suspect that b. is the most eligible, since
the protocOl number for udp is not likely to change, is it?

What would you consider acceptable practice?

Thanks.
--


Real programmers don't just die, they produce core dumps.

 
 
 

gethostbyname() h_addr vs. h_addr_list[0]

Post by Eric Peters » Fri, 04 Sep 1992 04:29:47



| Now, in order to that, I have to find out the following:
|
|       1. gethostbyname("localhost.or.something.else")
|       2. getservbyname("biff")
|       3. getprotobyname("udp")
|
| Well, so far so good, the only trouble is, these calls are done every time
| when mail arrives.  I was wondering, what is common practice in this case?
|
|       a. Go by the book and make all three calls at runtime?
|       b. Do 1. and 2. at runtime, 3. at compile time?
|       c. Do 1. at runtime, 2. and 3. at compile time?
|       d. Do all three at compile time?  (By compile-time I mean: compile
|          a separate program that makes these calls, and then use the output
|          from this program to hardcode the number(s) in the real program).
|          
| I personally like a., but I might suspect some performance penalty here
| (depending on the configuration every one of these calls causes several files
| to be opened and miscellaneous network-traffic to be generated).

I would consider *ONLY* (a) to be acceptable practice.  These functions
are system database query functions, and the intent of making them
functions and not, say, header file definitions was to sever the dependency
between the code and the data (ie, you wouldn't have to rebuild if you
decided to change the UDP protocol number).

Having said that, you could probably safely get away with hard-coding
these numbers into your code if you wanted to (except for the
gethostbyname() call) since they are so common that they probably
won't change.

Eric

 
 
 

gethostbyname() h_addr vs. h_addr_list[0]

Post by Donn Ca » Thu, 17 Sep 1992 01:38:29




>| Now, in order to that, I have to find out the following:
>|
>|   1. gethostbyname("localhost.or.something.else")
>|   2. getservbyname("biff")
>|   3. getprotobyname("udp")
>|
>| Well, so far so good, the only trouble is, these calls are done every time
>| when mail arrives.  I was wondering, what is common practice in this case?
>|
>|   a. Go by the book and make all three calls at runtime?
>|   b. Do 1. and 2. at runtime, 3. at compile time?
>|   c. Do 1. at runtime, 2. and 3. at compile time?
>|   d. Do all three at compile time?  (By compile-time I mean: compile
>|      a separate program that makes these calls, and then use the output
>|      from this program to hardcode the number(s) in the real program).
...
> I would consider *ONLY* (a) to be acceptable practice.  These functions
> are system database query functions, and the intent of making them
> functions and not, say, header file definitions was to sever the dependency
> between the code and the data (ie, you wouldn't have to rebuild if you
> decided to change the UDP protocol number).
> Having said that, you could probably safely get away with hard-coding
> these numbers into your code if you wanted to (except for the
> gethostbyname() call) since they are so common that they probably
> won't change.

Not only that, but perhaps you don't want to know if they do change.  Maybe
I don't understand something here, but doesn't getservbyname("biff") tell
me what port biff uses on_my_local_system?  If I want to connect to the
"biff" service on "localhost.or.something.else", it's to be hoped that they
will both use the same port, but if they don't, I certainly don't want to
know about the local installation.

/etc/services is a useful way to advertise port numbers between programmers
and system administrators, who otherwise would have no way to reserve a port,
but whether applications should refer to that file is open to question,
depending particularly on the system administration context.

        Donn Cave, University Computing Services, University of Washington

 
 
 

gethostbyname() h_addr vs. h_addr_list[0]

Post by Barry Margol » Thu, 17 Sep 1992 04:54:45



>/etc/services is a useful way to advertise port numbers between programmers
>and system administrators, who otherwise would have no way to reserve a port,
>but whether applications should refer to that file is open to question,
>depending particularly on the system administration context.

Well, it's an unlikely scenario, but suppose someone announces that
starting on October 1, 1992, the standard TELNET port is being changed from
23 to 191.  Having /etc/services (or better yet, an NIS services map) makes
such a conversion much easier than if the port number is hard-coded or
picked up at compile time.

While this is unlikely to happen with an entrenched protocol like TELNET, I
could see it happening with something like authd, given the controversy
between Dan Bernstein and the IETF over which authentication protocol
should be used on the standard port.
--
Barry Margolin
System Manager, Thinking Machines Corp.


 
 
 

gethostbyname() h_addr vs. h_addr_list[0]

Post by Donn Ca » Fri, 18 Sep 1992 02:35:27



|>/etc/services is a useful way to advertise port numbers between programmers
|>and system administrators, who otherwise would have no way to reserve a port,
|>but whether applications should refer to that file is open to question,
|>depending particularly on the system administration context.

| Well, it's an unlikely scenario, but suppose someone announces that
| starting on October 1, 1992, the standard TELNET port is being changed from
| 23 to 191.  Having /etc/services (or better yet, an NIS services map) makes
| such a conversion much easier than if the port number is hard-coded or
| picked up at compile time.

| While this is unlikely to happen with an entrenched protocol like TELNET, I
| could see it happening with something like authd, given the controversy
| between Dan Bernstein and the IETF over which authentication protocol
| should be used on the standard port.

Right - it makes sense to look at /etc/services, if the service is intended
to be available on a globally consistent port number.  Which is a noble
aspiration.

In contrast, if the implementors of the service are resigned to living with
different ports ... for example, our printing system transfers files across
the network like lpd, but with some important differences, and we need to
dedicate ports for that on a number of machines across campus (anything with
a printer).  So far I have heard of no problems with the standard port, but
eventually I'm going to run into someone with another application for that
port.  Fortunately, we're running off a network data base, so I can register
the non-standard port where it counts, where everyone else can see it.  Not
in /etc/services, where it will only be visible where it's of no use.

Sometimes it seems to make sense to me that services should in fact be a
network data base, but if you think looking in a file slows things down ...

        Donn Cave, University Computing Services, University of Washington

 
 
 

gethostbyname() h_addr vs. h_addr_list[0]

Post by Barry Margol » Fri, 18 Sep 1992 04:58:43



>Sometimes it seems to make sense to me that services should in fact be a
>network data base, but if you think looking in a file slows things down ...

If you use NIS, services and protocols *are* network databases.

I doubt that it slows things down too much.  Nothing should be looking up
services inside a critical loop.  Most network programs just make one
lookup when they start up.  Even inetd only looks up all the services and
protocols mentioned in inetd.conf when it starts up or receives a SIGHUP.
--
Barry Margolin
System Manager, Thinking Machines Corp.


 
 
 

gethostbyname() h_addr vs. h_addr_list[0]

Post by Black Lodge Engineeri » Sun, 25 Oct 1992 01:49:04


I am trying to use the "match" function in AWK. The following is a simple
AWK program that uses "match" but doesn't work. Can anyone help me out:

{ MATFLAG = match($0,/??-??-??/) ; print MATFLAG }

 
 
 

gethostbyname() h_addr vs. h_addr_list[0]

Post by Todd Hesema » Sun, 25 Oct 1992 06:43:48



|>
|> I am trying to use the "match" function in AWK. The following is a simple
|> AWK program that uses "match" but doesn't work. Can anyone help me out:
|>
|> { MATFLAG = match($0,/??-??-??/) ; print MATFLAG }

You don't say exactly what you want to do, but if you want to use
wildcards, try this:

   { MATFLAG = match($0,/..-..-../) ; print MATFLAG }

If you want to look for literal question marks, then use this:

   { MATFLAG = match($0,/\?\?-\?\?-\?\?/) ; print MATFLAT }

The question mark must be escaped because it has special meaning.

======================================================================

Empros Systems International                  
phone: (612)-553-4633                        
======================================================================

 
 
 

gethostbyname() h_addr vs. h_addr_list[0]

Post by Tom Christianse » Sat, 31 Oct 1992 02:20:53



:
:I am trying to use the "match" function in AWK. The following is a simple
:AWK program that uses "match" but doesn't work. Can anyone help me out:
:
:{ MATFLAG = match($0,/??-??-??/) ; print MATFLAG }

Even if you are using the new awk which understands match, you need to
use real egrep regexps, not shell style file-glob notation.

--tomm
--

    If you have ever seen the grim word "login:" on a screen, your mind
    is now a wholly-owned subsidiary of The Death Star.

 
 
 

1. gethostbyname h_addr_list

I am trying to get the list of dotted IP's from the domain name. I print out
h_addr_list for each item in the list and get the following:

NAME:
www.yahoo.akadns.net
ALIASES:
www.yahoo.com
IPs:
+ J3+ J4+ J5+ J7+ J2www.yahoo.com
+ J4+ J5+ J7+ J2www.yahoo.com
+ J5+ J7+ J2www.yahoo.com
+ J7+ J2www.yahoo.com
+ J2www.yahoo.com

Aren't these supposed to be dotted IP addresses? What's up with the wierd
characters? Am I supposed to pass h_addr_list[x] through some function to
get the dotted IP?

Blix

2. CANT GET BACK INTO X AFTER LEAVING

3. Linux vs OS2 vs NT vs Win95 vs Multics vs PDP11 vs BSD geeks

4. How to setup Sun Servers to Page me

5. struct hostent: End of h_addr_list

6. Network Puzzle with 2 NICs

7. Perfomance: tar vs ftp vs rsync vs cp vs ?

8. How to use a Wangtel tape drive with Linux

9. Slackware vs SuSE vs Debian vs Redhat vs ....

10. DOS vs. Windows vs. Mac vs. Unix vs. NS

11. KDE vs. Openlook vs. Xfree86 vs. MetroX vs. CDE

12. Redhat vs Debian vs Yggdrasil vs Caldera vs ...

13. BSD vs S5 vs MACH vs OSF/1 (no religion, please!)