Wow, worked perfectely in Ubuntu-10.04, Mandriva-2010 and openSUSE-11.2.<div><br></div><div>Thanks for the exelent solutions. :)<br><br><div class="gmail_quote">2010/10/7 Brian Winfrey <span dir="ltr"><<a href="mailto:bwcode4u@gmail.com">bwcode4u@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
I found an example for linux on stack overflow that was in c<br>
<a href="http://stackoverflow.com/questions/212528/linux-c-get-the-ip-address-of-local-computer" target="_blank">http://stackoverflow.com/questions/212528/linux-c-get-the-ip-address-of-local-computer</a><br>
<br>
- here is a rough translation:<br>
<br>
program GetPrimaryIpAddress;<br>
{$mode objfpc}<br>
<br>
uses<br>
baseunix,<br>
unixtype,<br>
sockets,<br>
SysUtils;<br>
<br>
procedure Get(var buf: array of char; const len: longint);<br>
const<br>
CN_GDNS_ADDR = '8.8.8.8';<br>
CN_GDNS_PORT = 53;<br>
var<br>
s: string;<br>
sock: longint;<br>
err: longint;<br>
HostAddr: TSockAddr;<br>
l: Integer;<br>
UnixAddr: TInetSockAddr;<br>
<br>
begin<br>
err := 0;<br>
Assert(len >= 16);<br>
<br>
sock := fpsocket(AF_INET, SOCK_DGRAM, 0);<br>
assert(sock <> -1);<br>
<br>
UnixAddr.family := AF_INET;<br>
UnixAddr.port := htons(CN_GDNS_PORT);<br>
UnixAddr.addr := StrToHostAddr(CN_GDNS_ADDR).s_addr;<br>
<br>
if (fpConnect(sock,@UnixAddr,SizeOf(UnixAddr)) = 0) then<br>
begin<br>
try<br>
l := SizeOf(HostAddr);<br>
if (fpgetsockname(sock, @HostAddr, @l) = 0) then<br>
begin<br>
s := NetAddrToStr(HostAddr.sin_addr);<br>
StrPCopy(PChar(Buf), s);<br>
end<br>
else<br>
begin<br>
err:=socketError;<br>
end;<br>
finally<br>
if (fpclose(sock) <> 0) then<br>
begin<br>
err := socketError;<br>
end;<br>
end;<br>
end<br>
else<br>
begin<br>
err:=socketError;<br>
end;<br>
<br>
if (err <> 0) then<br>
begin<br>
// report error<br>
end;<br>
end;<br>
<br>
var<br>
ipbuf: array[0..255] of char;<br>
<br>
begin<br>
system.FillChar(ipbuf, sizeOf(ipBuf), #0);<br>
Get(ipbuf, system.SizeOf(ipbuf));<br>
WriteLn(StrPas(ipbuf));<br>
end.<br>
<br>
BrianW</blockquote></div><br>-- <br>Silvio Clécio,<br><div><span style="font-family:arial"><div><div><span style="font-family:arial"><div><b><span style="color:rgb(204, 204, 204)"><span style="background-color:rgb(68, 68, 68)">programmer</span></span></b><span style="font-family:arial"><span style="font-family:arial"><span style="color:white"><span style="color:rgb(204, 204, 204)"><span style="background-color:rgb(68, 68, 68)"> </span></span><b><span style="color:rgb(68, 68, 68)"><span style="background-color:rgb(68, 68, 68)"><span style="color:rgb(106, 168, 79)">ObjectPascal</span></span></span></b></span></span></span></div>
</span></div></div></span></div>
</div>