diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2000-08-01 18:52:51 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2000-08-01 18:52:51 +0000 |
commit | 7c1321862209bc6758fc913b3e4a7f7c50a82119 (patch) | |
tree | 6b2dba427c9b25e1127d2554c4492f65f303585b /usr.sbin | |
parent | 10cade2b871ead893de1b91132edb849c3ad472d (diff) |
for datagram services, support IPv6.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/inetd/inetd.c | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/usr.sbin/inetd/inetd.c b/usr.sbin/inetd/inetd.c index 40e76f396a5..887b57762b1 100644 --- a/usr.sbin/inetd/inetd.c +++ b/usr.sbin/inetd/inetd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inetd.c,v 1.63 2000/07/08 01:57:27 itojun Exp $ */ +/* $OpenBSD: inetd.c,v 1.64 2000/08/01 18:52:50 itojun Exp $ */ /* $NetBSD: inetd.c,v 1.11 1996/02/22 11:14:41 mycroft Exp $ */ /* * Copyright (c) 1983,1991 The Regents of the University of California. @@ -41,7 +41,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)inetd.c 5.30 (Berkeley) 6/3/91";*/ -static char rcsid[] = "$OpenBSD: inetd.c,v 1.63 2000/07/08 01:57:27 itojun Exp $"; +static char rcsid[] = "$OpenBSD: inetd.c,v 1.64 2000/08/01 18:52:50 itojun Exp $"; #endif /* not lint */ /* @@ -609,9 +609,15 @@ main(argc, argv, envp) } int -dg_badinput(sin) - struct sockaddr_in *sin; +dg_badinput(sa) + struct sockaddr *sa; { + struct sockaddr_in *sin; + + if (sa->sa_family != AF_INET) + return (0); + + sin = (struct sockaddr_in *)sa; if (ntohs(sin->sin_port) < IPPORT_RESERVED) return (1); if (sin->sin_addr.s_addr == htonl(INADDR_BROADCAST)) @@ -1742,14 +1748,15 @@ echo_dg(s, sep) /* Echo service -- echo data back */ { char buffer[BUFSIZE]; int i, size; - struct sockaddr sa; + struct sockaddr_storage ss; - size = sizeof(sa); - if ((i = recvfrom(s, buffer, sizeof(buffer), 0, &sa, &size)) < 0) + size = sizeof(ss); + if ((i = recvfrom(s, buffer, sizeof(buffer), 0, (struct sockaddr *)&ss, + &size)) < 0) return; - if (dg_badinput((struct sockaddr_in *)&sa)) + if (dg_badinput((struct sockaddr *)&ss)) return; - (void) sendto(s, buffer, i, 0, &sa, sizeof(sa)); + (void) sendto(s, buffer, i, 0, (struct sockaddr *)&ss, size); } /* ARGSUSED */ @@ -1835,7 +1842,7 @@ chargen_dg(s, sep) /* Character generator */ int s; struct servtab *sep; { - struct sockaddr sa; + struct sockaddr_storage ss; static char *rs; int len, size; char text[LINESIZ+2]; @@ -1845,10 +1852,11 @@ chargen_dg(s, sep) /* Character generator */ rs = ring; } - size = sizeof(sa); - if (recvfrom(s, text, sizeof(text), 0, &sa, &size) < 0) + size = sizeof(ss); + if (recvfrom(s, text, sizeof(text), 0, (struct sockaddr *)&ss, + &size) < 0) return; - if (dg_badinput((struct sockaddr_in *)&sa)) + if (dg_badinput((struct sockaddr *)&ss)) return; if ((len = endring - rs) >= LINESIZ) @@ -1861,7 +1869,7 @@ chargen_dg(s, sep) /* Character generator */ rs = ring; text[LINESIZ] = '\r'; text[LINESIZ + 1] = '\n'; - (void) sendto(s, text, sizeof(text), 0, &sa, sizeof(sa)); + (void) sendto(s, text, sizeof(text), 0, (struct sockaddr *)&ss, size); } /* @@ -1903,19 +1911,18 @@ machtime_dg(s, sep) struct servtab *sep; { u_int result; - struct sockaddr sa; - struct sockaddr_in *sin; + struct sockaddr_storage ss; int size; - size = sizeof(sa); - if (recvfrom(s, (char *)&result, sizeof(result), 0, &sa, &size) < 0) + size = sizeof(ss); + if (recvfrom(s, (char *)&result, sizeof(result), 0, + (struct sockaddr *)&ss, &size) < 0) return; - sin = (struct sockaddr_in *)&sa; - if (sin->sin_addr.s_addr == htonl(INADDR_BROADCAST) || - ntohs(sin->sin_port) < IPPORT_RESERVED/2) + if (dg_badinput((struct sockaddr *)&ss)) return; result = machtime(); - (void) sendto(s, (char *) &result, sizeof(result), 0, &sa, sizeof(sa)); + (void) sendto(s, (char *) &result, sizeof(result), 0, + (struct sockaddr *)&ss, size); } /* ARGSUSED */ @@ -1941,18 +1948,20 @@ daytime_dg(s, sep) /* Return human-readable time of day */ { char buffer[256]; time_t time(), clock; - struct sockaddr sa; + struct sockaddr_storage ss; int size; clock = time((time_t *) 0); - size = sizeof(sa); - if (recvfrom(s, buffer, sizeof(buffer), 0, &sa, &size) < 0) + size = sizeof(ss); + if (recvfrom(s, buffer, sizeof(buffer), 0, (struct sockaddr *)&ss, + &size) < 0) return; - if (dg_badinput((struct sockaddr_in *)&sa)) + if (dg_badinput((struct sockaddr *)&ss)) return; (void) sprintf(buffer, "%.24s\r\n", ctime(&clock)); - (void) sendto(s, buffer, strlen(buffer), 0, &sa, sizeof(sa)); + (void) sendto(s, buffer, strlen(buffer), 0, (struct sockaddr *)&ss, + size); } /* |