-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGetHostName.pas
More file actions
30 lines (30 loc) · 847 Bytes
/
Copy pathGetHostName.pas
File metadata and controls
30 lines (30 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Function GetHostName(strIPAddress : String) : String;
//
// Retorna o Host onde seu TCP/IP está conectado
//
// Requer a Winsock declarada na clausula uses da unit
//
Var
strHost : String ;
pszIPAddress : PChar ;
pReturnedHostEnt : PHostEnt ;
InternetAddr : u_long ;
GInitData : TWSADATA ;
Begin
strHost := '';
If WSAStartup($101, GInitData) = 0 then
Begin
pszIPAddress := StrAlloc( Length( strIPAddress ) + 1 ) ;
StrPCopy( pszIPAddress, strIPAddress ) ;
InternetAddr := Inet_Addr(pszIPAddress) ;
StrDispose( pszIPAddress ) ;
pReturnedHostEnt := GetHostByAddr( PChar(@InternetAddr),4, PF_INET );
try
strHost := pReturnedHostEnt^.h_name;
WSACleanup;
Result := strHost ;
except
Result := 'Host inválido ou não encontrado';
end;
end;
end;