Re: [Dnsmasq-discuss] [PATCH] Remove NULL check for intname.

2017-10-05 Thread Kevin Lyda
That's not actually correct in practice.  If you'd like to see that I'm
correct take the following two programs:

foo.c:
#include 
#include 

int main(int argc, char *argv[]) {
  if (strlen(argv[0]) == 0) {
printf("Command empty");
  } else {
printf("Command not empty");
  }
}
bar.c:
#include 
#include 

int main(int argc, char *argv[]) {
  if (*argv[0] == '\0') {
printf("Command empty");
  } else {
printf("Command not empty");
  }
}

Next compile them to assembly like so:

for f in {foo,bar}.c; do gcc -O2 -S $f; done

And then compare them:

diff {foo,bar}.s

They should be the same (possibly different by a ".file" line). And if you
inspect the resulting code, there won't be a call to strlen or to any
function at all (well, except printf).

The reason is that gcc, like most C compilers since the 90s, optimises a
number of common functions in the standard C library. Which means that
developers can stick with writing code that will be well-optimised *and*
highly readable.

Kevin



On Thu, Oct 5, 2017 at 8:31 PM Roy Marples  wrote:

> On 05/10/2017 03:23, Rosen Penev wrote:
> > @@ -1239,7 +1238,7 @@ static struct serverfd *allocate_sfd(union
> mysockaddr *addr, char *intname)
> >   #endif
> >   }
> >
> > -  if (intname && strlen(intname) != 0)
> > +  if (!strlen(intname))
> >   ifindex = if_nametoindex(intname); /* index == 0 when not binding
> to an interface */
> >
> > /* may have a suitable one already */
> >
>
> I have no comment on the functionality of the patch (it if intname needs
> to be NULL checked or not), but this is not a good use of strlen.
>
> This could be re-written as
>
> if (*intname != '\0')
>
> Which saves a function call because the actual length of the string is
> not used.
>
> Roy
>
> ___
> Dnsmasq-discuss mailing list
> Dnsmasq-discuss@lists.thekelleys.org.uk
> http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
>
___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


[Dnsmasq-discuss] Two routers, two dnsmasq instances, can they sync?

2016-12-26 Thread Kevin Lyda
I have two OpenWRT routers which are physically far apart.  One serves
192.168.2, the other serves 192.168.1 and they route between each
other. I'd prefer it if rt1 and rt2 could each manage dhcp on their
respective subnets but I'd like them to have a common view of the
internal DNS.

Is this possible? Is this what server=/192.168.1.1/local.domain/ could
be used for?

Kevin


signature.asc
Description: PGP signature
___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss