Download raw body.
inet_aton -> inet_pton conversion: fix error checks
On Thu, Aug 22, 2024 at 08:58:53AM +0200, Florian Obser wrote:
> inet_pton returns 0 and -1 for error.
> Adjust the check that was now wrong after the inet_aton -> inet_pton
> conversion. Noticed by bluhm in ldpd.
>
> I checked all the other conversions I did yesterday and there the error
> checking was correct.
>
> OK?
OK bluhm@
> diff --git bgpctl/parser.c bgpctl/parser.c
> index ee86917744d..7064a739053 100644
> --- bgpctl/parser.c
> +++ bgpctl/parser.c
> @@ -1325,7 +1325,7 @@ parseextvalue(int type, char *s, uint32_t *v, uint32_t *flag)
> *v = uval | (uvalh << 16);
> break;
> case EXT_COMMUNITY_TRANS_IPV4:
> - if (inet_pton(AF_INET, s, &ip) == 0)
> + if (inet_pton(AF_INET, s, &ip) != 1)
> errx(1, "Bad ext-community %s not parseable", s);
> *v = ntohl(ip.s_addr);
> break;
> diff --git bgpd/parse.y bgpd/parse.y
> index d8841db3698..6a5d701a448 100644
> --- bgpd/parse.y
> +++ bgpd/parse.y
> @@ -4503,7 +4503,7 @@ parseextvalue(int type, char *s, uint32_t *v, uint32_t *flag)
> *v = uval | (uvalh << 16);
> break;
> case EXT_COMMUNITY_TRANS_IPV4:
> - if (inet_pton(AF_INET, s, &ip) == 0) {
> + if (inet_pton(AF_INET, s, &ip) != 1) {
> yyerror("Bad ext-community %s not parseable", s);
> return (-1);
> }
> diff --git eigrpd/parse.y eigrpd/parse.y
> index 76118b4072a..32b55587ac4 100644
> --- eigrpd/parse.y
> +++ eigrpd/parse.y
> @@ -223,7 +223,7 @@ varset : STRING '=' string {
> ;
>
> conf_main : ROUTERID STRING {
> - if (!inet_pton(AF_INET, $2, &conf->rtr_id)) {
> + if (inet_pton(AF_INET, $2, &conf->rtr_id) != 1) {
> yyerror("error parsing router-id");
> free($2);
> YYERROR;
> diff --git ldpd/parse.y ldpd/parse.y
> index d35621cc1e0..568f2ca0400 100644
> --- ldpd/parse.y
> +++ ldpd/parse.y
> @@ -203,7 +203,7 @@ string : string STRING {
> ;
>
> routerid : STRING {
> - if (!inet_pton(AF_INET, $1, &$$)) {
> + if (inet_pton(AF_INET, $1, &$$) != 1) {
> yyerror("%s: error parsing router id", $1);
> free($1);
> YYERROR;
>
> --
> In my defence, I have been left unsupervised.
inet_aton -> inet_pton conversion: fix error checks