diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2012-11-24 15:12:49 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2012-11-24 15:12:49 +0000 |
commit | b2856d42893f9d7102ddca106b2ce0f47daca64e (patch) | |
tree | 7d6c983167252826a92df0c73c9da1eaaaed0a03 | |
parent | bbbaec087ecd4abc69d10d21d9b59a895e3aa7ee (diff) |
knf
-rw-r--r-- | lib/libc/asr/asr.c | 48 | ||||
-rw-r--r-- | lib/libc/asr/asr.h | 3 | ||||
-rw-r--r-- | lib/libc/asr/asr_debug.c | 24 | ||||
-rw-r--r-- | lib/libc/asr/asr_private.h | 9 | ||||
-rw-r--r-- | lib/libc/asr/asr_utils.c | 13 | ||||
-rw-r--r-- | lib/libc/asr/getaddrinfo_async.c | 45 | ||||
-rw-r--r-- | lib/libc/asr/gethostnamadr.c | 6 | ||||
-rw-r--r-- | lib/libc/asr/gethostnamadr_async.c | 42 | ||||
-rw-r--r-- | lib/libc/asr/getnameinfo_async.c | 12 | ||||
-rw-r--r-- | lib/libc/asr/getnetnamadr.c | 4 | ||||
-rw-r--r-- | lib/libc/asr/getnetnamadr_async.c | 20 | ||||
-rw-r--r-- | lib/libc/asr/getrrsetbyname_async.c | 18 | ||||
-rw-r--r-- | lib/libc/asr/res_mkquery.c | 4 | ||||
-rw-r--r-- | lib/libc/asr/res_search_async.c | 20 | ||||
-rw-r--r-- | lib/libc/asr/res_send_async.c | 13 |
15 files changed, 141 insertions, 140 deletions
diff --git a/lib/libc/asr/asr.c b/lib/libc/asr/asr.c index 24ea6270439..270f1484304 100644 --- a/lib/libc/asr/asr.c +++ b/lib/libc/asr/asr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asr.c,v 1.13 2012/09/09 16:45:14 eric Exp $ */ +/* $OpenBSD: asr.c,v 1.14 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2010-2012 Eric Faurot <eric@openbsd.org> * @@ -14,9 +14,9 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + #include <sys/types.h> #include <sys/stat.h> - #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> @@ -220,7 +220,7 @@ async_run_sync(struct async *as, struct async_res *ar) struct pollfd fds[1]; int r, saved_errno = errno; - while((r = async_run(as, ar)) == ASYNC_COND) { + while ((r = async_run(as, ar)) == ASYNC_COND) { fds[0].fd = ar->ar_fd; fds[0].events = (ar->ar_cond == ASYNC_READ) ? POLLIN : POLLOUT; again: @@ -269,14 +269,14 @@ void async_free(struct async *as) { DPRINT("asr: async_free(%p)\n", as); - switch(as->as_type) { + switch (as->as_type) { case ASR_SEND: if (as->as_fd != -1) close(as->as_fd); if (as->as.dns.obuf && !(as->as.dns.flags & ASYNC_EXTOBUF)) - free (as->as.dns.obuf); + free(as->as.dns.obuf); if (as->as.dns.ibuf && !(as->as.dns.flags & ASYNC_EXTIBUF)) - free (as->as.dns.ibuf); + free(as->as.dns.ibuf); if (as->as.dns.dname) free(as->as.dns.dname); break; @@ -378,7 +378,7 @@ asr_ctx_unref(struct asr_ctx *ac) DPRINT("asr: asr_ctx_unref(ctx=%p) refcount=%i\n", ac, ac->ac_refcount); if (--ac->ac_refcount) return; - + asr_ctx_free(ac); } @@ -389,9 +389,9 @@ asr_ctx_free(struct asr_ctx *ac) if (ac->ac_domain) free(ac->ac_domain); - for(i = 0; i < ac->ac_nscount; i++) + for (i = 0; i < ac->ac_nscount; i++) free(ac->ac_ns[i]); - for(i = 0; i < ac->ac_domcount; i++) + for (i = 0; i < ac->ac_domcount; i++) free(ac->ac_dom[i]); free(ac); @@ -405,7 +405,7 @@ asr_check_reload(struct asr *asr) { struct asr_ctx *ac; #if ASR_OPT_RELOADCONF - struct stat st; + struct stat st; struct timespec tp; #endif @@ -505,7 +505,7 @@ asr_ndots(const char *s) { int n; - for(n = 0; *s; s++) + for (n = 0; *s; s++) if (*s == '.') n += 1; @@ -567,7 +567,7 @@ strsplit(char *line, char **tokens, int ntokens) int ntok; char *cp, **tp; - for(cp = line, tp = tokens, ntok = 0; + for (cp = line, tp = tokens, ntok = 0; ntok < ntokens && (*tp = strsep(&cp, " \t")) != NULL; ) if (**tp != '\0') { tp++; @@ -613,11 +613,11 @@ pass0(char **tok, int n, struct asr_ctx *ac) if (n - 1 > ASR_MAXDB) return; /* ensure that each lookup is only given once */ - for(i = 1; i < n; i++) - for(j = i + 1; j < n; j++) + for (i = 1; i < n; i++) + for (j = i + 1; j < n; j++) if (!strcmp(tok[i], tok[j])) return; - for(i = 1; i < n; i++, ac->ac_dbcount++) { + for (i = 1; i < n; i++, ac->ac_dbcount++) { if (!strcmp(tok[i], "yp")) { ac->ac_db[i-1] = ASR_DB_YP; } else if (!strcmp(tok[i], "bind")) { @@ -632,10 +632,10 @@ pass0(char **tok, int n, struct asr_ctx *ac) } } else if (!strcmp(tok[0], "search")) { /* resolv.conf says the last line wins */ - for(i = 0; i < ac->ac_domcount; i++) + for (i = 0; i < ac->ac_domcount; i++) free(ac->ac_dom[i]); ac->ac_domcount = 0; - for(i = 1; i < n; i++) + for (i = 1; i < n; i++) asr_ctx_add_searchdomain(ac, tok[i]); } else if (!strcmp(tok[0], "family")) { @@ -650,7 +650,7 @@ pass0(char **tok, int n, struct asr_ctx *ac) ac->ac_family[i - 1] = -1; } else if (!strcmp(tok[0], "options")) { - for(i = 1; i < n; i++) { + for (i = 1; i < n; i++) { if (!strcmp(tok[i], "tcp")) ac->ac_options |= RES_USEVC; else if ((!strncmp(tok[i], "ndots:", 6))) { @@ -692,7 +692,7 @@ asr_ctx_from_string(struct asr_ctx *ac, const char *str) /* If no search domain was specified, use the local subdomains */ if (ac->ac_domcount == 0) - for(ch = ac->ac_domain; ch; ) { + for (ch = ac->ac_domain; ch; ) { asr_ctx_add_searchdomain(ac, ch); ch = strchr(ch, '.'); if (ch && asr_ndots(++ch) == 0) @@ -725,7 +725,7 @@ asr_ctx_from_file(struct asr_ctx *ac, const char *path) if (r == -1) return (-1); buf[r] = '\0'; - + return asr_ctx_from_string(ac, buf); } @@ -821,7 +821,7 @@ asr_parse_nameserver(struct sockaddr *sa, const char *s) return (-1); port++; } - + if (port) { portno = strtonum(port, 1, USHRT_MAX, &estr); if (estr) @@ -886,7 +886,7 @@ asr_parse_namedb_line(FILE *file, char **tokens, int ntoken) char *buf; int ntok; - again: + again: if ((buf = fgetln(file, &len)) == NULL) return (-1); @@ -969,7 +969,7 @@ asr_iter_domain(struct async *as, const char *name, char * buf, size_t len) char *alias; #endif - switch(as->as_dom_step) { + switch (as->as_dom_step) { case DOM_INIT: /* First call */ @@ -1049,7 +1049,7 @@ asr_iter_domain(struct async *as, const char *name, char * buf, size_t len) default: DPRINT("asr: asr_iter_domain(\"%s\") done\n", name); return (-1); - } + } } #if ASR_OPT_HOSTALIASES diff --git a/lib/libc/asr/asr.h b/lib/libc/asr/asr.h index 5002df6885f..da1f2cf2959 100644 --- a/lib/libc/asr/asr.h +++ b/lib/libc/asr/asr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: asr.h,v 1.3 2012/09/06 08:36:52 eric Exp $ */ +/* $OpenBSD: asr.h,v 1.4 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -17,7 +17,6 @@ #include <sys/types.h> #include <sys/socket.h> - #include <netdb.h> #include <netinet/in.h> diff --git a/lib/libc/asr/asr_debug.c b/lib/libc/asr/asr_debug.c index 617aed64649..3c50eeafd86 100644 --- a/lib/libc/asr/asr_debug.c +++ b/lib/libc/asr/asr_debug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asr_debug.c,v 1.9 2012/11/24 13:59:53 eric Exp $ */ +/* $OpenBSD: asr_debug.c,v 1.10 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -14,9 +14,9 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + #include <sys/types.h> #include <sys/socket.h> - #include <netinet/in.h> #include <arpa/nameser.h> #include <arpa/inet.h> @@ -40,7 +40,7 @@ FILE *asr_debug = NULL; static const char * rcodetostr(uint16_t v) { - switch(v) { + switch (v) { case NOERROR: return "NOERROR"; case FORMERR: return "FORMERR"; case SERVFAIL: return "SERVFAIL"; @@ -83,7 +83,7 @@ print_rr(const struct rr *rr, char *buf, size_t max) max -= r; buf += r; - switch(rr->rr_type) { + switch (rr->rr_type) { case T_CNAME: print_dname(rr->rr.cname.cname, buf, max); break; @@ -152,7 +152,7 @@ print_header(const struct header *h, char *buf, size_t max) (h->flags & AA_MASK) ? "AA":" ", (h->flags & TC_MASK) ? "TC":" ", (h->flags & RD_MASK) ? "RD":" ", - (h->flags & RA_MASK) ? "RA":" ", + (h->flags & RA_MASK) ? "RA":" ", ((h->flags & Z_MASK) >> Z_SHIFT), rcodetostr(RCODE(h->flags)), h->qdcount, h->ancount, h->nscount, h->arcount); @@ -268,7 +268,7 @@ asr_dump_config(FILE *f, struct asr *a) fprintf(f, "STATIC CONF\n"); fprintf(f, "DOMAIN \"%s\"\n", ac->ac_domain); fprintf(f, "SEARCH\n"); - for(i = 0; i < ac->ac_domcount; i++) + for (i = 0; i < ac->ac_domcount; i++) fprintf(f, " \"%s\"\n", ac->ac_dom[i]); fprintf(f, "OPTIONS\n"); fprintf(f, " options:"); @@ -292,18 +292,18 @@ asr_dump_config(FILE *f, struct asr *a) fprintf(f, " ndots: %i\n", ac->ac_ndots); fprintf(f, " family:"); - for(i = 0; ac->ac_family[i] != -1; i++) + for (i = 0; ac->ac_family[i] != -1; i++) fprintf(f, " %s", (ac->ac_family[i] == AF_INET)?"inet":"inet6"); fprintf(f, "\n"); fprintf(f, "NAMESERVERS timeout=%i retry=%i\n", - ac->ac_nstimeout, - ac->ac_nsretries); - for(i = 0; i < ac->ac_nscount; i++) + ac->ac_nstimeout, + ac->ac_nsretries); + for (i = 0; i < ac->ac_nscount; i++) fprintf(f, " %s\n", print_sockaddr(ac->ac_ns[i], buf, sizeof buf)); fprintf(f, "HOSTFILE %s\n", ac->ac_hostfile); fprintf(f, "LOOKUP"); - for(i = 0; i < ac->ac_dbcount; i++) { + for (i = 0; i < ac->ac_dbcount; i++) { switch (ac->ac_db[i]) { case ASR_DB_FILE: fprintf(f, " file"); @@ -367,7 +367,7 @@ asr_querystr(int type) const char * asr_transitionstr(int type) { - switch(type) { + switch (type) { CASE(ASYNC_COND); CASE(ASYNC_YIELD); CASE(ASYNC_DONE); diff --git a/lib/libc/asr/asr_private.h b/lib/libc/asr/asr_private.h index c03e9200450..8e17a44dd15 100644 --- a/lib/libc/asr/asr_private.h +++ b/lib/libc/asr/asr_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: asr_private.h,v 1.9 2012/11/24 13:59:53 eric Exp $ */ +/* $OpenBSD: asr_private.h,v 1.10 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -14,6 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + #include <stdio.h> #ifndef ASRNODEBUG @@ -284,7 +285,7 @@ struct async { #define AS_DB(p) ((p)->as_ctx->ac_db[(p)->as_db_idx - 1]) #define AS_FAMILY(p) ((p)->as_ctx->ac_family[(p)->as_family_idx]) - + enum asr_state { ASR_STATE_INIT, ASR_STATE_NEXT_DOMAIN, @@ -339,7 +340,7 @@ struct async *gethostbyaddr_async_ctx(const void *, socklen_t, int, #ifdef DEBUG #define DPRINT(...) do { if(asr_debug) { \ - fprintf(asr_debug, __VA_ARGS__); \ + fprintf(asr_debug, __VA_ARGS__); \ } } while (0) #define DPRINT_PACKET(n, p, s) do { if(asr_debug) { \ fprintf(asr_debug, "----- %s -----\n", n); \ @@ -363,7 +364,7 @@ extern FILE * asr_debug; #endif /* DEBUG */ -#define async_set_state(a, s) do { \ +#define async_set_state(a, s) do { \ DPRINT("asr: [%s@%p] %s -> %s\n", \ asr_querystr((a)->as_type), \ as, \ diff --git a/lib/libc/asr/asr_utils.c b/lib/libc/asr/asr_utils.c index b7f1a38f609..1f35f11e24c 100644 --- a/lib/libc/asr/asr_utils.c +++ b/lib/libc/asr/asr_utils.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asr_utils.c,v 1.2 2012/11/24 13:59:53 eric Exp $ */ +/* $OpenBSD: asr_utils.c,v 1.3 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2009-2012 Eric Faurot <eric@faurot.net> * @@ -17,7 +17,6 @@ #include <sys/types.h> #include <sys/socket.h> - #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> @@ -52,7 +51,7 @@ dname_check_label(const char *s, size_t l) if (l == 0 || l > 63) return (-1); - for(l--; l; l--, s++) + for (l--; l; l--, s++) if (!(isalnum(*s) || *s == '_' || *s == '-')) return (-1); @@ -77,7 +76,7 @@ dname_from_fqdn(const char *str, char *dst, size_t max) return (1); } - for(; *str; str = d + 1) { + for (; *str; str = d + 1) { d = strchr(str, '.'); if (d == NULL || d == str) @@ -122,7 +121,7 @@ dname_expand(const unsigned char *data, size_t len, size_t offset, res = 0; end = start = offset; - for(; (n = data[offset]); ) { + for (; (n = data[offset]); ) { if ((n & 0xc0) == 0xc0) { if (offset + 2 > len) return (-1); @@ -299,7 +298,7 @@ unpack_rr(struct unpack *p, struct rr *rr) save_offset = p->offset; - switch(rr->rr_type) { + switch (rr->rr_type) { case T_CNAME: unpack_dname(p, rr->rr.cname.cname, sizeof(rr->rr.cname.cname)); @@ -400,7 +399,7 @@ pack_header(struct pack *p, const struct header *h) c.qdcount = htons(h->qdcount); c.ancount = htons(h->ancount); c.nscount = htons(h->nscount); - c.arcount = htons(h->arcount); + c.arcount = htons(h->arcount); return (pack_data(p, &c, HFIXEDSZ)); } diff --git a/lib/libc/asr/getaddrinfo_async.c b/lib/libc/asr/getaddrinfo_async.c index 6b1fb63b13c..20f5a2af198 100644 --- a/lib/libc/asr/getaddrinfo_async.c +++ b/lib/libc/asr/getaddrinfo_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo_async.c,v 1.9 2012/11/24 13:59:53 eric Exp $ */ +/* $OpenBSD: getaddrinfo_async.c,v 1.10 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -14,16 +14,10 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + #include <sys/types.h> #include <sys/uio.h> - #include <arpa/nameser.h> - -#include <err.h> -#include <errno.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> #ifdef YP #include <rpc/rpc.h> #include <rpcsvc/yp.h> @@ -31,6 +25,12 @@ #include "ypinternal.h" #endif +#include <err.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + #include "asr.h" #include "asr_private.h" @@ -57,7 +57,7 @@ static const struct match matches[] = { { PF_INET6, SOCK_DGRAM, IPPROTO_UDP }, { PF_INET6, SOCK_STREAM, IPPROTO_TCP }, { PF_INET6, SOCK_RAW, 0 }, - { -1, 0, 0, }, + { -1, 0, 0, }, }; #define MATCH_FAMILY(a, b) ((a) == matches[(b)].family || (a) == PF_UNSPEC) @@ -118,7 +118,7 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) } sa; next: - switch(as->as_state) { + switch (as->as_state) { case ASR_STATE_INIT: @@ -216,7 +216,7 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) /* If hostname is NULL, use local address */ if (as->as.ai.hostname == NULL) { - for(family = iter_family(as, 1); + for (family = iter_family(as, 1); family != -1; family = iter_family(as, 0)) { /* @@ -244,17 +244,16 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) } /* Try numeric addresses first */ - for(family = iter_family(as, 1); + for (family = iter_family(as, 1); family != -1; family = iter_family(as, 0)) { if (sockaddr_from_str(&sa.sa, family, - as->as.ai.hostname) == -1) + as->as.ai.hostname) == -1) continue; - if ((r = addrinfo_add(as, &sa.sa, NULL))) { + if ((r = addrinfo_add(as, &sa.sa, NULL))) ar->ar_gai_errno = r; - } break; } if (ar->ar_gai_errno || as->as_count) { @@ -322,7 +321,7 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) case ASR_STATE_SAME_DB: /* query the current DB again. */ - switch(AS_DB(as)) { + switch (AS_DB(as)) { case ASR_DB_DNS: family = (as->as.ai.hints.ai_family == AF_UNSPEC) ? AS_FAMILY(as) : as->as.ai.hints.ai_family; @@ -442,7 +441,7 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) ar->ar_errno = EOPNOTSUPP; ar->ar_gai_errno = EAI_SYSTEM; async_set_state(as, ASR_STATE_HALT); - break; + break; } goto next; } @@ -515,7 +514,7 @@ addrinfo_add(struct async *as, const struct sockaddr *sa, const char *cname) struct addrinfo *ai; int i, port; - for(i = 0; matches[i].family != -1; i++) { + for (i = 0; matches[i].family != -1; i++) { if (matches[i].family != sa->sa_family || !MATCH_SOCKTYPE(as->as.ai.hints.ai_socktype, i) || !MATCH_PROTO(as->as.ai.hints.ai_protocol, i)) @@ -577,7 +576,7 @@ addrinfo_from_file(struct async *as, int family, FILE *f) struct sockaddr_in6 sain6; } u; - for(;;) { + for (;;) { n = asr_parse_namedb_line(f, tokens, MAXTOKEN); if (n == -1) break; /* ignore errors reading the file */ @@ -622,7 +621,7 @@ addrinfo_from_pkt(struct async *as, char *pkt, size_t pktlen) unpack_init(&p, pkt, pktlen); unpack_header(&p, &h); - for(; h.qdcount; h.qdcount--) + for (; h.qdcount; h.qdcount--) unpack_query(&p, &q); for (i = 0; i < h.ancount; i++) { @@ -640,7 +639,7 @@ addrinfo_from_pkt(struct async *as, char *pkt, size_t pktlen) } else if (rr.rr_type == T_AAAA) { u.sain6.sin6_len = sizeof u.sain6; u.sain6.sin6_family = AF_INET6; - u.sain6.sin6_addr = rr.rr.in_aaaa.addr6; + u.sain6.sin6_addr = rr.rr.in_aaaa.addr6; u.sain6.sin6_port = 0; } else continue; @@ -667,7 +666,7 @@ strsplit(char *line, char **tokens, int ntokens) int ntok; char *cp, **tp; - for(cp = line, tp = tokens, ntok = 0; + for (cp = line, tp = tokens, ntok = 0; ntok < ntokens && (*tp = strsep(&cp, " \t")) != NULL; ) if (**tp != '\0') { tp++; @@ -688,7 +687,7 @@ addrinfo_from_yp(struct async *as, int family, char *line) struct sockaddr_in6 sain6; } u; - for(next = line; line; line = next) { + for (next = line; line; line = next) { if ((next = strchr(line, '\n'))) { *next = '\0'; next += 1; diff --git a/lib/libc/asr/gethostnamadr.c b/lib/libc/asr/gethostnamadr.c index 8bce1116d28..219f36a1532 100644 --- a/lib/libc/asr/gethostnamadr.c +++ b/lib/libc/asr/gethostnamadr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gethostnamadr.c,v 1.1 2012/09/08 11:08:21 eric Exp $ */ +/* $OpenBSD: gethostnamadr.c,v 1.2 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -69,7 +69,7 @@ _fillhostent(const struct hostent *h, struct hostent *r, char *buf, size_t len) r->h_name = pos; pos += n + 1; - for(i = 0; i < naliases; i++) { + for (i = 0; i < naliases; i++) { n = strlcpy(pos, h->h_aliases[i], end - pos); if (n >= end - pos) return; @@ -77,7 +77,7 @@ _fillhostent(const struct hostent *h, struct hostent *r, char *buf, size_t len) pos += n + 1; } - for(i = 0; i < naddrs; i++) { + for (i = 0; i < naddrs; i++) { if (r->h_length > end - pos) return; memmove(pos, h->h_addr_list[i], r->h_length); diff --git a/lib/libc/asr/gethostnamadr_async.c b/lib/libc/asr/gethostnamadr_async.c index 8fc4d48385a..3fa6cef699a 100644 --- a/lib/libc/asr/gethostnamadr_async.c +++ b/lib/libc/asr/gethostnamadr_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gethostnamadr_async.c,v 1.9 2012/11/24 13:59:53 eric Exp $ */ +/* $OpenBSD: gethostnamadr_async.c,v 1.10 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -14,18 +14,12 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + #include <sys/types.h> #include <sys/socket.h> - #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> - -#include <err.h> -#include <errno.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> #ifdef YP #include <rpc/rpc.h> #include <rpcsvc/yp.h> @@ -33,6 +27,12 @@ #include "ypinternal.h" #endif +#include <err.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + #include "asr.h" #include "asr_private.h" @@ -145,7 +145,7 @@ gethostnamadr_async_run(struct async *as, struct async_res *ar) char dname[MAXDNAME], *data; next: - switch(as->as_state) { + switch (as->as_state) { case ASR_STATE_INIT: @@ -175,7 +175,8 @@ gethostnamadr_async_run(struct async *as, struct async_res *ar) case ASR_STATE_NEXT_DOMAIN: - r = asr_iter_domain(as, as->as.hostnamadr.name, dname, sizeof(dname)); + r = asr_iter_domain(as, as->as.hostnamadr.name, dname, + sizeof(dname)); if (r == -1) { async_set_state(as, ASR_STATE_NOT_FOUND); break; @@ -203,7 +204,7 @@ gethostnamadr_async_run(struct async *as, struct async_res *ar) break; } - switch(AS_DB(as)) { + switch (AS_DB(as)) { case ASR_DB_DNS: @@ -314,7 +315,7 @@ gethostnamadr_async_run(struct async *as, struct async_res *ar) } /* Read the hostent from the packet. */ - + ar->ar_hostent = hostent_from_packet(as->as_type, as->as.hostnamadr.family, ar->ar_data, ar->ar_datalen); free(ar->ar_data); @@ -371,7 +372,7 @@ gethostnamadr_async_run(struct async *as, struct async_res *ar) ar->ar_h_errno = NETDB_INTERNAL; ar->ar_gai_errno = EAI_SYSTEM; async_set_state(as, ASR_STATE_HALT); - break; + break; } goto next; } @@ -381,13 +382,14 @@ gethostnamadr_async_run(struct async *as, struct async_res *ar) * name depending on reqtype, and build a hostent from the line. */ static struct hostent * -hostent_file_match(FILE *f, int reqtype, int family, const char *data, int datalen) +hostent_file_match(FILE *f, int reqtype, int family, const char *data, + int datalen) { char *tokens[MAXTOKEN], addr[16]; struct hostent *h; int n, i; - for(;;) { + for (;;) { n = asr_parse_namedb_line(f, tokens, MAXTOKEN); if (n == -1) { errno = 0; /* ignore errors reading the file */ @@ -441,9 +443,9 @@ hostent_from_packet(int reqtype, int family, char *pkt, size_t pktlen) unpack_init(&p, pkt, pktlen); unpack_header(&p, &hdr); - for(; hdr.qdcount; hdr.qdcount--) + for (; hdr.qdcount; hdr.qdcount--) unpack_query(&p, &q); - for(; hdr.ancount; hdr.ancount--) { + for (; hdr.ancount; hdr.ancount--) { unpack_rr(&p, &rr); if (rr.rr_class != C_IN) continue; @@ -594,7 +596,7 @@ addr_as_fqdn(const char *addr, int family, char *dst, size_t max) { const struct in6_addr *in6_addr; in_addr_t in_addr; - + switch (family) { case AF_INET: in_addr = ntohl(*((const in_addr_t *)addr)); @@ -693,7 +695,7 @@ strsplit(char *line, char **tokens, int ntokens) int ntok; char *cp, **tp; - for(cp = line, tp = tokens, ntok = 0; + for (cp = line, tp = tokens, ntok = 0; ntok < ntokens && (*tp = strsep(&cp, " \t")) != NULL; ) if (**tp != '\0') { tp++; @@ -713,7 +715,7 @@ hostent_from_yp(int family, char *line) if ((h = hostent_alloc(family)) == NULL) return (NULL); - for(next = line; line; line = next) { + for (next = line; line; line = next) { if ((next = strchr(line, '\n'))) { *next = '\0'; next += 1; diff --git a/lib/libc/asr/getnameinfo_async.c b/lib/libc/asr/getnameinfo_async.c index 4b251801896..3b2a3da527f 100644 --- a/lib/libc/asr/getnameinfo_async.c +++ b/lib/libc/asr/getnameinfo_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnameinfo_async.c,v 1.4 2012/08/19 16:17:40 eric Exp $ */ +/* $OpenBSD: getnameinfo_async.c,v 1.5 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -14,6 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> @@ -75,7 +76,7 @@ getnameinfo_async_run(struct async *as, struct async_res *ar) int r; next: - switch(as->as_state) { + switch (as->as_state) { case ASR_STATE_INIT: @@ -193,7 +194,7 @@ getnameinfo_async_run(struct async *as, struct async_res *ar) ar->ar_errno = EOPNOTSUPP; ar->ar_gai_errno = EAI_SYSTEM; async_set_state(as, ASR_STATE_HALT); - break; + break; } goto next; } @@ -252,10 +253,9 @@ _numerichost(struct async *as) addr = &as->as.ni.sa.sain.sin_addr; else addr = &as->as.ni.sa.sain6.sin6_addr; - + if (inet_ntop(as->as.ni.sa.sa.sa_family, addr, buf, buflen) == NULL) - /* errno set */ - return (-1); + return (-1); /* errno set */ return (0); } diff --git a/lib/libc/asr/getnetnamadr.c b/lib/libc/asr/getnetnamadr.c index 2831512399f..58a297d681c 100644 --- a/lib/libc/asr/getnetnamadr.c +++ b/lib/libc/asr/getnetnamadr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnetnamadr.c,v 1.1 2012/09/08 11:08:21 eric Exp $ */ +/* $OpenBSD: getnetnamadr.c,v 1.2 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -64,7 +64,7 @@ _fillnetent(const struct netent *e, struct netent *r, char *buf, size_t len) r->n_name = pos; pos += n + 1; - for(i = 0; i < naliases; i++) { + for (i = 0; i < naliases; i++) { n = strlcpy(pos, e->n_aliases[i], end - pos); if (n >= end - pos) return; diff --git a/lib/libc/asr/getnetnamadr_async.c b/lib/libc/asr/getnetnamadr_async.c index eaea8f5f537..a8e10d1ea20 100644 --- a/lib/libc/asr/getnetnamadr_async.c +++ b/lib/libc/asr/getnetnamadr_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnetnamadr_async.c,v 1.5 2012/11/24 13:59:53 eric Exp $ */ +/* $OpenBSD: getnetnamadr_async.c,v 1.6 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -14,13 +14,13 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + #include <sys/types.h> #include <sys/socket.h> - #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> - + #include <err.h> #include <errno.h> #include <stdlib.h> @@ -111,7 +111,7 @@ getnetnamadr_async_run(struct async *as, struct async_res *ar) in_addr_t in; next: - switch(as->as_state) { + switch (as->as_state) { case ASR_STATE_INIT: @@ -132,7 +132,7 @@ getnetnamadr_async_run(struct async *as, struct async_res *ar) break; } - switch(AS_DB(as)) { + switch (AS_DB(as)) { case ASR_DB_DNS: if (as->as_type == ASR_GETNETBYNAME) { @@ -157,7 +157,7 @@ getnetnamadr_async_run(struct async *as, struct async_res *ar) as->as.netnamadr.subq = res_query_async_ctx( name, C_IN, type, NULL, 0, as->as_ctx); } - + if (as->as.netnamadr.subq == NULL) { ar->ar_errno = errno; ar->ar_h_errno = NETDB_INTERNAL; @@ -262,7 +262,7 @@ getnetnamadr_async_run(struct async *as, struct async_res *ar) ar->ar_h_errno = NETDB_INTERNAL; ar->ar_gai_errno = EAI_SYSTEM; async_set_state(as, ASR_STATE_HALT); - break; + break; } goto next; } @@ -275,7 +275,7 @@ netent_file_match(FILE *f, int reqtype, const char *data) int n, i; in_addr_t net; - for(;;) { + for (;;) { n = asr_parse_namedb_line(f, tokens, MAXTOKEN); if (n == -1) { errno = 0; /* ignore errors reading the file */ @@ -326,9 +326,9 @@ netent_from_packet(int reqtype, char *pkt, size_t pktlen) unpack_init(&p, pkt, pktlen); unpack_header(&p, &hdr); - for(; hdr.qdcount; hdr.qdcount--) + for (; hdr.qdcount; hdr.qdcount--) unpack_query(&p, &q); - for(; hdr.ancount; hdr.ancount--) { + for (; hdr.ancount; hdr.ancount--) { unpack_rr(&p, &rr); if (rr.rr_class != C_IN) continue; diff --git a/lib/libc/asr/getrrsetbyname_async.c b/lib/libc/asr/getrrsetbyname_async.c index d673a8896b1..540d13bd4fe 100644 --- a/lib/libc/asr/getrrsetbyname_async.c +++ b/lib/libc/asr/getrrsetbyname_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getrrsetbyname_async.c,v 1.2 2012/08/18 13:49:13 eric Exp $ */ +/* $OpenBSD: getrrsetbyname_async.c,v 1.3 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -14,12 +14,12 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + #include <sys/types.h> #include <sys/uio.h> - #include <netinet/in.h> #include <arpa/nameser.h> - + #include <err.h> #include <errno.h> #include <netdb.h> @@ -67,7 +67,7 @@ static int getrrsetbyname_async_run(struct async *as, struct async_res *ar) { next: - switch(as->as_state) { + switch (as->as_state) { case ASR_STATE_INIT: @@ -116,7 +116,7 @@ getrrsetbyname_async_run(struct async *as, struct async_res *ar) /* No packet received.*/ if (ar->ar_datalen == -1) { - switch(ar->ar_h_errno) { + switch (ar->ar_h_errno) { case HOST_NOT_FOUND: ar->ar_rrset_errno = ERRSET_NONAME; break; @@ -134,7 +134,7 @@ getrrsetbyname_async_run(struct async *as, struct async_res *ar) /* Got a packet but no answer. */ if (ar->ar_count == 0) { free(ar->ar_data); - switch(ar->ar_rcode) { + switch (ar->ar_rcode) { case NXDOMAIN: ar->ar_rrset_errno = ERRSET_NONAME; break; @@ -162,14 +162,14 @@ getrrsetbyname_async_run(struct async *as, struct async_res *ar) default: ar->ar_rrset_errno = ERRSET_FAIL; async_set_state(as, ASR_STATE_HALT); - break; + break; } goto next; } /* The rest of this file is taken from the orignal implementation. */ -/* $OpenBSD: getrrsetbyname_async.c,v 1.2 2012/08/18 13:49:13 eric Exp $ */ +/* $OpenBSD: getrrsetbyname_async.c,v 1.3 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2001 Jakob Schlyter. All rights reserved. @@ -577,7 +577,7 @@ count_dns_rr(struct dns_rr *p, u_int16_t class, u_int16_t type) { int n = 0; - while(p) { + while (p) { if (p->class == class && p->type == type) n++; p = p->next; diff --git a/lib/libc/asr/res_mkquery.c b/lib/libc/asr/res_mkquery.c index 6e2371c868d..21ac2b8534b 100644 --- a/lib/libc/asr/res_mkquery.c +++ b/lib/libc/asr/res_mkquery.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_mkquery.c,v 1.2 2012/11/24 13:59:53 eric Exp $ */ +/* $OpenBSD: res_mkquery.c,v 1.3 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -17,8 +17,8 @@ #include <sys/types.h> #include <netinet/in.h> - #include <arpa/nameser.h> /* for MAXDNAME */ + #include <errno.h> #include <resolv.h> #include <string.h> diff --git a/lib/libc/asr/res_search_async.c b/lib/libc/asr/res_search_async.c index 5ec59e48ecd..915b0fea84e 100644 --- a/lib/libc/asr/res_search_async.c +++ b/lib/libc/asr/res_search_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_search_async.c,v 1.2 2012/09/09 09:42:06 eric Exp $ */ +/* $OpenBSD: res_search_async.c,v 1.3 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -17,9 +17,8 @@ #include <sys/types.h> #include <sys/uio.h> - #include <arpa/nameser.h> - + #include <err.h> #include <errno.h> #include <stdlib.h> @@ -64,7 +63,8 @@ res_search_async_ctx(const char *name, int class, int type, unsigned char *ans, { struct async *as; - DPRINT("asr: res_search_async_ctx(\"%s\", %i, %i)\n", name, class, type); + DPRINT("asr: res_search_async_ctx(\"%s\", %i, %i)\n", name, class, + type); if ((as = async_new(ac, ASR_SEARCH)) == NULL) goto err; /* errno set */ @@ -101,7 +101,7 @@ res_search_async_run(struct async *as, struct async_res *ar) char fqdn[MAXDNAME]; next: - switch(as->as_state) { + switch (as->as_state) { case ASR_STATE_INIT: @@ -110,8 +110,10 @@ res_search_async_run(struct async *as, struct async_res *ar) break; case ASR_STATE_NEXT_DOMAIN: - - /* Reset flags to be able to identify the case in STATE_SUBQUERY. */ + /* + * Reset flags to be able to identify the case in + * STATE_SUBQUERY. + */ as->as_dom_flags = 0; r = asr_iter_domain(as, as->as.search.name, fqdn, sizeof(fqdn)); @@ -128,7 +130,7 @@ res_search_async_run(struct async *as, struct async_res *ar) break; } as->as.search.subq = res_query_async_ctx(fqdn, - as->as.search.class, as->as.search.type, + as->as.search.class, as->as.search.type, as->as.search.ibuf, as->as.search.ibufsize, as->as_ctx); if (as->as.search.subq == NULL) { ar->ar_errno = errno; @@ -215,7 +217,7 @@ res_search_async_run(struct async *as, struct async_res *ar) ar->ar_errno = EOPNOTSUPP; ar->ar_h_errno = NETDB_INTERNAL; async_set_state(as, ASR_STATE_HALT); - break; + break; } goto next; } diff --git a/lib/libc/asr/res_send_async.c b/lib/libc/asr/res_send_async.c index 8e5b96e0a27..72efa178a41 100644 --- a/lib/libc/asr/res_send_async.c +++ b/lib/libc/asr/res_send_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_send_async.c,v 1.5 2012/11/24 13:59:53 eric Exp $ */ +/* $OpenBSD: res_send_async.c,v 1.6 2012/11/24 15:12:48 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -17,7 +17,6 @@ #include <sys/types.h> #include <sys/uio.h> - #include <netinet/in.h> #include <arpa/nameser.h> @@ -169,7 +168,7 @@ static int res_send_async_run(struct async *as, struct async_res *ar) { next: - switch(as->as_state) { + switch (as->as_state) { case ASR_STATE_INIT: @@ -295,7 +294,7 @@ res_send_async_run(struct async *as, struct async_res *ar) ar->ar_count = as->as.dns.ancount; } else { ar->ar_count = 0; - switch(as->as.dns.rcode) { + switch (as->as.dns.rcode) { case NXDOMAIN: ar->ar_h_errno = HOST_NOT_FOUND; break; @@ -316,7 +315,7 @@ res_send_async_run(struct async *as, struct async_res *ar) ar->ar_errno = EOPNOTSUPP; ar->ar_h_errno = NETDB_INTERNAL; async_set_state(as, ASR_STATE_HALT); - break; + break; } goto next; } @@ -728,7 +727,7 @@ validate_packet(struct async *as) goto inval; /* Must be a response */ if ((h.flags & QR_MASK) == 0) - goto inval; + goto inval; as->as.dns.rcode = RCODE(h.flags); as->as.dns.ancount = h.ancount; @@ -752,7 +751,7 @@ validate_packet(struct async *as) } /* Validate the rest of the packet */ - for(r = h.ancount + h.nscount + h.arcount; r; r--) + for (r = h.ancount + h.nscount + h.arcount; r; r--) unpack_rr(&p, &rr); if (p.err || (p.offset != as->as.dns.ibuflen)) |