[fpc-pascal]getting my local ip

ron wilson ron.wilson at coastgames.com
Fri Mar 15 15:42:02 CET 2002

ok - thats what i thought - so they both point to the same memory area.  my
question is this then:  how do i access the list.  i guess my pascal syntax
is too far gone.  i understand pointers pretty well, but in this case, i'm
lost.  what we have here is a pointer to pchar - ^pchar.  so to access the
first pchar in the list i would code this:

program test;
  pc: pchar;
  h: hostent;
  /* fill h here */

how do i access the second pchar?  the third?  from high school (been a
while) i seem to recall adding 1 to the pointer?  h.h_addr_list^+1?  or
maybe inc(h.h_addr_list^)?  in my program, the first pchar in the list for
the host is almost always - which is a no-brainer.  what i need is
the second or third address in the list, i.e. my modem ip.

the reverend
(: the goodguys :)
icq 83250263

-----Original Message-----
From: fpc-pascal-admin at deadlock.et.tudelft.nl
[mailto:fpc-pascal-admin at deadlock.et.tudelft.nl]On Behalf Of Michael Van
Sent: Friday, March 15, 2002 2:36 AM
To: fpc-pascal at deadlock.et.tudelft.nl
Subject: Re: [fpc-pascal]getting my local ip

On Thu, 14 Mar 2002, ron wilson wrote:

> im having difficulty getting my ip from within a winsock program.  this is
> mainly due to my inability to understand this:
>     type
>        hostent = record
>           { official name of host  }
>           h_name: pchar;
>           { alias list  }
>           h_aliases: ^pchar;
>           { host address type  }
>           h_addrtype: SmallInt;
>           { length of address  }
>           h_length: SmallInt;
>           { list of addresses  }
>           case byte of
>              0: (h_addr_list: ^pchar);
>              1: (h_addr: ^pchar)
>        end;
> how do i understand the case statement?  what does 'case byte of' refer
> in all the c examples i have read, they indicate that h_addr_list should
> contain an array of addresses for the host, i.e. me.  however, the length
> this list is always 4 bytes, which is only one address, and it's always
> same as h_addr, both pointing to the loopback address.  the c examples all
> use h_addr_list as an array.  why isn't this an array here?  im seriously
> confused.

It is not an array here because it is not a real array; It's just a
pointer to a null-terminated list of names.

The h_addr_list and h_addr pointers can be used interchangably. Probably
a name change occurred, and for compatibility reasons both names have
been retained.


fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org

More information about the fpc-pascal mailing list