hs.inc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. function HostAddrToStr (Entry : THostAddr) : String;
  2. Var Dummy : String[4];
  3. I : Longint;
  4. begin
  5. HostAddrToStr:='';
  6. For I:=1 to 4 do
  7. begin
  8. Str(Entry[I],Dummy);
  9. HostAddrToStr:=HostAddrToStr+Dummy;
  10. If I<4 Then
  11. HostAddrToStr:=HostAddrToStr+'.';
  12. end;
  13. end;
  14. function StrToHostAddr(IP : String) : THostAddr ;
  15. Var
  16. Dummy : String;
  17. I : Longint;
  18. J : Integer;
  19. Temp : THostAddr;
  20. begin
  21. Result:=NoAddress;
  22. For I:=1 to 4 do
  23. begin
  24. If I<4 Then
  25. begin
  26. J:=Pos('.',IP);
  27. If J=0 then
  28. exit;
  29. Dummy:=Copy(IP,1,J-1);
  30. Delete (IP,1,J);
  31. end
  32. else
  33. Dummy:=IP;
  34. Val (Dummy,Temp[I],J);
  35. If J<>0 then Exit;
  36. end;
  37. Result:=Temp;
  38. end;
  39. function NetAddrToStr (Entry : TNetAddr) : String;
  40. Var Dummy : String[4];
  41. I : Longint;
  42. begin
  43. NetAddrToStr:='';
  44. For I:=4 downto 1 do
  45. begin
  46. Str(Entry[I],Dummy);
  47. NetAddrToStr:=NetAddrToStr+Dummy;
  48. If I>1 Then
  49. NetAddrToStr:=NetAddrToStr+'.';
  50. end;
  51. end;
  52. function StrToNetAddr(IP : String) : TNetAddr;
  53. begin
  54. StrToNetAddr:=TNetAddr(StrToHostAddr(IP));
  55. end;
  56. Function HostToNet (Host : ThostAddr) : THostAddr;
  57. begin
  58. Result[1]:=Host[4];
  59. Result[2]:=Host[3];
  60. Result[3]:=Host[2];
  61. Result[4]:=Host[1];
  62. end;
  63. Function NetToHost (Net : TNetAddr) : TNetAddr;
  64. begin
  65. Result[1]:=Net[4];
  66. Result[2]:=Net[3];
  67. Result[3]:=Net[2];
  68. Result[4]:=Net[1];
  69. end;
  70. Function HostToNet (Host : Longint) : Longint;
  71. begin
  72. Result:=Longint(HostToNet(THostAddr(host)));
  73. end;
  74. Function NetToHost (Net : Longint) : Longint;
  75. begin
  76. Result:=Longint(NetToHost(TNetAddr(Net)));
  77. end;
  78. Function ShortHostToNet (Host : Word) : Word;
  79. begin
  80. ShortHostToNet:=lo(host)*256+Hi(Host);
  81. end;
  82. Function ShortNetToHost (Net : Word) : Word;
  83. begin
  84. ShortNetToHost:=lo(Net)*256+Hi(Net);
  85. end;