On Wed, Jan 15, 2020 at 01:26:53AM +0100, Klemens Nanni wrote:
> Replace the very same error message strlcpy() uses earlier. This makes
> it easier to distinguish and does not hide different errors behind the
> same generic one.
>
> For example, it turns
>
> # route -qn add -inet6 fec0::% -prefixlen 10 ::1 -reject
> route: fec0::%: bad value
>
> into
>
> # ./obj/route -qn add -inet6 fec0::% -prefixlen 10 ::1 -reject
> route: fec0::%: no address associated with name
>
> Feedback? OK?
Error messages should be unique so you know where to debug.
OK bluhm@
> Index: route.c
> ===
> RCS file: /cvs/src/sbin/route/route.c,v
> retrieving revision 1.246
> diff -u -p -r1.246 route.c
> --- route.c 22 Nov 2019 15:28:05 - 1.246
> +++ route.c 15 Jan 2020 00:20:29 -
> @@ -859,6 +859,7 @@ getaddr(int which, int af, char *s, stru
> sizeof("::::::255:255:255:255/128")
> ];
> char *sep;
> + int error;
>
> if (strlcpy(buf, s, sizeof buf) >= sizeof buf) {
> errx(1, "%s: bad value", s);
> @@ -871,10 +872,12 @@ getaddr(int which, int af, char *s, stru
> hints.ai_family = afamily; /*AF_INET6*/
> hints.ai_flags = AI_NUMERICHOST;
> hints.ai_socktype = SOCK_DGRAM; /*dummy*/
> - if (getaddrinfo(buf, "0", &hints, &res) != 0) {
> + error = getaddrinfo(buf, "0", &hints, &res);
> + if (error) {
> hints.ai_flags = 0;
> - if (getaddrinfo(buf, "0", &hints, &res) != 0)
> - errx(1, "%s: bad value", s);
> + error = getaddrinfo(buf, "0", &hints, &res);
> + if (error)
> + errx(1, "%s: %s", s, gai_strerror(error));
> }
> if (res->ai_next)
> errx(1, "%s: resolved to multiple values", s);