Deleted Added
full compact
tftpd.c (40765) tftpd.c (45393)
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93";
43#endif
44static const char rcsid[] =
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93";
43#endif
44static const char rcsid[] =
45 "$Id: tftpd.c,v 1.11 1998/04/12 11:15:54 phk Exp $";
45 "$Id: tftpd.c,v 1.12 1998/10/30 16:17:39 dg Exp $";
46#endif /* not lint */
47
48/*
49 * Trivial file transfer protocol server.
50 *
51 * This version includes many modifications by Jim Guyton
52 * <guyton@rand-unix>.
53 */

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

60
61#include <netinet/in.h>
62#include <arpa/tftp.h>
63#include <arpa/inet.h>
64
65#include <ctype.h>
66#include <errno.h>
67#include <fcntl.h>
46#endif /* not lint */
47
48/*
49 * Trivial file transfer protocol server.
50 *
51 * This version includes many modifications by Jim Guyton
52 * <guyton@rand-unix>.
53 */

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

60
61#include <netinet/in.h>
62#include <arpa/tftp.h>
63#include <arpa/inet.h>
64
65#include <ctype.h>
66#include <errno.h>
67#include <fcntl.h>
68#include <libutil.h>
68#include <netdb.h>
69#include <pwd.h>
70#include <setjmp.h>
71#include <signal.h>
72#include <stdio.h>
73#include <stdlib.h>
74#include <string.h>
75#include <syslog.h>

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

103 char *name;
104 int len;
105} dirs[MAXDIRS+1];
106static int suppress_naks;
107static int logging;
108
109static char *errtomsg __P((int));
110static void nak __P((int));
69#include <netdb.h>
70#include <pwd.h>
71#include <setjmp.h>
72#include <signal.h>
73#include <stdio.h>
74#include <stdlib.h>
75#include <string.h>
76#include <syslog.h>

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

104 char *name;
105 int len;
106} dirs[MAXDIRS+1];
107static int suppress_naks;
108static int logging;
109
110static char *errtomsg __P((int));
111static void nak __P((int));
111static char *verifyhost __P((struct sockaddr_in *));
112
113int
114main(argc, argv)
115 int argc;
116 char *argv[];
117{
118 register struct tftphdr *tp;
119 register int n;

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

320 if (strcmp(pf->f_mode, mode) == 0)
321 break;
322 if (pf->f_mode == 0) {
323 nak(EBADOP);
324 exit(1);
325 }
326 ecode = (*pf->f_validate)(&filename, tp->th_opcode);
327 if (logging) {
112
113int
114main(argc, argv)
115 int argc;
116 char *argv[];
117{
118 register struct tftphdr *tp;
119 register int n;

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

320 if (strcmp(pf->f_mode, mode) == 0)
321 break;
322 if (pf->f_mode == 0) {
323 nak(EBADOP);
324 exit(1);
325 }
326 ecode = (*pf->f_validate)(&filename, tp->th_opcode);
327 if (logging) {
328 syslog(LOG_INFO, "%s: %s request for %s: %s",
329 verifyhost(&from),
328 char host[MAXHOSTNAMELEN + 1];
329
330 realhostname(host, sizeof host - 1, &from.sin_addr);
331 host[sizeof host - 1] = '\0';
332 syslog(LOG_INFO, "%s: %s request for %s: %s", host,
330 tp->th_opcode == WRQ ? "write" : "read",
331 filename, errtomsg(ecode));
332 }
333 if (ecode) {
334 /*
335 * Avoid storms of naks to a RRQ broadcast for a relative
336 * bootfile pathname from a diskless Sun.
337 */

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

665 }
666 strcpy(tp->th_msg, pe->e_msg);
667 length = strlen(pe->e_msg);
668 tp->th_msg[length] = '\0';
669 length += 5;
670 if (send(peer, buf, length, 0) != length)
671 syslog(LOG_ERR, "nak: %m");
672}
333 tp->th_opcode == WRQ ? "write" : "read",
334 filename, errtomsg(ecode));
335 }
336 if (ecode) {
337 /*
338 * Avoid storms of naks to a RRQ broadcast for a relative
339 * bootfile pathname from a diskless Sun.
340 */

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

668 }
669 strcpy(tp->th_msg, pe->e_msg);
670 length = strlen(pe->e_msg);
671 tp->th_msg[length] = '\0';
672 length += 5;
673 if (send(peer, buf, length, 0) != length)
674 syslog(LOG_ERR, "nak: %m");
675}
673
674static char *
675verifyhost(fromp)
676 struct sockaddr_in *fromp;
677{
678 struct hostent *hp;
679
680 hp = gethostbyaddr((char *)&fromp->sin_addr, sizeof (fromp->sin_addr),
681 fromp->sin_family);
682 if (hp)
683 return hp->h_name;
684 else
685 return inet_ntoa(fromp->sin_addr);
686}