@@ -74,6 +74,8 @@ struct tftp_client *tftp_client_create(const char *ip_addr, int port)
7474 }
7575 /* Number of Initial Retries */
7676 client -> max_retry = TFTP_MAX_RETRY ;
77+ /* Initialization error number */
78+ client -> err = TFTP_OK ;
7779 /* Binding Private Data */
7880 client -> _private = _private ;
7981 return client ;
@@ -102,6 +104,7 @@ int tftp_client_push(struct tftp_client *client, const char *local_name, const c
102104
103105 _private = client -> _private ;
104106 max_retry = client -> max_retry ;
107+ client -> err = TFTP_OK ;
105108 while (max_retry )
106109 {
107110 /* Send Write Request */
@@ -110,6 +113,7 @@ int tftp_client_push(struct tftp_client *client, const char *local_name, const c
110113 {
111114 tftp_printf ("tftp send request failed !! retry:%d. exit\n" , client -> max_retry - max_retry );
112115 max_retry = 0 ;
116+ client -> err = res ;
113117 break ;
114118 }
115119 /* Waiting for server response */
@@ -121,15 +125,16 @@ int tftp_client_push(struct tftp_client *client, const char *local_name, const c
121125 }
122126 else if (res == - TFTP_ETIMEOUT )
123127 {
124- tftp_printf ("tftp selct timeout. retry\n" );
128+ tftp_printf ("tftp wait response timeout. retry\n" );
125129 max_retry -- ;
126130 continue ;
127131 }
128132 else
129133 {
130134 /* Waiting for Response Error */
131- tftp_printf ("tftp selct err:%d. exit\n" , res );
135+ tftp_printf ("tftp wait response err:%d. exit\n" , res );
132136 max_retry = 0 ;
137+ client -> err = res ;
133138 break ;
134139 }
135140 }
@@ -143,20 +148,23 @@ int tftp_client_push(struct tftp_client *client, const char *local_name, const c
143148 if (res != TFTP_OK )
144149 {
145150 tftp_printf ("wait ack failed!! exit\n" );
151+ client -> err = res ;
146152 return res ;
147153 }
148154 /* Open file */
149155 fp = tftp_file_open (local_name , _private -> xfer -> mode , 1 );
150156 if (fp == NULL )
151157 {
152158 tftp_printf ("open file \"%s\" error.\n" , local_name );
159+ client -> err = - TFTP_EFILE ;
153160 return - TFTP_EFILE ;
154161 }
155162 pack = malloc (sizeof (struct tftp_packet ));
156163 if (pack == NULL )
157164 {
158165 tftp_transfer_err (_private -> xfer , 0 , "malloc pack failed!" );
159166 tftp_file_close (fp );
167+ client -> err = - TFTP_EMEM ;
160168 return - TFTP_EMEM ;
161169 }
162170 while (1 )
@@ -166,6 +174,7 @@ int tftp_client_push(struct tftp_client *client, const char *local_name, const c
166174 if (r_size < 0 )
167175 {
168176 max_retry = 0 ;
177+ client -> err = - TFTP_EFILE ;
169178 break ;
170179 }
171180 max_retry = client -> max_retry ;
@@ -177,6 +186,7 @@ int tftp_client_push(struct tftp_client *client, const char *local_name, const c
177186 {
178187 tftp_transfer_err (_private -> xfer , 0 , "send file err!" );
179188 max_retry = 0 ;
189+ client -> err = - TFTP_EDATA ;
180190 break ;
181191 }
182192 /* Wait server ACK */
@@ -188,14 +198,15 @@ int tftp_client_push(struct tftp_client *client, const char *local_name, const c
188198 }
189199 else if (res == - TFTP_ETIMEOUT )
190200 {
191- tftp_printf ("tftp selct timeout. retry\n" );
201+ tftp_printf ("tftp wait response timeout. retry\n" );
192202 max_retry -- ;
193203 continue ;
194204 }
195205 else
196206 {
197- tftp_printf ("tftp selct err:%d. exit\n" , res );
207+ tftp_printf ("tftp wait response err:%d. exit\n" , res );
198208 max_retry = 0 ;
209+ client -> err = res ;
199210 break ;
200211 }
201212 }
@@ -208,6 +219,7 @@ int tftp_client_push(struct tftp_client *client, const char *local_name, const c
208219 if (tftp_wait_ack (_private -> xfer ) != TFTP_OK )
209220 {
210221 tftp_printf ("wait ack failed!! exit\n" );
222+ client -> err = - TFTP_EACK ;
211223 break ;
212224 }
213225 file_size += r_size ;
@@ -234,6 +246,7 @@ int tftp_client_pull(struct tftp_client *client, const char *remote_name, const
234246
235247 _private = client -> _private ;
236248 max_retry = client -> max_retry ;
249+ client -> err = TFTP_OK ;
237250 while (max_retry )
238251 {
239252 /* Send Read File Request */
@@ -242,6 +255,7 @@ int tftp_client_pull(struct tftp_client *client, const char *remote_name, const
242255 {
243256 tftp_printf ("tftp send request failed !! retry:%d. exit\n" , max_retry );
244257 max_retry = 0 ;
258+ client -> err = res ;
245259 break ;
246260 }
247261 /* Waiting for the server to respond to the request */
@@ -253,16 +267,17 @@ int tftp_client_pull(struct tftp_client *client, const char *remote_name, const
253267 }
254268 else if (res == - TFTP_ETIMEOUT )
255269 {
256- tftp_printf ("tftp selct timeout. retry\n" );
270+ tftp_printf ("tftp wait response timeout. retry\n" );
257271 max_retry -- ;
258272 continue ;
259273 }
260274 else
261275 {
262- tftp_printf ("tftp selct err:%d. exit\n" , res );
276+ tftp_printf ("tftp wait response err:%d. exit\n" , res );
263277 max_retry = 0 ;
278+ client -> err = res ;
264279 break ;
265- }
280+ }
266281 }
267282
268283 /* More than the maximum number of retries. exit */
@@ -276,6 +291,7 @@ int tftp_client_pull(struct tftp_client *client, const char *remote_name, const
276291 if (fp == NULL )
277292 {
278293 tftp_printf ("open file \"%s\" error.\n" , local_name );
294+ client -> err = - TFTP_EFILE ;
279295 return - TFTP_EFILE ;
280296 }
281297 pack = malloc (sizeof (struct tftp_packet ));
@@ -284,6 +300,7 @@ int tftp_client_pull(struct tftp_client *client, const char *remote_name, const
284300 /* malloc failed. send err msg and exit */
285301 tftp_transfer_err (_private -> xfer , 0 , "malloc pack failed!" );
286302 tftp_file_close (fp );
303+ client -> err = - TFTP_EMEM ;
287304 return - TFTP_EMEM ;
288305 }
289306 while (1 )
@@ -294,6 +311,7 @@ int tftp_client_pull(struct tftp_client *client, const char *remote_name, const
294311 if (recv_size < 0 )
295312 {
296313 tftp_printf ("read data err[%d]! exit\n" , recv_size );
314+ client -> err = - TFTP_EDATA ;
297315 break ;
298316 }
299317 /* Write data to file */
@@ -302,6 +320,7 @@ int tftp_client_pull(struct tftp_client *client, const char *remote_name, const
302320 {
303321 tftp_printf ("write file err! exit\n" );
304322 tftp_transfer_err (_private -> xfer , 0 , "write file err!" );
323+ client -> err = - TFTP_EFILE ;
305324 break ;
306325 }
307326 file_size += recv_size ;
@@ -324,13 +343,14 @@ int tftp_client_pull(struct tftp_client *client, const char *remote_name, const
324343 }
325344 else if (res == - TFTP_ETIMEOUT )
326345 {
327- tftp_printf ("tftp selct timeout. retry\n" );
346+ tftp_printf ("tftp wait response timeout. retry\n" );
328347 max_retry -- ;
329348 }
330349 else
331350 {
332- tftp_printf ("tftp selct err:%d. exit\n" , res );
351+ tftp_printf ("tftp wait response err:%d. exit\n" , res );
333352 max_retry = 0 ;
353+ client -> err = res ;
334354 break ;
335355 }
336356 }
@@ -344,3 +364,8 @@ int tftp_client_pull(struct tftp_client *client, const char *remote_name, const
344364 free (pack );
345365 return file_size ;
346366}
367+
368+ int tftp_client_err (struct tftp_client * client )
369+ {
370+ return client -> err ;
371+ }
0 commit comments