forked from mirrors/tftp-hpa-google
Fix numeric IPv6 address handling
This patch fix a issue with numeric IPv6 addresses in the tftpd -a address[:port] option. Since IPv6 addresses use colon ':' in differnt counts itself, we cannot detect, if the last colon is a seperator, so it is needed to put the IPv6 address into square brackets, e.g. [2001:db8::1], so a optional port assignment is unambiguous. The patch also allows to specify numeric IPv6 addresses in other places enclosed in [], but in these cases it accept these also without []. Signed-off-by: Karsten Keil <kkeil@suse.de> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
parent
c3a5c712e2
commit
cfb85d4dec
4 changed files with 102 additions and 6 deletions
|
@ -83,6 +83,10 @@ option. The default is to listen to the
|
|||
port specified in
|
||||
.I /etc/services
|
||||
on all local addresses.
|
||||
|
||||
.B Please note:
|
||||
Numeric IPv6 adresses must be enclosed in square brackets
|
||||
to avoid ambiguity with the optional port information.
|
||||
.TP
|
||||
.B \-c
|
||||
Allow new files to be created. By default,
|
||||
|
|
|
@ -256,6 +256,28 @@ static int recv_time(int s, void *rbuf, int len, unsigned int flags,
|
|||
}
|
||||
}
|
||||
|
||||
static int split_port(char **ap, char **pp)
|
||||
{
|
||||
char *a, *p;
|
||||
|
||||
a = *ap;
|
||||
if (is_numeric_ipv6(a)) {
|
||||
if (*a++ != '[')
|
||||
return 1;
|
||||
*ap = a;
|
||||
p = strrchr(a, ']');
|
||||
if (!p)
|
||||
return 1;
|
||||
*p++ = 0;
|
||||
a = p;
|
||||
}
|
||||
p = strrchr(a, ':');
|
||||
if (p)
|
||||
*p++ = 0;
|
||||
*pp = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct tftphdr *tp;
|
||||
|
@ -482,16 +504,19 @@ int main(int argc, char **argv)
|
|||
}
|
||||
#endif
|
||||
if (address) {
|
||||
char *portptr, *eportptr;
|
||||
char *portptr = NULL, *eportptr;
|
||||
int err;
|
||||
struct servent *servent;
|
||||
unsigned long port;
|
||||
|
||||
address = tfstrdup(address);
|
||||
portptr = strrchr(address, ':');
|
||||
if (portptr)
|
||||
*portptr++ = '\0';
|
||||
else
|
||||
err = split_port(&address, &portptr);
|
||||
if (err) {
|
||||
syslog(LOG_ERR,
|
||||
"Numeric IPv6 addresses need to be enclosed in []");
|
||||
exit(EX_USAGE);
|
||||
}
|
||||
if (!portptr)
|
||||
portptr = (char *)"tftp";
|
||||
if (*address) {
|
||||
if (fd4 >= 0) {
|
||||
|
@ -507,6 +532,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
#ifdef HAVE_IPV6
|
||||
if (fd6 >= 0) {
|
||||
bindaddr6.sin6_family = AF_INET6;
|
||||
err = set_sock_addr(address,
|
||||
(union sock_addr *)&bindaddr6, NULL);
|
||||
if (err) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue