On Thu, Oct 03, 2013 at 11:16:19PM -0500, Derek Martin wrote: > What, you want a counter example?
Yes, > http://dev.mutt.org/trac/ticket/3298 This one is a miss. > - Had a working patch 4 years ago. I don't like some parts of your original patch too, by the way. mutt is not an MTA but MUA and MUA may choose to operate offline, so some hacks around libresolv (like reading /etc/resolv.conf) are OK instead of just returning -1: if (gethostname(node, MAXHOSTNAME)) return -1; if (!(h = gethostbyname(node))) return -1; if (!(p = strchr(h->h_name, '.'))) return -1; Then, you removed "#include <string.h>" but used strchr(). This is an obvious error. Also, the gethostname() method is just plain wrong in many situations. E.g., it returns "ckee" domain for my current network: > xrgtn@ux280p:/tmp/domainname$ cat gethostname.c > #include <stdio.h> > #include <string.h> > #include <unistd.h> > #include <netdb.h> > > int main(int argc, char *argv[]) { > char node[255]; > struct hostent *h; > char *p; > if (gethostname(node, 254)) return 1; > if (!(h = gethostbyname(node))) return 1; > if (!(p = strchr(h->h_name, '.'))) return 1; > printf("%s\n", p+1); > return 0; > }; > xrgtn@ux280p:/tmp/domainname$ make gethostname > cc gethostname.c -o gethostname > xrgtn@ux280p:/tmp/domainname$ ./gethostname > ckee > xrgtn@ux280p:/tmp/domainname$ while /etc/resolv.conf would give correct location: > xrgtn@ux280p:/tmp/domainname$ cat getresolvconf.c > #include <stdio.h> > #include <string.h> > #include <unistd.h> > #include <netdb.h> > > int main(int argc, char *argv[]) { > FILE *f; > char tmp[1024]; > char *p = NULL; > char *q; > > if ((f = fopen ("/etc/resolv.conf", "r")) == NULL) return (-1); > tmp[sizeof (tmp) - 1] = 0; > while (fgets (tmp, sizeof (tmp) - 1, f) != NULL) > { > p = tmp; > while (isspace (*p)) p++; > if (strncmp ("domain", p, 6) == 0 > || strncmp ("search", p, 6) == 0) > { > p += 6; > for (q = strtok (p, " \t\n"); q; q = strtok (NULL, " \t\n")) > if (strcmp (q, ".")) > break; > if (q) > printf ("%s\n", q); > } > } > fclose (f); > return 0; > } > xrgtn@ux280p:/tmp/domainname$ make getresolvconf > cc getresolvconf.c -o getresolvconf > xrgtn@ux280p:/tmp/domainname$ ./getresolvconf > umc.com.ua > xrgtn@ux280p:/tmp/domainname$ IMHO it's obvious your patch was wronfg and original implementation is correct. -- With best regards, xrgtn
signature.asc
Description: Digital signature