Deleted Added
full compact
tftp.c (193189) tftp.c (221358)
1/* $NetBSD: tftp.c,v 1.4 1997/09/17 16:57:07 drochner Exp $ */
2
3/*
4 * Copyright (c) 1996
5 * Matthias Drochner. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 18 unchanged lines hidden (view full) ---

27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
1/* $NetBSD: tftp.c,v 1.4 1997/09/17 16:57:07 drochner Exp $ */
2
3/*
4 * Copyright (c) 1996
5 * Matthias Drochner. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 18 unchanged lines hidden (view full) ---

27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/lib/libstand/tftp.c 193189 2009-05-31 21:29:07Z ed $");
35__FBSDID("$FreeBSD: head/lib/libstand/tftp.c 221358 2011-05-03 04:44:50Z rodrigc $");
36
37/*
38 * Simple TFTP implementation for libsa.
39 * Assumes:
40 * - socket descriptor (int) at open_file->f_devdata
41 * - server host IP in global servip
42 * Restrictions:
43 * - read only

--- 61 unchanged lines hidden (view full) ---

105 ENOSPC,
106 EINVAL, /* ??? */
107 EINVAL, /* ??? */
108 EEXIST,
109 EINVAL /* ??? */
110};
111
112static ssize_t
36
37/*
38 * Simple TFTP implementation for libsa.
39 * Assumes:
40 * - socket descriptor (int) at open_file->f_devdata
41 * - server host IP in global servip
42 * Restrictions:
43 * - read only

--- 61 unchanged lines hidden (view full) ---

105 ENOSPC,
106 EINVAL, /* ??? */
107 EINVAL, /* ??? */
108 EEXIST,
109 EINVAL /* ??? */
110};
111
112static ssize_t
113recvtftp(d, pkt, len, tleft)
114 struct iodesc *d;
115 void *pkt;
116 ssize_t len;
117 time_t tleft;
113recvtftp(struct iodesc *d, void *pkt, ssize_t len, time_t tleft)
118{
119 struct tftphdr *t;
120
121 errno = 0;
122
123 len = readudp(d, pkt, len, tleft);
124
125 if (len < 4)

--- 37 unchanged lines hidden (view full) ---

163 printf("tftp type %d not handled\n", ntohs(t->th_opcode));
164#endif
165 return (-1);
166 }
167}
168
169/* send request, expect first block (or error) */
170static int
114{
115 struct tftphdr *t;
116
117 errno = 0;
118
119 len = readudp(d, pkt, len, tleft);
120
121 if (len < 4)

--- 37 unchanged lines hidden (view full) ---

159 printf("tftp type %d not handled\n", ntohs(t->th_opcode));
160#endif
161 return (-1);
162 }
163}
164
165/* send request, expect first block (or error) */
166static int
171tftp_makereq(h)
172 struct tftp_handle *h;
167tftp_makereq(struct tftp_handle *h)
173{
174 struct {
175 u_char header[HEADER_SIZE];
176 struct tftphdr t;
177 u_char space[FNAME_SIZE + 6];
178 } __packed __aligned(4) wbuf;
179 char *wtail;
180 int l;

--- 26 unchanged lines hidden (view full) ---

207 h->islastblock = 0;
208 if (res < SEGSIZE)
209 h->islastblock = 1; /* very short file */
210 return (0);
211}
212
213/* ack block, expect next */
214static int
168{
169 struct {
170 u_char header[HEADER_SIZE];
171 struct tftphdr t;
172 u_char space[FNAME_SIZE + 6];
173 } __packed __aligned(4) wbuf;
174 char *wtail;
175 int l;

--- 26 unchanged lines hidden (view full) ---

202 h->islastblock = 0;
203 if (res < SEGSIZE)
204 h->islastblock = 1; /* very short file */
205 return (0);
206}
207
208/* ack block, expect next */
209static int
215tftp_getnextblock(h)
216 struct tftp_handle *h;
210tftp_getnextblock(struct tftp_handle *h)
217{
218 struct {
219 u_char header[HEADER_SIZE];
220 struct tftphdr t;
221 } __packed __aligned(4) wbuf;
222 char *wtail;
223 int res;
224 struct tftphdr *t;

--- 16 unchanged lines hidden (view full) ---

241 h->currblock++;
242 h->validsize = res;
243 if (res < SEGSIZE)
244 h->islastblock = 1; /* EOF */
245 return (0);
246}
247
248static int
211{
212 struct {
213 u_char header[HEADER_SIZE];
214 struct tftphdr t;
215 } __packed __aligned(4) wbuf;
216 char *wtail;
217 int res;
218 struct tftphdr *t;

--- 16 unchanged lines hidden (view full) ---

235 h->currblock++;
236 h->validsize = res;
237 if (res < SEGSIZE)
238 h->islastblock = 1; /* EOF */
239 return (0);
240}
241
242static int
249tftp_open(path, f)
250 const char *path;
251 struct open_file *f;
243tftp_open(const char *path, struct open_file *f)
252{
253 struct tftp_handle *tftpfile;
254 struct iodesc *io;
255 int res;
256
257#ifndef __i386__
258 if (strcmp(f->f_dev->dv_name, "net") != 0)
259 return (EINVAL);

--- 22 unchanged lines hidden (view full) ---

282 free(tftpfile);
283 return (res);
284 }
285 f->f_fsdata = (void *) tftpfile;
286 return (0);
287}
288
289static int
244{
245 struct tftp_handle *tftpfile;
246 struct iodesc *io;
247 int res;
248
249#ifndef __i386__
250 if (strcmp(f->f_dev->dv_name, "net") != 0)
251 return (EINVAL);

--- 22 unchanged lines hidden (view full) ---

274 free(tftpfile);
275 return (res);
276 }
277 f->f_fsdata = (void *) tftpfile;
278 return (0);
279}
280
281static int
290tftp_read(f, addr, size, resid)
291 struct open_file *f;
292 void *addr;
293 size_t size;
294 size_t *resid; /* out */
282tftp_read(struct open_file *f, void *addr, size_t size,
283 size_t *resid /* out */)
295{
296 struct tftp_handle *tftpfile;
297 static int tc = 0;
298 tftpfile = (struct tftp_handle *) f->f_fsdata;
299
300 while (size > 0) {
301 int needblock, count;
302

--- 53 unchanged lines hidden (view full) ---

356 }
357
358 if (resid)
359 *resid = size;
360 return (0);
361}
362
363static int
284{
285 struct tftp_handle *tftpfile;
286 static int tc = 0;
287 tftpfile = (struct tftp_handle *) f->f_fsdata;
288
289 while (size > 0) {
290 int needblock, count;
291

--- 53 unchanged lines hidden (view full) ---

345 }
346
347 if (resid)
348 *resid = size;
349 return (0);
350}
351
352static int
364tftp_close(f)
365 struct open_file *f;
353tftp_close(struct open_file *f)
366{
367 struct tftp_handle *tftpfile;
368 tftpfile = (struct tftp_handle *) f->f_fsdata;
369
370 /* let it time out ... */
371
372 if (tftpfile) {
373 free(tftpfile->path);
374 free(tftpfile);
375 }
376 return (0);
377}
378
379static int
354{
355 struct tftp_handle *tftpfile;
356 tftpfile = (struct tftp_handle *) f->f_fsdata;
357
358 /* let it time out ... */
359
360 if (tftpfile) {
361 free(tftpfile->path);
362 free(tftpfile);
363 }
364 return (0);
365}
366
367static int
380tftp_write(f, start, size, resid)
381 struct open_file *f;
382 void *start;
383 size_t size;
384 size_t *resid; /* out */
368tftp_write(struct open_file *f __unused, void *start __unused, size_t size __unused,
369 size_t *resid /* out */ __unused)
385{
386 return (EROFS);
387}
388
389static int
370{
371 return (EROFS);
372}
373
374static int
390tftp_stat(f, sb)
391 struct open_file *f;
392 struct stat *sb;
375tftp_stat(struct open_file *f, struct stat *sb)
393{
394 struct tftp_handle *tftpfile;
395 tftpfile = (struct tftp_handle *) f->f_fsdata;
396
397 sb->st_mode = 0444 | S_IFREG;
398 sb->st_nlink = 1;
399 sb->st_uid = 0;
400 sb->st_gid = 0;
401 sb->st_size = -1;
402 return (0);
403}
404
405static off_t
376{
377 struct tftp_handle *tftpfile;
378 tftpfile = (struct tftp_handle *) f->f_fsdata;
379
380 sb->st_mode = 0444 | S_IFREG;
381 sb->st_nlink = 1;
382 sb->st_uid = 0;
383 sb->st_gid = 0;
384 sb->st_size = -1;
385 return (0);
386}
387
388static off_t
406tftp_seek(f, offset, where)
407 struct open_file *f;
408 off_t offset;
409 int where;
389tftp_seek(struct open_file *f, off_t offset, int where)
410{
411 struct tftp_handle *tftpfile;
412 tftpfile = (struct tftp_handle *) f->f_fsdata;
413
414 switch (where) {
415 case SEEK_SET:
416 tftpfile->off = offset;
417 break;
418 case SEEK_CUR:
419 tftpfile->off += offset;
420 break;
421 default:
422 errno = EOFFSET;
423 return (-1);
424 }
425 return (tftpfile->off);
426}
390{
391 struct tftp_handle *tftpfile;
392 tftpfile = (struct tftp_handle *) f->f_fsdata;
393
394 switch (where) {
395 case SEEK_SET:
396 tftpfile->off = offset;
397 break;
398 case SEEK_CUR:
399 tftpfile->off += offset;
400 break;
401 default:
402 errno = EOFFSET;
403 return (-1);
404 }
405 return (tftpfile->off);
406}