interface
uses WinSock, Sockets, ctypes;
+const
+
+ NI_NOFQDN = $01;
+ NI_NUMERICHOST = $02;
+ NI_NAMEREQD = $04;
+ NI_NUMERICSERV = $08;
+ NI_DGRAM = $10;
+
+
type
PAddrInfo = ^TAddrInfo;
function ResolveHost(HostName: ansistring; Family: cint): TGAIResult;
procedure FreeHost(var GAIResult: TGAIResult);
+ function ResolveIP(AddrInfo: PAddrInfo; Flags: cint): ansistring; overload;
function ResolveIP(AddrInfo: PAddrInfo): ansistring; overload;
+ function ResolveIP(SockAddr: PSockAddr; Flags: cint): ansistring; overload;
function ResolveIP(SockAddr: PSockAddr): ansistring; overload;
function IPToStr(SockAddr: PSockAddr): ansistring;
end;
end;
-function ResolveIP(AddrInfo: PAddrInfo): ansistring;
+function ResolveIP(AddrInfo: PAddrInfo; Flags: cint): ansistring;
var
r: integer;
NodeBuffer: array[0..255] of char;
begin
NodeBuffer[0]:= #0;
- r:= getnameinfo(AddrInfo^.ai_addr, AddrInfo^.ai_addrlen, @NodeBuffer, SizeOf(NodeBuffer), nil, 0, 0);
+ r:= getnameinfo(AddrInfo^.ai_addr, AddrInfo^.ai_addrlen, @NodeBuffer, SizeOf(NodeBuffer), nil, 0, Flags);
if r = 0 then ResolveIP:= PChar(@NodeBuffer)
else ResolveIP:= IPToStr(AddrInfo^.ai_addr);
end;
-function ResolveIP(SockAddr: PSockAddr): ansistring;
+function ResolveIP(AddrInfo: PAddrInfo): ansistring;
+begin
+ ResolveIP:= ResolveIP(AddrInfo, 0);
+end;
+
+function ResolveIP(SockAddr: PSockAddr; Flags: cint): ansistring;
var
AddrInfo: TAddrInfo;
begin
else
AddrInfo.ai_addrlen:= 0;
- ResolveIP:= ResolveIP(PAddrInfo(@AddrInfo));
+ ResolveIP:= ResolveIP(PAddrInfo(@AddrInfo), Flags);
+end;
+
+function ResolveIP(SockAddr: PSockAddr): ansistring;
+begin
+ ResolveIP:= ResolveIP(SockAddr, 0);
end;
function IPToStr(SockAddr: PSockAddr): ansistring;
begin
+{$IFNDEF GNI}
if SockAddr^.sa_family = AF_INET then
IPToStr:= NetAddrToStr(SockAddr^.sin_addr)
else if SockAddr^.sa_family = AF_INET6 then
IPToStr:= NetAddrToStr6(PSockAddr6(SockAddr)^.sin6_addr)
else
IPToStr:= 'unknown';
+{$ELSE}
+ IPToStr:= ResolveIP(SockAddr, NI_NUMERICHOST);
+{$ENDIF}
end;
echo Building for Win32...
echo.
del *.o *.ppu *.a
-fpc -omgsmtp.exe MgSMTP.pas
+fpc -dGNI -omgsmtp.exe MgSMTP.pas
echo Building for Win64...
echo.
del *.o *.ppu *.a
-ppcrossx64 -omgsmtp64.exe MgSMTP.pas
\ No newline at end of file
+ppcrossx64 -dGNI -omgsmtp64.exe MgSMTP.pas
\ No newline at end of file