On 2014-11-19 14:39, Maxim Uvarov wrote:
> On 11/19/2014 12:32 PM, Anders Roxell wrote:
> >On 2014-11-15 12:25, Maxim Uvarov wrote:
> >>On 11/14/2014 10:50 PM, Mike Holmes wrote:
> >>>>+ ret = ioctl(sockfd, SIOCSIFMTU, (caddr_t)&ifr);
> >>>>>+ if (ret) {
> >>> From the ioctl man page
> >>>Usually, on success zero is returned. A few ioctl() requests use the
> >>> return value as an output parameter and return a nonnegative value
> >>> on
> >>> success. On error, -1 is returned, and errno is set appropriately.
> >>>
> >>>So in this case you need to check for (-1==ret)
> >>>
> >>Mike, yes I saw that. But I don't think it's needed for ioctls which I'm
> >>using here. I.e. for SIOCSIFMTU and other. I want them to return 0. Any
> >>other value is error for that ioctls.
> >Every person that reads this will wounder why you check for different
> >for zero instead of different from -1.
> >
> >Be complient with the ioctl manpage please.
> >
> >Cheers,
> >Anders
> You can check:
> 1. if ioctl returned not success (0).
> 2. if ioctl returned error -1.
>
> I prefer to see success in success case. If not success, then rise error.
>
>
> However if it's disputable place I can follow upstream projects code for
> that ioctl:
>
> ifconfig code:
> if (ioctl(skfd, SIOCSIFMTU, &ifr) < 0) {
> fprintf(stderr, "SIOCSIFMTU: %s\n", strerror(errno));
> goterr = 1;
> }
> if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)
>
>
> iproute code:
> err = ioctl(fd, SIOCSIFFLAGS, &ifr);
> if (err)
> perror("SIOCSIFFLAGS");
>
> if (ioctl(s, SIOCSIFMTU, &ifr) < 0) {
> perror("SIOCSIFMTU");
>
>
> Check for <0 is also not clear. I prefer to see success there. But I just
> follow upstream projects.
> Will that work for you?
For simplicity and to remove the need for understanding the meaning of
the return value for the specific ioctl call I think a comparison with
-1 the right thing to do, since this for *all* ioctl calls means error.
Cheers,
Anders
_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp