[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;
var
  pc: pchar;
  h: hostent;
begin
  /* fill h here */
  pc:=stralloc(sizeof(h.h_addr_list^));
  strpcopy(pc,h.h_addr_list^);
  writeln(pc);
end.

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 127.0.0.1 - 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
http://thereverend.coastgames.com/tradewars/


-----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
Canneyt
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
to?
> 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
of
> this list is always 4 bytes, which is only one address, and it's always
the
> 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.

Michael.


_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal





More information about the fpc-pascal mailing list