function Bind_Port(Socket: TSocket; LocalPort: Integer): Integer;
var
SockNamelen : Integer;
LocalSockName: TSockAddrIn;
Ip, n: String;
begin
GetHostInfo(n, Ip);
FillChar(LocalSockName, Sizeof(LocalSockName), 0);
SockNamelen := sizeof(LocalSockName);
LocalSockName.sin_family := AF_INET;
LocalSockName.sin_port := WSocket_htons(LocalPort);//Port Local
LocalSockName.sin_addr.s_addr := WSocketResolveHost(Ip).s_addr;
result := Bind(Socket, LocalSockName, SockNamelen);
end;
procedure GetHostInfo(var Name, Address: string);
var
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
{ no error checking...}
WSAStartup(2, WSAData);
SetLength(Name, 255);
Gethostname(PChar(Name), 255);
SetLength(Name, StrLen(PChar(Name)));
HostEnt := gethostbyname(PChar(Name));
with HostEnt^ do
Address := Format('%d.%d.%d.%d',[
Byte(h_addr^[0]),
Byte(h_addr^[1]),
Byte(h_addr^[2]),
Byte(h_addr^[3])]);
WSACleanup;
end;
---------------
Des bons sites pour Delphi? http://forum.hardware.fr/forum2.php3?post=16838&cat=10 -- informaticien -- http://www.z0rglub.com/phpwebgallery/ -- Delphi :love: