tbug966.pp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. { Source provided for Free Pascal Bug Report 966 }
  2. {$i-}
  3. {$ifdef linux}
  4. {$define has_sockets}
  5. {$endif linux}
  6. {$ifdef win32}
  7. {$define has_sockets}
  8. {$endif win32}
  9. {$ifdef has_sockets}
  10. uses
  11. {$ifdef linux}
  12. linux,
  13. {$else}
  14. crt,
  15. {$endif}
  16. Sockets;
  17. Var
  18. S : Longint ; Sin,Sout: Text;
  19. Temp, Temp2 : Char;
  20. i : longint;
  21. const
  22. isocket: TInetSockAddr= (
  23. Family:AF_INET;
  24. Port:$1500;
  25. Addr:((93*256+36)*256+161)*256+130);
  26. {*** ftp 130.161.36.93 i.e. ftp.freepascal.org }
  27. { FIXME: it would be much better to have the number
  28. through a name server but I don't know how to do this ! PM }
  29. procedure perror(const S: string);
  30. begin
  31. writeln(S,SocketError);
  32. halt(100) ;
  33. end;
  34. procedure read_to_eof;
  35. var
  36. temp2 : char;
  37. begin
  38. {$ifdef linux}
  39. while selecttext(sin,1)>0 do
  40. begin
  41. read(Sin,Temp2);
  42. write(Temp2);
  43. end;
  44. {$else}
  45. repeat until not eof(sin);
  46. while not eof(sin) do
  47. begin
  48. read(Sin,Temp2);
  49. write(Temp2);
  50. delay(1);
  51. end;
  52. {$endif}
  53. end;
  54. begin
  55. S:=Socket(AF_INET,SOCK_STREAM,0);
  56. if SocketError<>0 then Perror('Client : Socket : ');
  57. WriteLn('*1');
  58. if not Connect(s,isocket,sin,sout)then Perror('Client : Socket : ');
  59. WriteLn('*2');
  60. ReWrite(Sout); Reset(Sin);
  61. WriteLn('*3');
  62. read_to_eof;
  63. Writeln('Sending "USER anonymous#10"');
  64. Write(Sout,'USER anonymous'#10);
  65. read_to_eof;
  66. Writeln('Sending "PASS [email protected]#10"');
  67. Write(Sout,'PASS [email protected]'#10);
  68. read_to_eof;
  69. Writeln('Sending "QUIT#10"');
  70. Write(Sout,'QUIT'#10);
  71. read_to_eof;
  72. shutdown(s,2); close(sin); close(sout);
  73. {$else : not has_sockets}
  74. Writeln('No sockets unit for this target');
  75. {$endif has_sockets}
  76. end.