On Wed, 26 Oct 2016 22:30:07 +0300
Cyrill Gorcunov <gorcu...@gmail.com> wrote:

>  
>                               if (h->nlmsg_type == NLMSG_DONE) {
> +                                     int len;
> +
> +                                     /*
> +                                      * The kernel reports if there is
> +                                      * no inet-diag module present in
> +                                      * the system via negative length
> +                                      * as error code.
> +                                      */
> +                                     if (h->nlmsg_len < 
> NLMSG_LENGTH(sizeof(int))) {
> +                                             fprintf(stderr, "Truncated 
> length reply\n");
> +                                             return -1;
> +                                     }
> +                                     len = *(int *)NLMSG_DATA(h);
> +                                     if (len < 0) {
> +                                             errno = -len;
> +                                             if (errno == ENOENT ||
> +                                                 errno == EOPNOTSUPP)
> +                                                     return -1;
> +                                             perror("RTNETLINK answers");
> +                                             return len;
> +                                     }
>                                       found_done = 1;
>                                       break; /* process next filter */
>                               

This looks like a mistake in how you implemented the functionality in the 
kernel.
Despite what it looks like, all netlink request/reply functionality reports
errors in current implementation by returning error to the sendmsg request.

What you added implies that the new kernel api is wrong, or many other usages
are wrong.  Please fix the kernel.

Reply via email to