8 IdUDPBase
, IdUDPClient
,
12 TIdTFTPMode
= (tfNetAscii
, tfOctet
);
17 function MakeAckPkt(const BlockNumber
: Word): string;
18 procedure SendError(UDPBase
: TIdUDPBase
; APeerIP
: string; const APort
: Integer;
19 const ErrNumber
: Word; ErrorString
: string); overload
;
20 procedure SendError(UDPClient
: TIdUDPClient
; const ErrNumber
: Word; ErrorString
:
22 procedure SendError(UDPBase
: TIdUDPBase
; APeerIP
: string; const APort
: Integer;
23 E
: Exception
); overload
;
24 procedure SendError(UDPClient
: TIdUDPClient
; E
: Exception
); overload
;
25 function StrToWord(const Value
: string): Word;
26 function WordToStr(const Value
: Word): WordStr
;
39 sBlockSize
= 'blksize'#0;
44 ErrAccessViolation
= 2;
45 ErrAllocationExceeded
= 3;
46 ErrIllegalOperation
= 4;
47 ErrUnknownTransferID
= 5;
48 ErrFileAlreadyExists
= 6;
50 ErrOptionNegotiationFailed
= 8;
58 function StrToWord(const Value
: string): Word;
60 Result
:= Word(pointer(@Value
[1])^);
63 function WordToStr(const Value
: Word): WordStr
;
65 SetLength(Result
, SizeOf(Value
));
66 Move(Value
, Result
[1], SizeOf(Value
));
69 function MakeAckPkt(const BlockNumber
: Word): string;
71 Result
:= WordToStr(GStack
.WSHToNs(TFTP_ACK
)) +
72 WordToStr(GStack
.WSHToNs(BlockNumber
));
75 procedure SendError(UDPBase
: TIdUDPBase
; APeerIP
: string; const APort
: Integer;
76 const ErrNumber
: Word; ErrorString
: string);
78 UDPBase
.Send(APeerIP
, APort
, WordToStr(GStack
.WSHToNs(TFTP_ERROR
)) +
79 WordToStr(ErrNumber
) + ErrorString
+ #0);
82 procedure SendError(UDPClient
: TIdUDPClient
; const ErrNumber
: Word; ErrorString
:
85 SendError(UDPClient
, UDPClient
.Host
, UDPClient
.Port
, ErrNumber
, ErrorString
);
88 procedure SendError(UDPBase
: TIdUDPBase
; APeerIP
: string; const APort
: Integer;
93 ErrNumber
:= ErrUndefined
;
94 { if E is EIdTFTPFileNotFound then ErrNumber := ErrFileNotFound;
95 if E is EIdTFTPAccessViolation then ErrNumber := ErrAccessViolation;
96 if E is EIdTFTPAllocationExceeded then ErrNumber := ErrAllocationExceeded;
97 if E is EIdTFTPIllegalOperation then ErrNumber := ErrIllegalOperation;
98 if E is EIdTFTPUnknownTransferID then ErrNumber := ErrUnknownTransferID;
99 if E is EIdTFTPFileAlreadyExists then ErrNumber := ErrFileAlreadyExists;
100 if E is EIdTFTPNoSuchUser then ErrNumber := ErrNoSuchUser;
101 if E is EIdTFTPOptionNegotiationFailed then
102 ErrNumber := ErrOptionNegotiationFailed;}
103 SendError(UDPBase
, APeerIP
, APort
, ErrNumber
, E
.Message);
106 procedure SendError(UDPClient
: TIdUDPClient
; E
: Exception
);
108 SendError(UDPClient
, UDPClient
.Host
, UDPClient
.Port
, E
);