diff options
author | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-09 15:50:21 +0200 |
---|---|---|
committer | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-09 15:50:21 +0200 |
commit | 795ffc5e62e8ba383575dbcd9943a580d4bd3358 (patch) | |
tree | c128889056202b255e2f22afeb7717894d350862 | |
parent | 5fadc0cbb8577c61d66bd6f19ceaf0507c11e23b (diff) |
formatting changes
Manual format adjustments.
Comment adjustments.
Remove usage of the register keyword.
80 files changed, 648 insertions, 635 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b010b19 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.cache/ +compile_commands.json @@ -1,21 +1,21 @@ -fehQlibs-09: First public release based on Qlibs as +fehQlibs-09: First public release based on Qlibs as a common project of Kai Peter and Erwin Hoffmann. fehQlibs-10: Added IPV6_V6ONLY setsockoptions call. Improved poll handling in iopause.c considering poll RC. Added building of shared libraries + updated docs. fehQlibs-11: Added ia4_fmt, ia6_fmt and dns_cname (for *qmail). - Changed dns_transmit lookup time constants. + Changed dns_transmit lookup time constants. fehQlibs-12: dns_ip, dns_cname, dns_txt, dns_name and dns_mx - return now the number of DNS answers received - unlike the number of bytes for the given output. + return now the number of DNS answers received + unlike the number of bytes for the given output. Added convenience routines for forthcoming s/qmail. fehQlibs-12a: Fixed missing DNS A lookup in dns_ip.c. -fehQlibs-12b: Removed (one) obsolete return value check +fehQlibs-12b: Removed (one) obsolete return value check for iopause in timeoutconn.c. fehQlibs-12c: Checking carefully all dnsstub return codes - while using a coherent scheme. + while using a coherent scheme. fehQlibs-13: Bugs fixed: str_copy (wrong paranthesis setting) - UI changed: log() -> log_who() + UI changed: log() -> log_who() Added: man str(3) fehQlibs-13a: Fixed wrong input boundary checking for multiple DNSCACHE variables settings in dns_rcip.c. (Tx. J.W.) @@ -24,18 +24,18 @@ fehQlibs-13c: iopause it RC < 0 forces end of connection loop. DNS stub return codes straightend with djbdnscurve6-36. fehQlibs-13d: Fixed integration bugs not displaying IPv6 addresses (dns_ip.c, dns_mx.c). - Wrong dependency check in Makefile for SHAREDLIBS (tx. Alan S.). + Wrong dependency check in Makefile for SHAREDLIBS (tx. Alan S.). fehQlibs-14: Added 'const' for most input arguments + updated man: byte, logmsg, str, pathexec. Patch contributed by Alan S. Added byte_fill and case_upper function (potentially for SRS). Included CLFAGS and LDFLAGS macros in Makefile. fehQlibs-15: Added the Guninski patch for alloc from Qualys (CVE-2005-1513). - dns_ipq (IP qualify) now with unified IPv4/IPv6 handling and evaluation + dns_ipq (IP qualify) now with unified IPv4/IPv6 handling and evaluation of DNS well-know names 'localhost' and 'ipv[4|6]-loopback' (RFC 6761). Fixed DNS lookup for IPv6 addresses. Adjusted DNS man pages. fehQlibs-15a: Again, changes for dns_ipq.c concerning return codes. Should have only impact in case using DJB's qualification format. - Documentation and man page fixes for DNS stub resolver. + Documentation and man page fixes for DNS stub resolver. GCC 10 linker warning for external 'ipv4socket' solved. fehQlibs-15b: GCC 10 compiler issues solved. DNS TLSA record correct value. fehQlibs-16: 19961114 change: dns_ip() now recognizes [1.2.3.4] and [f80::a]. tnx DS. @@ -46,7 +46,7 @@ fehQlibs-16: 19961114 change: dns_ip() now recognizes [1.2.3.4] and [f80::a]. tn fehQlibs-16+: GCC 10.2 conformance; ipv4socket definitition removed in socket_send() and socket_connect(). This is a major desaster: 'external' definitions depend on time-of-usage. -fehQlibs-17: Removed dependency on ipv4socket entirely. +fehQlibs-17: Removed dependency on ipv4socket entirely. Reworked socket interface + doc. Removed obsolete dns_sortip() function. genalloc.h is now separate. Installation of man pages described. fehQlibs-18 @@ -58,7 +58,7 @@ fehQlibs-19 fehQlibs-20 Added uint8p.c functions. Fixed dns_txt.c for multiple labels in RDATA section. fehQlibs-21 - Fixed wrong return code for DNS_COM (tx Franz). + Fixed wrong return code for DNS_COM (tx Franz). Fixed header and man page for env functions and included fd_coe in man fd. fehQlibs-22 Changed ipX_bytestring to return correctly the number of bytes processed. diff --git a/src/dnsstub/README.md b/README_DNSSTUB.md index 95cd11c..95cd11c 100644 --- a/src/dnsstub/README.md +++ b/README_DNSSTUB.md diff --git a/include/buffer.h b/include/buffer.h index 4f513e7..b7e0c8a 100644 --- a/include/buffer.h +++ b/include/buffer.h @@ -1,5 +1,6 @@ #ifndef BUFFER_H #define BUFFER_H + #include <sys/types.h> /* need type: ssize_t */ typedef struct buffer { @@ -11,10 +12,11 @@ typedef struct buffer { } buffer; #define BUFFER_INIT(op, fd, buf, len) {(buf), 0, (len), (fd), (op)} -#define BUFFER_SMALL 256 -#define BUFFER_INSIZE 8192 -#define BUFFER_OUTSIZE 8192 -#define BUFFER_MTUSIZE 1450 + +#define BUFFER_SMALL 256 +#define BUFFER_INSIZE 8192 +#define BUFFER_OUTSIZE 8192 +#define BUFFER_MTUSIZE 1450 extern void buffer_init(buffer *, ssize_t (*op)(), int, char *, size_t); diff --git a/include/byte.h b/include/byte.h index 04337e8..3886127 100644 --- a/include/byte.h +++ b/include/byte.h @@ -2,10 +2,10 @@ #define BYTE_H /** - @file byte.h - @author djb, feh - @source s/qmail - @comment no declaration of argument types; too many compiler errors + @file byte.h + @author djb, feh + @source s/qmail + @comment no declaration of argument types; too many compiler errors */ extern unsigned int byte_chr(); diff --git a/include/dnsresolv.h b/include/dnsresolv.h index 0d01a87..ba388b5 100644 --- a/include/dnsresolv.h +++ b/include/dnsresolv.h @@ -22,7 +22,7 @@ * Revision 20180222, Erwin Hoffmann * - we consider in total 32 NS IPs (IPv4 + IPv6) * - added dns_transmit_start6 - * - added uint32 scope_ids[32], + * - added uint32 scope_ids[32], * the initial NS scopes read from /etc/resolv.conf et al. * Revision 20180118, Erwin Hoffmann * - included MSGSIZE for DNS messages (instead of MTUSIZE) @@ -31,7 +31,7 @@ * Revision 20170902, Erwin Hoffmann * - added old definitions from *qmail for (temp) backwards compatibility * - added more DNS RR definitions -*/ + */ #include "iopause.h" #include "stralloc.h" diff --git a/include/env.h b/include/env.h index 88566cf..26f44b5 100644 --- a/include/env.h +++ b/include/env.h @@ -2,12 +2,12 @@ #define ENV_H /* - * Revision 20171220, Erwin Hoffmann - * - removed variable names - * Revision 20160628, Kai Peter - * - updated code (*env_get) like in ucspi-tcp-0.88 - * - commented out 'env_pick' and 'env_clear' -*/ + * Revision 20171220, Erwin Hoffmann + * - removed variable names + * Revision 20160628, Kai Peter + * - updated code (*env_get) like in ucspi-tcp-0.88 + * - commented out 'env_pick' and 'env_clear' + */ extern char **environ; diff --git a/include/error.h b/include/error.h index 63132ff..0640d71 100644 --- a/include/error.h +++ b/include/error.h @@ -10,14 +10,14 @@ #define error_str(i) errstr(i) extern char *error_str(int); -/* Exception handling notes: +/* Exception handling notes: (1) system errors RECEIVED according to <errno.h> during operation and handed over (2) application errors DEFINED internally and ennumerated alongside with <errno.h> */ /* djb backwards compatibility - deprecated form of system errors */ -/* Comparison of error codes and constants: - intern Linux FreeBSD OmniOS */ +/* Comparison of error codes and constants: + intern Linux FreeBSD OmniOS */ #define error_intr EINTR /* -1 4 4 4 */ #define error_nomem ENOMEM /* -2 12 12 12 */ #define error_noent ENOENT /* -3 2 2 2 */ @@ -35,9 +35,9 @@ extern char *error_str(int); #define error_proto EPROTO /* -15 71 92 71 */ #define error_isdir EISDIR /* -16 21 21 21 */ #define error_connrefused ECONNREFUSED /* -17 111 61 146 */ -//extern int error_notdir; /* -18 20 20 20 */ -#define error_rofs EROFS /* -19 30 30 30 */ -#define error_connreset ECONNRESET /* -20 104 54 131 */ +#define error_rofs EROFS /* -19 30 30 30 */ +#define error_connreset ECONNRESET /* -20 104 54 131 */ +//extern int error_notdir; /* -18 20 20 20 */ /* djb uses some internal application error and class definitions -- revised (feh) */ #define CAT -10 /* raw message w/o terminating \n */ diff --git a/include/exit.h b/include/exit.h index f74b741..8e54239 100644 --- a/include/exit.h +++ b/include/exit.h @@ -2,10 +2,10 @@ #define EXIT_H /** - @file exit.h - @author djb, feh - @source qmail - @brief convenience header + @file exit.h + @author djb, feh + @source qmail + @brief convenience header */ extern void _exit(int); diff --git a/include/fifo.h b/include/fifo.h index 7e7e0f1..ad3d15e 100644 --- a/include/fifo.h +++ b/include/fifo.h @@ -2,9 +2,9 @@ #define FIFO_H /** - @file fifo.h - @author djb, feh - @source s/qmail + @file fifo.h + @author djb, feh + @source s/qmail */ int fifo_make(char *, int); diff --git a/include/fmt.h b/include/fmt.h index e6de428..eb8b8b8 100644 --- a/include/fmt.h +++ b/include/fmt.h @@ -2,11 +2,11 @@ #define FMT_H /** - @file fmt.h - @author djb, kp, feh - @source qmail - @brief conversion function declarations - */ + @file fmt.h + @author djb, kp, feh + @source qmail + @brief conversion function declarations +*/ #define FMT_ULONG 40 /* enough space to hold 2^128 - 1 in decimal, plus \0 */ #define FMT_LEN ((char *)0) /* convenient abbreviation */ diff --git a/include/genalloc.h b/include/genalloc.h index d27c6b1..351fb98 100644 --- a/include/genalloc.h +++ b/include/genalloc.h @@ -2,28 +2,31 @@ #define GENALLOC_H /* - * Revision 20210307, Erwin Hoffmann - * - -*/ + * Revision 20210307, Erwin Hoffmann + * - + */ #include <sys/types.h> -/* GEN_ALLOC demystified: - - GEN_ALLOC generates a list of self-defined types (structs) in an - allocated contiguous heap chunk while copying the content of the - entire field members or appending the existing field. - GEN_ALLOC types care of currently used and/or allocated bytes of field. +#include "alloc.h" + +/* + GEN_ALLOC demystified: -Macros: - GEN_ALLOC_ready (ta,type,field,len,a,i,n,x,base,ta_ready) - GEN_ALLOC_readyplus(ta,type,field,len,a,i,n,x,base,ta_rplus) - GEN_ALLOC_append (ta,type,field,len,a,i,n,x,base,ta_rplus,ta_append) + GEN_ALLOC generates a list of self-defined types (structs) in an + allocated contiguous heap chunk while copying the content of the + entire field members or appending the existing field. + GEN_ALLOC types care of currently used and/or allocated bytes of field. + + Macros: + GEN_ALLOC_ready (ta,type,field,len,a,i,n,x,base,ta_ready) + GEN_ALLOC_readyplus(ta,type,field,len,a,i,n,x,base,ta_rplus) + GEN_ALLOC_append (ta,type,field,len,a,i,n,x,base,ta_rplus,ta_append) 0. ta: 'type alloc' - typedef'ed struct name (aka ipalloc et al.) - 1. type: defined struct (used for size information) + 1. type: defined struct (used for size information) 2. field: declared public name of struct - 2. len: used length of string + 2. len: used length of string 4. a: allocated size 5. i: current allocated size for member x 6. n: bytes to allocate; in 'ready' mode: +size of one entry; @@ -32,7 +35,6 @@ Macros: 8. base: size of single entry 9. ta_ready/ta_readyplus (operation) 10. ta_append (operation) - */ /* file: gen_alloc.h */ @@ -46,11 +48,9 @@ Macros: /* file: gen_allocdefs.h (deprecated) */ // used in: ipalloc, prioq, qmail-remote, qmail-inject, token822 #define GEN_ALLOC_ready(ta, type, field, len, a, i, n, x, base, ta_ready) \ - int ta_ready(x, n) \ - register ta *x; \ - register unsigned int n; \ + int ta_ready(ta *x, unsigned int n) \ { \ - register unsigned int i; \ + unsigned int i; \ if (x->field) { \ i = x->a; \ if (n > i) { \ @@ -66,11 +66,9 @@ Macros: } #define GEN_ALLOC_readyplus(ta, type, field, len, a, i, n, x, base, ta_rplus) \ - int ta_rplus(x, n) \ - register ta *x; \ - register unsigned int n; \ + int ta_rplus(ta *x, unsigned int n) \ { \ - register unsigned int i; \ + unsigned int i; \ if (x->field) { \ i = x->a; \ n += x->len; \ @@ -87,9 +85,7 @@ Macros: } #define GEN_ALLOC_append(ta, type, field, len, a, i, n, x, base, ta_rplus, ta_append) \ - int ta_append(x, i) \ - register ta *x; \ - register type *i; \ + int ta_append(ta *x, type *i) \ { \ if (!ta_rplus(x, 1)) return 0; \ x->field[x->len++] = *i; \ diff --git a/include/getoptb.h b/include/getoptb.h index 61fa7aa..426567d 100644 --- a/include/getoptb.h +++ b/include/getoptb.h @@ -2,9 +2,9 @@ #define BGETOPT_H /* - * Revision 20160714, Kai Peter - * - consolidated 'sgetopt.h' and 'subgetopt.h' into '(b)getopt.h' -*/ + * Revision 20160714, Kai Peter + * - consolidated 'sgetopt.h' and 'subgetopt.h' into '(b)getopt.h' + */ #define optarg subgetoptarg #define optind subgetoptind diff --git a/include/lock.h b/include/lock.h index 74df4c9..6abecb7 100644 --- a/include/lock.h +++ b/include/lock.h @@ -2,9 +2,9 @@ #define LOCK_H /** - @file lock.h - @author djb, feh - @source s/qmail + @file lock.h + @author djb, feh + @source s/qmail */ int lock_ex(int); diff --git a/include/ndelay.h b/include/ndelay.h index 7a03a8d..6791c5b 100644 --- a/include/ndelay.h +++ b/include/ndelay.h @@ -2,9 +2,9 @@ #define NDELAY_H /** - @brief ndelay.h - @author djb, feh - @source s/qmail + @brief ndelay.h + @author djb, feh + @source s/qmail */ int ndelay_on(int); diff --git a/include/open.h b/include/open.h index 428ebfb..c2f272b 100644 --- a/include/open.h +++ b/include/open.h @@ -2,9 +2,9 @@ #define OPEN_H /** - @file open.h - @author djb, feh - @source s/qmail + @file open.h + @author djb, feh + @source s/qmail */ int open_read(const char *); diff --git a/include/uint_t.h b/include/uint_t.h index aba0f38..7bf32c8 100644 --- a/include/uint_t.h +++ b/include/uint_t.h @@ -1,11 +1,11 @@ #include <stdint.h> /** - @file uint_t.h - @author djb, kp, feh - @source qmail, djbdns6 - @brief additional types and pack routines - @brief define basic integer types and size through <stdint.h> + @file uint_t.h + @author djb, kp, feh + @source qmail, djbdns6 + @brief additional types and pack routines + @brief define basic integer types and size through <stdint.h> */ #ifndef UINT8_H diff --git a/include/wait.h b/include/wait.h index af8a979..dd059d9 100644 --- a/include/wait.h +++ b/include/wait.h @@ -2,9 +2,9 @@ #define WAIT_H /** - @file wait.h - @author djb - @source s/qmail + @file wait.h + @author djb + @source s/qmail */ int wait_pid(int *, int); diff --git a/src/base64.c b/src/base64.c index 636874e..33b54e6 100644 --- a/src/base64.c +++ b/src/base64.c @@ -4,10 +4,10 @@ #include "stralloc.h" /** - @file base64.c - @author unkown - @source unknown - @brief base64 en+decoding of strings + @file base64.c + @author unkown + @source unknown + @brief base64 en+decoding of strings */ static char *b64alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; diff --git a/src/buffer.c b/src/buffer.c index c30caf2..036b298 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -7,9 +7,9 @@ #include "str.h" /** - @file buffer.c - @author djb - @brief input/output routines + @file buffer.c + @author djb + @brief input/output routines */ void buffer_init(buffer *s, ssize_t (*op)(), int fd, char *buf, size_t len) @@ -1,18 +1,16 @@ #include "byte.h" /** - @file byte.c - @author djb - @brief byte manipulation functions + @file byte.c + @author djb + @brief byte manipulation functions */ -unsigned int byte_chr(char *s, register unsigned int n, int c) +unsigned int byte_chr(char *s, unsigned int n, int c) { - register char ch; - register char *t; + char ch = c; + char *t = s; - ch = c; - t = s; for (;;) { // clang-format off if (!n) { break; } if (*t == ch) { break; } ++t; --n; @@ -24,7 +22,7 @@ unsigned int byte_chr(char *s, register unsigned int n, int c) return t - s; } -void byte_copy(register char *to, register unsigned int n, register char *from) +void byte_copy(char *to, unsigned int n, char *from) { for (;;) { // clang-format off @@ -36,7 +34,7 @@ void byte_copy(register char *to, register unsigned int n, register char *from) } } -void byte_copyr(register char *to, register unsigned int n, register char *from) +void byte_copyr(char *to, unsigned int n, char *from) { to += n; from += n; @@ -51,7 +49,7 @@ void byte_copyr(register char *to, register unsigned int n, register char *from) } } -int byte_diff(register char *s, register unsigned int n, register char *t) +int byte_diff(char *s, unsigned int n, char *t) { for (;;) { // clang-format off @@ -64,30 +62,25 @@ int byte_diff(register char *s, register unsigned int n, register char *t) return ((int)(unsigned int)(unsigned char)*s) - ((int)(unsigned int)(unsigned char)*t); } -unsigned int byte_rchr(char *s, register unsigned int n, int c) +unsigned int byte_rchr(char *s, unsigned int n, int c) { - register char ch; - register char *t; - register char *u; + char ch = c; + char *t = s; + char *u = 0; - ch = c; - t = s; - u = 0; for (;;) { // clang-format off - if (!n) { break; } if (*t == ch) { u = t; } ++t; --n; - if (!n) { break; } if (*t == ch) { u = t; } ++t; --n; + if (!n) { break; } if (*t == ch) { u = t; } ++t; --n; + if (!n) { break; } if (*t == ch) { u = t; } ++t; --n; if (!n) { break; } if (*t == ch) { u = t; } ++t; --n; if (!n) { break; } if (*t == ch) { u = t; } ++t; --n; // clang-format on } - if (!u) { - u = t; - } + if (!u) u = t; return u - s; } -void byte_zero(char *s, register unsigned int n) +void byte_zero(char *s, unsigned int n) { for (;;) { // clang-format off @@ -99,11 +92,10 @@ void byte_zero(char *s, register unsigned int n) } } -void byte_fill(char *s, register unsigned int n, const int c) +void byte_fill(char *s, unsigned int n, int c) { - register char ch; + char ch = c; - ch = c; for (;;) { // clang-format off if (!n) { break; } *s++ = ch; --n; @@ -3,15 +3,15 @@ #include "str.h" /** - @file case.c - @author djb - @brief string comparison and helper functions; case insensitive + @file case.c + @author djb + @brief string comparison and helper functions; case insensitive */ -int case_diffb(register char *s, unsigned int len, register char *t) +int case_diffb(char *s, unsigned int len, char *t) { - register unsigned char x; - register unsigned char y; + unsigned char x; + unsigned char y; while (len > 0) { --len; @@ -30,10 +30,10 @@ int case_diffb(register char *s, unsigned int len, register char *t) return 0; } -int case_diffs(register char *s, register char *t) +int case_diffs(char *s, char *t) { - register unsigned char x; - register unsigned char y; + unsigned char x; + unsigned char y; for (;;) { x = *s++ - 'A'; @@ -52,10 +52,10 @@ int case_diffs(register char *s, register char *t) return ((int)(unsigned int)x) - ((int)(unsigned int)y); } -int case_diffrs(register char *s, register char *t) +int case_diffrs(char *s, char *t) { - register unsigned char x = 0; - register unsigned char y = 0; + unsigned char x = 0; + unsigned char y = 0; unsigned int lens = str_len(s); unsigned int lent = str_len(t); @@ -119,10 +119,10 @@ void case_uppers(char *s) } } -int case_startb(register char *s, unsigned int len, register char *t) +int case_startb(char *s, unsigned int len, char *t) { - register unsigned char x; - register unsigned char y; + unsigned char x; + unsigned char y; for (;;) { y = *t++ - 'A'; @@ -142,10 +142,10 @@ int case_startb(register char *s, unsigned int len, register char *t) } } -int case_starts(register char *s, register char *t) +int case_starts(char *s, char *t) { - register unsigned char x; - register unsigned char y; + unsigned char x; + unsigned char y; for (;;) { x = *s++ - 'A'; diff --git a/src/cdbmake.c b/src/cdbmake.c index 47bb420..d1464d1 100644 --- a/src/cdbmake.c +++ b/src/cdbmake.c @@ -8,10 +8,10 @@ #include "seek.h" /** - @file cdbmake.c - @author djb - @source ucspi-tcp - @brief constant data base (cdb) generation + @file cdbmake.c + @author djb + @source ucspi-tcp + @brief constant data base (cdb) generation */ int cdb_make_start(struct cdb_make *c, int fd) diff --git a/src/cdbread.c b/src/cdbread.c index 802c726..8ba920c 100644 --- a/src/cdbread.c +++ b/src/cdbread.c @@ -10,10 +10,10 @@ #include "seek.h" /** - @file cdbread.c - @author djb - @source ucspi-tcp, fastforward - @brief read entries from a cdb + @file cdbread.c + @author djb + @source ucspi-tcp, fastforward + @brief read entries from a cdb */ uint32 cdb_unpack(unsigned char *buf) diff --git a/src/dnsstub/dns_cname.c b/src/dnsstub/dns_cname.c index d1ea110..1235f06 100644 --- a/src/dnsstub/dns_cname.c +++ b/src/dnsstub/dns_cname.c @@ -6,9 +6,9 @@ #include "uint_t.h" /** - @file dns_cname.c - @author feh - @brief DNS cname lookup + @file dns_cname.c + @author feh + @brief DNS cname lookup */ static char *q = 0; diff --git a/src/dnsstub/dns_dfd.c b/src/dnsstub/dns_dfd.c index 645d068..832bd6e 100644 --- a/src/dnsstub/dns_dfd.c +++ b/src/dnsstub/dns_dfd.c @@ -4,10 +4,10 @@ #include "error.h" /** - @file dns_dfd.c - @author djb - @source ucspi-tcp - @brief domain name qualification (domain from dot) + @file dns_dfd.c + @author djb + @source ucspi-tcp + @brief domain name qualification (domain from dot) */ int dns_domain_fromdot(char **out, const char *buf, unsigned int n) diff --git a/src/dnsstub/dns_domain.c b/src/dnsstub/dns_domain.c index 4ee7ba3..dcdf2f2 100644 --- a/src/dnsstub/dns_domain.c +++ b/src/dnsstub/dns_domain.c @@ -4,10 +4,10 @@ #include "dnsresolv.h" /** - @file dns_domain.c - @author djb - @source ucspi-tcp - @brief domain qualification + @file dns_domain.c + @author djb + @source ucspi-tcp + @brief domain qualification */ unsigned int dns_domain_length(const char *dn) diff --git a/src/dnsstub/dns_dtda.c b/src/dnsstub/dns_dtda.c index 13e6051..f1b7d58 100644 --- a/src/dnsstub/dns_dtda.c +++ b/src/dnsstub/dns_dtda.c @@ -2,10 +2,10 @@ #include "stralloc.h" /** - @file dns_dtda.c - @author djb - @source ucspi-tcp - @brief domain to dot append + @file dns_dtda.c + @author djb + @source ucspi-tcp + @brief domain to dot append */ int dns_domain_todot_cat(stralloc *out, const char *d) diff --git a/src/dnsstub/dns_ip.c b/src/dnsstub/dns_ip.c index 0a63022..913c310 100644 --- a/src/dnsstub/dns_ip.c +++ b/src/dnsstub/dns_ip.c @@ -5,10 +5,10 @@ #include "uint_t.h" /** - @file dns_ip.c - @author djb, fefe, feh - @source ucspi-tcp6 - @brief DNS IP query + @file dns_ip.c + @author djb, fefe, feh + @source ucspi-tcp6 + @brief DNS IP query */ static char *q = 0; diff --git a/src/dnsstub/dns_ipq.c b/src/dnsstub/dns_ipq.c index d1a40e5..49049b5 100644 --- a/src/dnsstub/dns_ipq.c +++ b/src/dnsstub/dns_ipq.c @@ -7,14 +7,14 @@ #include "stralloc.h" /** - @file dns_ipq.c - @author djb, feh - @source ucspi-tcp - @brief DNS hostname qualification for ipv4 and ipv6 + @file dns_ipq.c + @author djb, feh + @source ucspi-tcp + @brief DNS hostname qualification for ipv4 and ipv6 */ -/** - @fn int doit -> @return number of added chars to name +/** + @fn int doit -> @return number of added chars to name */ static int doit(stralloc *work, const char *rule) { diff --git a/src/dnsstub/dns_mx.c b/src/dnsstub/dns_mx.c index 3a140d2..967999e 100644 --- a/src/dnsstub/dns_mx.c +++ b/src/dnsstub/dns_mx.c @@ -4,11 +4,11 @@ #include "uint_t.h" /** - @file dns_mx.c - @author djb - @source qmail - @brief dns MX query - @param (on output) stralloc out + @file dns_mx.c + @author djb + @source qmail + @brief dns MX query + @param (on output) stralloc out */ static char *q = 0; @@ -37,7 +37,7 @@ int dns_mx_packet(stralloc *out, const char *buf, unsigned int len) pos = dns_packet_copy(buf, len, pos, header, 10); if (!pos) return DNS_ERR; uint16_unpack_big(header + 8, &datalen); - if (byte_equal(header, 2, DNS_T_MX)) + if (byte_equal(header, 2, DNS_T_MX)) { if (byte_equal(header + 2, 2, DNS_C_IN)) { if (!dns_packet_copy(buf, len, pos, pref, 2)) return DNS_ERR; if (!dns_packet_getname(buf, len, pos + 2, &q)) return DNS_ERR; @@ -45,6 +45,7 @@ int dns_mx_packet(stralloc *out, const char *buf, unsigned int len) if (dns_domain_todot_cat(out, q) <= 0) return DNS_ERR; if (!stralloc_0(out)) return DNS_MEM; } + } pos += datalen; ++ranswers; } diff --git a/src/dnsstub/dns_name.c b/src/dnsstub/dns_name.c index db4565a..1802143 100644 --- a/src/dnsstub/dns_name.c +++ b/src/dnsstub/dns_name.c @@ -5,10 +5,10 @@ #include "uint_t.h" /** - @file dns_name.c - @author djb, fefe, feh - @source ucspi-tcp - @brief DNS name query (ptr) + @file dns_name.c + @author djb, fefe, feh + @source ucspi-tcp + @brief DNS name query (ptr) */ static char *q = 0; @@ -35,12 +35,13 @@ int dns_name_packet(stralloc *out, const char *buf, unsigned int len) pos = dns_packet_copy(buf, len, pos, header, 10); if (!pos) return DNS_ERR; uint16_unpack_big(header + 8, &datalen); - if (byte_equal(header, 2, DNS_T_PTR)) + if (byte_equal(header, 2, DNS_T_PTR)) { if (byte_equal(header + 2, 2, DNS_C_IN)) { if (!dns_packet_getname(buf, len, pos, &q)) return DNS_ERR; if (dns_domain_todot_cat(out, q) <= 0) return DNS_ERR; return 1; } + } pos += datalen; } diff --git a/src/dnsstub/dns_nd.c b/src/dnsstub/dns_nd.c index 3bbbeca..b8e153a 100644 --- a/src/dnsstub/dns_nd.c +++ b/src/dnsstub/dns_nd.c @@ -4,10 +4,10 @@ #include "ip.h" /** - @file dns_nd.c - @autor djb, fefe - @source ucspi-tcp - @brief DNS domain name for ip (wire format) + @file dns_nd.c + @autor djb, fefe + @source ucspi-tcp + @brief DNS domain name for ip (wire format) */ int dns_name4_domain(char name[DNS_NAME4_DOMAIN], const char ip[4]) diff --git a/src/dnsstub/dns_packet.c b/src/dnsstub/dns_packet.c index 2b2040f..66d6196 100644 --- a/src/dnsstub/dns_packet.c +++ b/src/dnsstub/dns_packet.c @@ -2,11 +2,11 @@ #include "error.h" /** - @file dns_packet.c - @author djb - @source ucspi-tcp - @brief DNS low level packet routine - @brief DNS should have used LZ77 instead of its own sophomoric compression algorithm. + @file dns_packet.c + @author djb + @source ucspi-tcp + @brief DNS low level packet routine + @brief DNS should have used LZ77 instead of its own sophomoric compression algorithm. */ unsigned int dns_packet_copy( diff --git a/src/dnsstub/dns_random.c b/src/dnsstub/dns_random.c index 8b89244..d345c78 100644 --- a/src/dnsstub/dns_random.c +++ b/src/dnsstub/dns_random.c @@ -5,10 +5,10 @@ #include "uint_t.h" /** - @file dns_random.c - @author djb - @source ucspi-tcp - @brief random use of DNS resolvers given their IP + @file dns_random.c + @author djb + @source ucspi-tcp + @brief random use of DNS resolvers given their IP */ static uint32 seed[32]; diff --git a/src/dnsstub/dns_rcip.c b/src/dnsstub/dns_rcip.c index fd86df9..2d6ad08 100644 --- a/src/dnsstub/dns_rcip.c +++ b/src/dnsstub/dns_rcip.c @@ -7,10 +7,10 @@ #include "taia.h" /** - @file dns_rcip.c - @author djb, fefe, feh - @source ucspi-tcp - @brief DNS receive for query + @file dns_rcip.c + @author djb, fefe, feh + @source ucspi-tcp + @brief DNS receive for query */ static stralloc data = {0}; @@ -26,25 +26,26 @@ static int init(char ip[QUERY_MAXIPLEN], uint32 sid[QUERY_MAXNS]) char ip4[4]; /* Read (compactified) IPv4|v6 addresses of resolvers - Store them in array IP with fixed length : - ip(64) -> 16 IPv4 addresses (not used anymore) - ip(512) -> 16*2 IPv6 addresses (we use IPv4 mapped IPv6 addresses) - sid(32) -> the scope for the respective IPv6 or 0 -*/ + Store them in array IP with fixed length: + ip(64) -> 16 IPv4 addresses (not used anymore) + ip(512) -> 16*2 IPv6 addresses (we use IPv4 mapped IPv6 addresses) + sid(32) -> the scope for the respective IPv6 or 0 + */ for (i = 0; i < QUERY_MAXNS; ++i) sid[i] = 0; x = env_get("DNSCACHEIP"); - if (x) + if (x) { while (iplen <= 240 && *x != '\0') { - if (*x == ' ') + if (*x == ' ') { ++x; - else if ((i = ip6_ifscan(x, ip + iplen, &ifname))) { + } else if ((i = ip6_ifscan(x, ip + iplen, &ifname))) { if (ifname.len > 2) sid[k] = socket_getifidx(ifname.s); iplen += 16; k++; if (*(x += i) == '\0') break; } } + } if (!iplen) { i = openreadclose("/etc/resolv.conf", &data, 64); @@ -52,7 +53,7 @@ static int init(char ip[QUERY_MAXIPLEN], uint32 sid[QUERY_MAXNS]) if (i) { if (!stralloc_append(&data, "\n")) return DNS_MEM; i = 0; - for (j = 0; j < data.len; ++j) + for (j = 0; j < data.len; ++j) { if (data.s[j] == '\n') { if (byte_equal("nameserver ", 11, data.s + i) || byte_equal("nameserver\t", 11, data.s + i)) { i += 10; @@ -75,6 +76,7 @@ static int init(char ip[QUERY_MAXIPLEN], uint32 sid[QUERY_MAXNS]) } i = j + 1; } + } } } diff --git a/src/dnsstub/dns_rcrw.c b/src/dnsstub/dns_rcrw.c index 8c15591..95239a2 100644 --- a/src/dnsstub/dns_rcrw.c +++ b/src/dnsstub/dns_rcrw.c @@ -8,10 +8,10 @@ #include "taia.h" /** - @file dns_rcrw.c - @author djb - @source ucspi-tcp - @brief DNS receive rewrite + @file dns_rcrw.c + @author djb + @source ucspi-tcp + @brief DNS receive rewrite */ static stralloc data = {0}; @@ -56,12 +56,13 @@ static int init(stralloc *rules) if (!stralloc_append(&data, " ")) return DNS_MEM; if (!stralloc_copys(rules, "?:")) return DNS_MEM; i = 0; - for (j = 0; j < data.len; ++j) + for (j = 0; j < data.len; ++j) { if (data.s[j] == ' ') { if (!stralloc_cats(rules, "+.")) return DNS_MEM; if (!stralloc_catb(rules, data.s + i, j - i)) return DNS_MEM; i = j + 1; } + } if (!stralloc_0(rules)) return DNS_MEM; if (!stralloc_cats(rules, "*.:")) return DNS_MEM; if (!stralloc_0(rules)) return DNS_MEM; @@ -74,7 +75,7 @@ static int init(stralloc *rules) if (i) { if (!stralloc_append(&data, "\n")) return DNS_MEM; i = 0; - for (j = 0; j < data.len; ++j) + for (j = 0; j < data.len; ++j) { if (data.s[j] == '\n') { if (byte_equal("search ", 7, data.s + i) || byte_equal("search\t", 7, data.s + i) || byte_equal("domain ", 7, data.s + i) || byte_equal("domain\t", 7, data.s + i)) @@ -99,6 +100,7 @@ static int init(stralloc *rules) } i = j + 1; } + } } host[0] = 0; diff --git a/src/dnsstub/dns_resolve.c b/src/dnsstub/dns_resolve.c index 90c5615..6257b08 100644 --- a/src/dnsstub/dns_resolve.c +++ b/src/dnsstub/dns_resolve.c @@ -5,10 +5,10 @@ #include "taia.h" /** - @file dns_resolve.c - @author djb, fefe, feh - @source ucspi-tcp - @brief high-level DNS resolve function + @file dns_resolve.c + @author djb, fefe, feh + @source ucspi-tcp + @brief high-level DNS resolve function */ struct dns_transmit dns_resolve_tx = {0}; diff --git a/src/dnsstub/dns_sortip.c b/src/dnsstub/dns_sortip.c index 886e989..f319f53 100644 --- a/src/dnsstub/dns_sortip.c +++ b/src/dnsstub/dns_sortip.c @@ -3,10 +3,10 @@ #include "ip.h" /** - @file dns_sortip.c - @authors djb, fefe, feh - @source ucspi-tcp6 - @brief random sort of DNS servers per IP + @file dns_sortip.c + @authors djb, fefe, feh + @source ucspi-tcp6 + @brief random sort of DNS servers per IP */ /* XXX: sort servers by configurable notion of closeness? */ @@ -19,7 +19,7 @@ void dns_sortip4(char *s, unsigned int n) unsigned int i; char tmp[4]; - n >>= 2; /* 4 byte per IPv4 address */ + n >>= 2; // 4 byte per IPv4 address while (n > 1) { i = dns_random(n); --n; @@ -34,7 +34,7 @@ void dns_sortip6(char *s, unsigned int n) unsigned int i; char tmp[16]; - n >>= 4; /* 16 byte per IPv4 address */ + n >>= 4; // 16 byte per IPv4 address while (n > 1) { i = dns_random(n); --n; diff --git a/src/dnsstub/dns_transmit.c b/src/dnsstub/dns_transmit.c index e041312..96eb38c 100644 --- a/src/dnsstub/dns_transmit.c +++ b/src/dnsstub/dns_transmit.c @@ -11,11 +11,11 @@ #include "uint_t.h" /** - @file dns_transmit.c - @authors djb, fefe, feh - @source qlibs - @brief DNS query function - @brief scope_ids[32] -> 32 LLU root servers supported + @file dns_transmit.c + @authors djb, fefe, feh + @source qlibs + @brief DNS query function + @brief scope_ids[32] -> 32 LLU root servers supported */ #define DNSPORT 53 diff --git a/src/dnsstub/dns_txt.c b/src/dnsstub/dns_txt.c index ce0afc4..8368a05 100644 --- a/src/dnsstub/dns_txt.c +++ b/src/dnsstub/dns_txt.c @@ -29,7 +29,7 @@ int dns_txt_packet(stralloc *out, const char *buf, unsigned int len) pos = dns_packet_copy(buf, len, pos, header, 10); if (!pos) return DNS_ERR; uint16_unpack_big(header + 8, &datalen); - if (byte_equal(header, 2, DNS_T_TXT)) + if (byte_equal(header, 2, DNS_T_TXT)) { if (byte_equal(header + 2, 2, DNS_C_IN)) { if (pos + datalen > len) return DNS_ERR; txtlen = (unsigned char)buf[pos]; @@ -44,6 +44,7 @@ int dns_txt_packet(stralloc *out, const char *buf, unsigned int len) } } } + } pos += datalen; ++ranswers; if (numanswers) @@ -4,10 +4,10 @@ #include "str.h" /** - @file env.c - @author djb - @source ucspi-tcp - @brief setting up environment after fork + @file env.c + @author djb + @source ucspi-tcp + @brief setting up environment after fork */ extern /*@null@*/ char *env_get(char *s) @@ -111,7 +111,7 @@ int env_put(char *name, char *value) return 1; } -int env_init() +int env_init(void) { char **newenviron; int i; @@ -146,6 +146,7 @@ void env_clear() else environ = &null; } + extern char *env_pick() { return environ[0]; diff --git a/src/errstr.c b/src/errstr.c index 47b5aef..e2807ef 100644 --- a/src/errstr.c +++ b/src/errstr.c @@ -1,10 +1,10 @@ #include "error.h" /** - @file errstr.c - @author kp - @source qlibs - @brief error output to log for different conditions and OS + @file errstr.c + @author kp + @source qlibs + @brief error output to log for different conditions and OS */ #define X(e, s) \ @@ -14,151 +14,154 @@ extern char *error_str(int); char *errstr(int code) { - X(0, "") // NOERROR - X(error_intr, "interrupted system call") // EINTR - X(EINTR, "interrupted system call") - X(error_nomem, "out of memory") // ENOMEM - X(ENOMEM, "out of memory") - X(error_noent, "file does not exist") // ENOENT - X(ENOENT, "file does not exist") - X(error_txtbsy, "text busy") // ETXTBSY - X(ETXTBSY, "text busy") - X(error_io, "input/output error") // EIO - X(EIO, "input/output error") - X(error_exist, "file already exists") // EEXISTS - X(EEXIST, "file already exists") - X(error_timeout, "timed out") // ETIMEDOUT - X(ETIMEDOUT, "timed out") - X(error_inprogress, "operation in progress") // EINPROGRESS - X(EINPROGRESS, "operation in progress") - X(error_again, "temporary failure") // EAGAIN - X(EAGAIN, "temporary failure") - X(error_wouldblock, "input/output would block") // EWOULDBLOCK (intern EAGAIN) - X(EWOULDBLOCK, "input/output would block") - X(error_pipe, "broken pipe") // EPIPE - X(EPIPE, "broken pipe") - X(error_perm, "permission denied") // EPERM - X(EPERM, "permission denied") - X(error_acces, "access denied") // EACCES - X(EACCES, "access denied") - - X(ESRCH, "no such process") - - // X(error_nodevice,"device not configured") // ENXIO - X(ENXIO, "device not configured") - - X(E2BIG, "argument list too long") - X(ENOEXEC, "exec format error") - X(EBADF, "file descriptor not open") - X(ECHILD, "no child processes") - X(EDEADLK, "operation would cause deadlock") - X(EFAULT, "bad address") - X(ENOTBLK, "not a block device") - X(EBUSY, "device busy") - X(EXDEV, "cross-device link") - X(ENODEV, "device does not support operation") - // X(error_notdir,"not a directory") // ENOTDIR - X(ENOTDIR, "not a directory") - X(error_isdir, "is a directory") // EISDIR - X(EISDIR, "is a directory") - X(EINVAL, "invalid argument") - X(ENFILE, "system cannot open more files") - X(EMFILE, "process cannot open more files") - X(ENOTTY, "not a tty") - X(EFBIG, "file too big") - X(ENOSPC, "out of disk space") - X(ESPIPE, "unseekable descriptor") - // X(error_rofs,"read-only file system") // EROFS - X(EROFS, "read-only file system") - X(EMLINK, "too many links") - X(EDOM, "input out of range") - X(ERANGE, "output out of range") - X(EALREADY, "operation already in progress") - X(ENOTSOCK, "not a socket") - X(EDESTADDRREQ, "destination address required") - X(EMSGSIZE, "message too long") - X(EPROTOTYPE, "incorrect protocol type") - X(ENOPROTOOPT, "protocol not available") - X(EPROTONOSUPPORT, "protocol not supported") - X(ESOCKTNOSUPPORT, "socket type not supported") - X(EOPNOTSUPP, "operation not supported") - X(EPFNOSUPPORT, "protocol family not supported") - X(EAFNOSUPPORT, "address family not supported") - X(EADDRINUSE, "address already used") - X(EADDRNOTAVAIL, "address not available") - X(ENETDOWN, "network down") - X(ENETUNREACH, "network unreachable") - X(ENETRESET, "network reset") - X(ECONNABORTED, "connection aborted") - X(error_connreset, "connection reset") // ECONNRESET - X(ECONNRESET, "connection reset") - X(ENOBUFS, "out of buffer space") - X(EISCONN, "already connected") - X(ENOTCONN, "not connected") - X(ESHUTDOWN, "socket shut down") - X(ETOOMANYREFS, "too many references") - X(error_connrefused, "connection refused") // ECONNREFUSED - X(ECONNREFUSED, "connection refused") - X(ELOOP, "symbolic link loop") - X(ENAMETOOLONG, "file name too long") - X(EHOSTDOWN, "host down") - X(EHOSTUNREACH, "host unreachable") - X(ENOTEMPTY, "directory not empty") - X(EUSERS, "too many users") - X(EDQUOT, "disk quota exceeded") - X(ESTALE, "stale NFS file handle") + // clang-format off + X(0, "") // NOERROR + X(error_intr, "interrupted system call") // EINTR + X(EINTR, "interrupted system call") + X(error_nomem, "out of memory") // ENOMEM + X(ENOMEM, "out of memory") + X(error_noent, "file does not exist") // ENOENT + X(ENOENT, "file does not exist") + X(error_txtbsy, "text busy") // ETXTBSY + X(ETXTBSY, "text busy") + X(error_io, "input/output error") // EIO + X(EIO, "input/output error") + X(error_exist, "file already exists") // EEXISTS + X(EEXIST, "file already exists") + X(error_timeout, "timed out") // ETIMEDOUT + X(ETIMEDOUT, "timed out") + X(error_inprogress, "operation in progress") // EINPROGRESS + X(EINPROGRESS, "operation in progress") + X(error_again, "temporary failure") // EAGAIN + X(EAGAIN, "temporary failure") + X(error_wouldblock, "input/output would block") // EWOULDBLOCK (intern EAGAIN) + X(EWOULDBLOCK, "input/output would block") + X(error_pipe, "broken pipe") // EPIPE + X(EPIPE, "broken pipe") + X(error_perm, "permission denied") // EPERM + X(EPERM, "permission denied") + X(error_acces, "access denied") // EACCES + X(EACCES, "access denied") + + X(ESRCH, "no such process") + +//X(error_nodevice,"device not configured") // ENXIO + X(ENXIO, "device not configured") + + X(E2BIG, "argument list too long") + X(ENOEXEC, "exec format error") + X(EBADF, "file descriptor not open") + X(ECHILD, "no child processes") + X(EDEADLK, "operation would cause deadlock") + X(EFAULT, "bad address") + X(ENOTBLK, "not a block device") + X(EBUSY, "device busy") + X(EXDEV, "cross-device link") + X(ENODEV, "device does not support operation") +//X(error_notdir,"not a directory") // ENOTDIR + X(ENOTDIR, "not a directory") + X(error_isdir, "is a directory") // EISDIR + X(EISDIR, "is a directory") + X(EINVAL, "invalid argument") + X(ENFILE, "system cannot open more files") + X(EMFILE, "process cannot open more files") + X(ENOTTY, "not a tty") + X(EFBIG, "file too big") + X(ENOSPC, "out of disk space") + X(ESPIPE, "unseekable descriptor") +//X(error_rofs,"read-only file system") // EROFS + X(EROFS, "read-only file system") + X(EMLINK, "too many links") + X(EDOM, "input out of range") + X(ERANGE, "output out of range") + X(EALREADY, "operation already in progress") + X(ENOTSOCK, "not a socket") + X(EDESTADDRREQ, "destination address required") + X(EMSGSIZE, "message too long") + X(EPROTOTYPE, "incorrect protocol type") + X(ENOPROTOOPT, "protocol not available") + X(EPROTONOSUPPORT, "protocol not supported") + X(ESOCKTNOSUPPORT, "socket type not supported") + X(EOPNOTSUPP, "operation not supported") + X(EPFNOSUPPORT, "protocol family not supported") + X(EAFNOSUPPORT, "address family not supported") + X(EADDRINUSE, "address already used") + X(EADDRNOTAVAIL, "address not available") + X(ENETDOWN, "network down") + X(ENETUNREACH, "network unreachable") + X(ENETRESET, "network reset") + X(ECONNABORTED, "connection aborted") + X(error_connreset, "connection reset") // ECONNRESET + X(ECONNRESET, "connection reset") + X(ENOBUFS, "out of buffer space") + X(EISCONN, "already connected") + X(ENOTCONN, "not connected") + X(ESHUTDOWN, "socket shut down") + X(ETOOMANYREFS, "too many references") + X(error_connrefused,"connection refused") // ECONNREFUSED + X(ECONNREFUSED, "connection refused") + X(ELOOP, "symbolic link loop") + X(ENAMETOOLONG, "file name too long") + X(EHOSTDOWN, "host down") + X(EHOSTUNREACH, "host unreachable") + X(ENOTEMPTY, "directory not empty") + X(EUSERS, "too many users") + X(EDQUOT, "disk quota exceeded") + X(ESTALE, "stale NFS file handle") /* BSD only (all BSD's, NOT on Linux) */ - // X(EPROCLIM, "too many processes") // -L +FB +OB +NB - // X(EBADRPC, "RPC structure is bad") // -L +FB +OB +NB +//X(EPROCLIM, "too many processes") // -L +FB +OB +NB +//X(EBADRPC, "RPC structure is bad") // -L +FB +OB +NB - // X(ERPCMISMATCH, "RPC version mismatch") // -L +FB +OB +NB - // X(EPROGUNAVAIL, "RPC program unavailable") // -L +FB +OB +NB - // X(EPROGMISMATCH, "program version mismatch") // -L +FB +OB +NB - // X(EPROCUNAVAIL, "bad procedure for program") // -L +FB +OB +NB - // X(EFTYPE, "bad file type") // -L +FB +OB +NB +//X(ERPCMISMATCH, "RPC version mismatch") // -L +FB +OB +NB +//X(EPROGUNAVAIL, "RPC program unavailable") // -L +FB +OB +NB +//X(EPROGMISMATCH, "program version mismatch") // -L +FB +OB +NB +//X(EPROCUNAVAIL, "bad procedure for program") // -L +FB +OB +NB +//X(EFTYPE, "bad file type") // -L +FB +OB +NB - X(ENOLCK, "no locks available") - X(ENOSYS, "system call not available") - X(ENOMSG, "no message of desired type") - X(EIDRM, "identifier removed") + X(ENOLCK, "no locks available") + X(ENOSYS, "system call not available") + X(ENOMSG, "no message of desired type") + X(EIDRM, "identifier removed") - // X(ERREMOTE, "object not local") // -L -FB -OB -NB - X(EREMOTE, "object not local") // Linux: "Object is remote" - // X(EREMOTE, "too many levels of remote in path") +//X(ERREMOTE, "object not local") // -L -FB -OB -NB + X(EREMOTE, "object not local") // Linux: "Object is remote" +//X(EREMOTE, "too many levels of remote in path") /* Linux only */ - // X(ENONET, "machine not on network") // +L -FB -OB -NB - // X(EADV, "advertise error") // +L -FB -OB -NB - // X(ESRMNT, "srmount error") // +L -FB -OB -NB - // X(ECOMM, "communication error") // +L -FB -OB -NB - // X(EREMCHG, "remote address changed") // +L -FB -OB -NB +//X(ENONET, "machine not on network") // +L -FB -OB -NB +//X(EADV, "advertise error") // +L -FB -OB -NB +//X(ESRMNT, "srmount error") // +L -FB -OB -NB +//X(ECOMM, "communication error") // +L -FB -OB -NB +//X(EREMCHG, "remote address changed") // +L -FB -OB -NB + + X(error_proto, "protocol error") // EPROTO - X(error_proto, "protocol error") // EPROTO /* EPROTO: see 'error.h' for OpenBSD compat */ - X(EPROTO, "protocol error") // +L +FB -OB +NB + X(EPROTO, "protocol error") // +L +FB -OB +NB /* Linux and NetBSD */ - // X(ENOSTR, "not a stream device") // +L -FB -OB +NB - // X(ETIME, "timer expired") // +L -FB -OB +NB - // X(ENOSR, "out of stream resources") // +L -FB -OB +NB +//X(ENOSTR, "not a stream device") // +L -FB -OB +NB +//X(ETIME, "timer expired") // +L -FB -OB +NB +//X(ENOSR, "out of stream resources") // +L -FB -OB +NB /* FreeBSD and NetBSD */ - // X(EAUTH, "authentication error") // -L +FB -OB +NB - // X(ENEEDAUTH, "not authenticated") // -L +FB -OB +NB +//X(EAUTH, "authentication error") // -L +FB -OB +NB +//X(ENEEDAUTH, "not authenticated") // -L +FB -OB +NB /* NOT on OpenBSD */ - // X(EBADMSG, "bad message type") // +L +FB -OB +NB - // X(ENOLINK, "link severed") // +L +FB -OB +NB - // X(EMULTIHOP, "multihop attempted") // +L +FB -OB +NB +//X(EBADMSG, "bad message type") // +L +FB -OB +NB +//X(ENOLINK, "link severed") // +L +FB -OB +NB +//X(EMULTIHOP, "multihop attempted") // +L +FB -OB +NB /* Application/DJB specific */ - X(EHARD, " ") - X(ESOFT, " ") - X(USAGE, "usage error") // qmail; explicit - X(SYNTAX, "syntax error") // djbdns, qmail; explicit - X(DROP, "connection dropped") // ucspi-tcp - X(FATAL, "unable to continue") // all - - return "unknown error"; /* worst case */ + X(EHARD, " ") + X(ESOFT, " ") + X(USAGE, "usage error") // qmail; explicit + X(SYNTAX, "syntax error") // djbdns, qmail; explicit + X(DROP, "connection dropped") // ucspi-tcp + X(FATAL, "unable to continue") // all + // clang-format on + + return "unknown error"; // worst case } @@ -3,10 +3,10 @@ #include <fcntl.h> /** - @file fd.c - @autor djb - @source qmail - @brief file descriptor manipulation + @file fd.c + @autor djb + @source qmail + @brief file descriptor manipulation */ int close(int __fd); /* we won't use unistd.h here */ @@ -1,39 +1,41 @@ #include "fmt.h" /** - @file fmt.c - @author djb - @source qmail - @brief formating differnt inputs format for output printing + @file fmt.c + @author djb + @source qmail + @brief formating differnt inputs format for output printing */ -unsigned int fmt_str(register char *s, register char *t) +unsigned int fmt_str(char *s, char *t) { - register unsigned int len; + unsigned int len; char ch; len = 0; if (s) { while ((ch = t[len])) s[len++] = ch; - } else + } else { while (t[len]) len++; + } return len; } -unsigned int fmt_strn(register char *s, register char *t, register unsigned int n) +unsigned int fmt_strn(char *s, char *t, unsigned int n) { - register unsigned int len; + unsigned int len; char ch; len = 0; if (s) { while (n-- && (ch = t[len])) s[len++] = ch; - } else + } else { while (n-- && t[len]) len++; + } return len; } -unsigned int fmt_uint(register char *s, register unsigned int u) +unsigned int fmt_uint(char *s, unsigned int u) { - register unsigned long l; + unsigned long l; l = u; return fmt_ulong(s, l); } @@ -50,10 +52,10 @@ unsigned int fmt_uint0(char *s, unsigned int u, unsigned int n) return len; } -unsigned int fmt_ulong(register char *s, register unsigned long u) +unsigned int fmt_ulong(char *s, unsigned long u) { - register unsigned int len; - register unsigned long q; + unsigned int len; + unsigned long q; len = 1; q = u; while (q > 9) { @@ -70,10 +72,10 @@ unsigned int fmt_ulong(register char *s, register unsigned long u) return len; } -unsigned int fmt_xlong(register char *s, register unsigned long u) +unsigned int fmt_xlong(char *s, unsigned long u) { - register unsigned int len; - register unsigned long q; + unsigned int len; + unsigned long q; len = 1; q = u; while (q > 15) { @@ -108,5 +110,6 @@ int fromhex(unsigned char c) return c - 'A' + 10; else if (c >= 'a' && c <= 'f') return c - 'a' + 10; - return -1; + else + return -1; } diff --git a/src/getln.c b/src/getln.c index 64189fe..476e197 100644 --- a/src/getln.c +++ b/src/getln.c @@ -3,10 +3,10 @@ #include "byte.h" /** - @file getln.c - @author djb - @source qmail - @brief evaluting tokenized input arguments + @file getln.c + @author djb + @source qmail + @brief evaluting tokenized input arguments */ int getln(buffer *b, stralloc *sa, int *match, int sep) @@ -26,8 +26,8 @@ int getln(buffer *b, stralloc *sa, int *match, int sep) int sgetln(buffer *b, stralloc *sa, char **cont, unsigned int *clen, int sep) { - register char *x; - register unsigned int i; + char *x; + unsigned int i; int n; if (!stralloc_ready(sa, 0)) return -1; diff --git a/src/getoptb.c b/src/getoptb.c index 9859102..64ac8ca 100644 --- a/src/getoptb.c +++ b/src/getoptb.c @@ -3,10 +3,10 @@ #include "buffer.h" /** - @file getoptb.c - @author djb - @source ucspi-tcp - @brief 'getopt' version w/o stdlib + @file getoptb.c + @author djb + @source ucspi-tcp + @brief 'getopt' version w/o stdlib */ #define optind subgetoptind @@ -27,7 +27,7 @@ int getopt(int argc, char **argv, char *opts) if (*s == '/') optprogname = s + 1; } c = subgetopt(argc, argv, opts); - if (opterr) + if (opterr) { if (c == '?') { char chp[2]; chp[0] = optproblem; @@ -40,6 +40,7 @@ int getopt(int argc, char **argv, char *opts) buffer_put(buffer_2, chp, 2); buffer_flush(buffer_2); } + } return c; } diff --git a/src/iopause.c b/src/iopause.c index 0baad2a..9c160ac 100644 --- a/src/iopause.c +++ b/src/iopause.c @@ -6,10 +6,10 @@ #include "taia.h" /** - @file iopause.c - @author djb - @source qmail - @brief stateful reading from net + @file iopause.c + @author djb + @source qmail + @brief stateful reading from net @return > 0 if successful */ @@ -20,9 +20,9 @@ int iopause(iopause_fd *x, unsigned int len, struct taia *deadline, struct taia double d; int i, r; - if (taia_less(deadline, stamp)) + if (taia_less(deadline, stamp)) { millisecs = 0; - else { + } else { t = *stamp; taia_sub(&t, deadline, &t); d = taia_approx(&t); @@ -4,10 +4,10 @@ #include "str.h" /** - @file ip4.c - @author djb, fefe, feh, kp - @source ucspi-tcp, ucspi-tcp6 - @brief handling of IPv4 addresses + @file ip4.c + @author djb, fefe, feh, kp + @source ucspi-tcp, ucspi-tcp6 + @brief handling of IPv4 addresses */ /** @@ -133,7 +133,7 @@ unsigned int ip4_cidr(char *s, char ip[4], unsigned long *plen) } /** - @brief ip4_bytestring + @brief ip4_bytestring parse IPv4 address and represent as char string with length prefix @param input: IPv4 char array, prefix length output: pointer to stralloc bytestring @@ -5,10 +5,10 @@ #include "str.h" /** - @file ip6.c - @author djb, fefe, feh - @source ucspi-tcp, ucspi-tcp6 - @brief handling of IPv6 addresses + @file ip6.c + @author djb, fefe, feh + @source ucspi-tcp, ucspi-tcp6 + @brief handling of IPv6 addresses */ /*** @@ -94,15 +94,14 @@ unsigned int ip6_fmt_flat(char *s, char ip[16]) return 32; } -/*** - @brief ia6_fmt - convert IPv6 address to inverse DNS nibble format - 1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.ip6.arpa - @param input: IPv6 char array - output: pointer to IPv6 address string - @return int length of address - */ - +/** + @brief ia6_fmt + convert IPv6 address to inverse DNS nibble format + 1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.ip6.arpa + @param input: IPv6 char array + output: pointer to IPv6 address string + @return int length of address +*/ unsigned int ia6_fmt(char *s, char ip[16]) { unsigned int i; @@ -273,7 +272,7 @@ unsigned int ip6_scanbracket(const char *s, char ip[16]) /** @brief ip6_ifscan - parse compactified IPv6 address string + parse compactified IPv6 address string concatinated with the interface name: fe80::1%eth0 @param input: pointer to IPv6 address string output: IPv6 char array, stralloc interface_name @@ -308,7 +307,7 @@ unsigned int ip6_ifscan(char *s, char ip[16], stralloc *ifname) parse compactified IPv6 address string concatinated with the prefix length: fe80::1/64 @param input: pointer to IPv6 address string - output: IPv6 char array, long plen + output: IPv6 char array, long plen @return int length of ip6_address/ip */ @@ -6,10 +6,10 @@ #include <unistd.h> /** - @file lock.c - @author djb - @source qmail - @brief locking of resources + @file lock.c + @author djb + @source qmail + @brief locking of resources */ #ifdef HASFLOCK @@ -17,10 +17,12 @@ int lock_ex(int fd) { return flock(fd, LOCK_EX); } + int lock_exnb(int fd) { return flock(fd, LOCK_EX | LOCK_NB); } + int lock_un(int fd) { return flock(fd, LOCK_UN); @@ -30,10 +32,12 @@ int lock_ex(int fd) { return lockf(fd, 1, 0); } + int lock_exnb(int fd) { return lockf(fd, 2, 0); } + int lock_un(int fd) { return lockf(fd, 0, 0); diff --git a/src/logmsg.c b/src/logmsg.c index e846275..f254fd9 100644 --- a/src/logmsg.c +++ b/src/logmsg.c @@ -11,10 +11,10 @@ #include "stralloc.h" /** - @file logmsg.c - @author kp, feh - @source qlibs - @brief unified system and error message handling + @file logmsg.c + @author kp, feh + @source qlibs + @brief unified system and error message handling */ #define WHO "logmsg" diff --git a/src/ndelay.c b/src/ndelay.c index 8f6b5a9..44a34d7 100644 --- a/src/ndelay.c +++ b/src/ndelay.c @@ -4,10 +4,10 @@ #include <sys/types.h> /** - @file ndelay.c - @author djb - @soure qmail - @brief delaying of IO operations + @file ndelay.c + @author djb + @soure qmail + @brief delaying of IO operations */ #ifndef O_NONBLOCK @@ -4,10 +4,10 @@ #include <sys/types.h> /** - @file open.c - @author djb - @source qmail - @brief open a file + @file open.c + @author djb + @source qmail + @brief open a file */ int open_append(const char *fn) diff --git a/src/pathexec.c b/src/pathexec.c index 343b4ba..e588c65 100644 --- a/src/pathexec.c +++ b/src/pathexec.c @@ -10,10 +10,10 @@ #include "stralloc.h" /** - @file pathexec.c - @author djb - @source ucspi-tcp, ucspi-ssl - @brief populate environment after fork + @file pathexec.c + @author djb + @source ucspi-tcp, ucspi-ssl + @brief populate environment after fork */ static stralloc plus; @@ -1,14 +1,16 @@ +#include "prot.h" + #include <grp.h> #include <sys/types.h> #include <unistd.h> + //#include "hasshsgr.h" -#include "prot.h" /** - @file prot.c - @author djb - @source qmail - @brief setting up uid an gid for OS (short group was for ancient solaris) + @file prot.c + @author djb + @source qmail + @brief setting up uid an gid for OS (short group was for ancient solaris) */ /* XXX: there are more portability problems here waiting to leap out at me */ diff --git a/src/readclose.c b/src/readclose.c index 2804965..307f830 100644 --- a/src/readclose.c +++ b/src/readclose.c @@ -6,10 +6,10 @@ #include "open.h" /** - @file readclose.c - @author kp - @source qlibs - @brief This is the successor of the older 'slurpclose.c' file. The function + @file readclose.c + @author kp + @source qlibs + @brief This is the successor of the older 'slurpclose.c' file. The function 'slurpclose' is now called 'readclose_append'. The other function 'readclose' was introduced here initial. */ @@ -1,10 +1,10 @@ #include "scan.h" /** - @file scan.c - @author djb - @source qmail, ucspi-tcp - @brief scanning/conversion of strings to different variable types + @file scan.c + @author djb + @source qmail, ucspi-tcp + @brief scanning/conversion of strings to different variable types */ static long int fromhex(unsigned char c) @@ -18,11 +18,11 @@ static long int fromhex(unsigned char c) return -1; } -unsigned int scan_0x(register const char *s, register unsigned int *u) +unsigned int scan_0x(const char *s, unsigned int *u) { - register unsigned int pos = 0; - register unsigned long result = 0; - register long int c; + unsigned int pos = 0; + unsigned long result = 0; + long int c; while ((c = fromhex((unsigned char)(s[pos]))) >= 0) { result = (result << 4) + c; @@ -32,11 +32,11 @@ unsigned int scan_0x(register const char *s, register unsigned int *u) return pos; } -unsigned int scan_8long(register const char *s, register unsigned long *u) +unsigned int scan_8long(const char *s, unsigned long *u) { - register unsigned int pos = 0; - register unsigned long result = 0; - register unsigned long c; + unsigned int pos = 0; + unsigned long result = 0; + unsigned long c; while ((c = (unsigned long)(unsigned char)(s[pos] - '0')) < 8) { result = result * 8 + c; @@ -46,9 +46,9 @@ unsigned int scan_8long(register const char *s, register unsigned long *u) return pos; } -unsigned int scan_uint(register const char *s, register unsigned int *u) +unsigned int scan_uint(const char *s, unsigned int *u) { - register unsigned int pos; + unsigned int pos; unsigned long result; pos = scan_ulong(s, &result); @@ -56,7 +56,7 @@ unsigned int scan_uint(register const char *s, register unsigned int *u) return pos; } -unsigned int scan_plusminus(register const char *s, register int *sign) +static unsigned int scan_plusminus(const char *s, int *sign) { if (*s == '+') { *sign = 1; @@ -70,11 +70,11 @@ unsigned int scan_plusminus(register const char *s, register int *sign) return 0; } -unsigned int scan_long(register const char *s, register long *i) +unsigned int scan_long(const char *s, long *i) { int sign; unsigned long u; - register unsigned int len; + unsigned int len; len = scan_plusminus(s, &sign); s += len; @@ -87,11 +87,11 @@ unsigned int scan_long(register const char *s, register long *i) } -unsigned int scan_ulong(register const char *s, register unsigned long *u) +unsigned int scan_ulong(const char *s, unsigned long *u) { - register unsigned int pos = 0; - register unsigned long result = 0; - register unsigned long c; + unsigned int pos = 0; + unsigned long result = 0; + unsigned long c; while ((c = (unsigned long)(unsigned char)(s[pos] - '0')) < 10) { result = result * 10 + c; @@ -103,9 +103,9 @@ unsigned int scan_ulong(register const char *s, register unsigned long *u) unsigned int scan_xlong(const char *s, unsigned long *u) { - register const char *t = s; - register int l = 0; - register unsigned char c; + const char *t = s; + int l = 0; + unsigned char c; while ((c = fromhex(*t)) < 16) { l = (l << 4) + c; @@ -117,9 +117,9 @@ unsigned int scan_xlong(const char *s, unsigned long *u) unsigned int scan_xint(const char *s, unsigned int *i) { - register const char *t = s; - register unsigned int l = 0; - register unsigned char c; + const char *t = s; + unsigned int l = 0; + unsigned char c; while ((l >> (sizeof(l) * 8 - 4)) == 0 && (c = (unsigned char)fromhex((unsigned char)*t)) < 16) { l = (l << 4) + c; @@ -3,10 +3,10 @@ #include <sys/types.h> /** - @file seek.c - @author djb - @source qmail - @brief seek in an open file descritor + @file seek.c + @author djb + @source qmail + @brief seek in an open file descritor */ off_t lseek(int fd, off_t offset, int whence); @@ -3,16 +3,17 @@ #include <signal.h> /** - @file sig.c - @author djb - @source qmail - @brief signal handling functions + @file sig.c + @author djb + @source qmail + @brief signal handling functions */ void sig_alarmblock() { sig_block(SIGALRM); } + void sig_alarmunblock() { sig_unblock(SIGALRM); @@ -21,10 +22,12 @@ void sig_alarmcatch(f) void (*f)(); { sig_catch(SIGALRM, f); } + void sig_alarmdefault() { sig_catch(SIGALRM, SIG_DFL); } + int sig_alarm = SIGALRM; void sig_block(int sig) @@ -70,16 +73,19 @@ void sig_pipeignore() { sig_catch(SIGPIPE, SIG_IGN); } + void sig_pipedefault() { sig_catch(SIGPIPE, SIG_DFL); } + int sig_pipe = SIGPIPE; void sig_childblock() { sig_block(SIGCHLD); } + void sig_childunblock() { sig_unblock(SIGCHLD); @@ -88,16 +94,19 @@ void sig_childcatch(f) void (*f)(); { sig_catch(SIGCHLD, f); } + void sig_childdefault() { sig_catch(SIGCHLD, SIG_DFL); } + int sig_child = SIGCHLD; void sig_hangupblock() { sig_block(SIGHUP); } + void sig_hangupunblock() { sig_unblock(SIGHUP); @@ -106,16 +115,19 @@ void sig_hangupcatch(f) void (*f)(); { sig_catch(SIGHUP, f); } + void sig_hangupdefault() { sig_catch(SIGHUP, SIG_DFL); } + int sig_hangup = SIGHUP; void sig_termblock() { sig_block(SIGTERM); } + void sig_termunblock() { sig_unblock(SIGTERM); @@ -124,10 +136,12 @@ void sig_termcatch(f) void (*f)(); { sig_catch(SIGTERM, f); } + void sig_termdefault() { sig_catch(SIGTERM, SIG_DFL); } + int sig_term = SIGTERM; void sig_bugcatch(void (*f)()) @@ -144,6 +158,7 @@ void sig_bugcatch(void (*f)()) sig_catch(SIGEMT, f); #endif } + void (*sig_defaulthandler)() = SIG_DFL; void sig_miscignore() @@ -160,6 +175,7 @@ void sig_miscignore() sig_catch(SIGXFSZ, SIG_IGN); #endif } + void (*sig_ignorehandler)() = SIG_IGN; int sig_cont = SIGCONT; diff --git a/src/socket_bind.c b/src/socket_bind.c index 0376265..314ffa0 100644 --- a/src/socket_bind.c +++ b/src/socket_bind.c @@ -8,10 +8,10 @@ #include "socket_if.h" /** - @file socket_bind.c - @author djb, fefe, feh - @source qmail, djbdns, ucspi-tcp6 - @brief binding a socket to a local resource + @file socket_bind.c + @author djb, fefe, feh + @source qmail, djbdns, ucspi-tcp6 + @brief binding a socket to a local resource */ int socket_bind4(int s, const char ip[4], uint16 port) diff --git a/src/socket_connect.c b/src/socket_connect.c index a5d5e8f..240d5da 100644 --- a/src/socket_connect.c +++ b/src/socket_connect.c @@ -10,10 +10,10 @@ #include "socket_if.h" /** - @file socket_connect.c - @author djb, fefe, feh, kp - @source qmail, ucscpi-tcp6 - @brief connection to remote IP host + @file socket_connect.c + @author djb, fefe, feh, kp + @source qmail, ucscpi-tcp6 + @brief connection to remote IP host */ int socket_connect6(int s, const char ip[16], uint16 port, uint32 scope_id) diff --git a/src/socket_if.c b/src/socket_if.c index e8e1d54..682f8bd 100644 --- a/src/socket_if.c +++ b/src/socket_if.c @@ -7,10 +7,10 @@ #include <sys/types.h> /** - @file socket_if.c - @author fefe, feh - @source ucspi-tcp6 - @brief interface handling for LLU + @file socket_if.c + @author fefe, feh + @source ucspi-tcp6 + @brief interface handling for LLU */ const unsigned char V4loopback[4] = {127, 0, 0, 1}; diff --git a/src/socket_info.c b/src/socket_info.c index 9300b24..14ec6b0 100644 --- a/src/socket_info.c +++ b/src/socket_info.c @@ -8,10 +8,10 @@ #include "socket_if.h" /** - @file socket_info.c - @author djb, fefe, feh - @source ucspi-tcp6 - @brief querying local and remote info for socket + @file socket_info.c + @author djb, fefe, feh + @source ucspi-tcp6 + @brief querying local and remote info for socket */ int socket_local(int s, char ip[16], uint16 *port, uint32 *scope_id) diff --git a/src/socket_recv.c b/src/socket_recv.c index 03aa311..2fb1e64 100644 --- a/src/socket_recv.c +++ b/src/socket_recv.c @@ -8,10 +8,10 @@ #include "socket_if.h" /** - @file socket_recv.c - @author djb, fefe - @source ucspi-tcp6 - @brief setup receiving socket + @file socket_recv.c + @author djb, fefe + @source ucspi-tcp6 + @brief setup receiving socket */ int socket_recv(int s, char *buf, unsigned int len, char ip[16], uint16 *port, uint32 *scope_id) diff --git a/src/socket_send.c b/src/socket_send.c index 7c919f4..1d0ce56 100644 --- a/src/socket_send.c +++ b/src/socket_send.c @@ -8,10 +8,10 @@ #include "socket_if.h" /** - @file socket_send.c - @author djb, fefe, feh - @source ucspi-tcp6 - @brief setup sending socket + @file socket_send.c + @author djb, fefe, feh + @source ucspi-tcp6 + @brief setup sending socket */ int socket_send4(int s, const char *buf, unsigned int len, const char ip[4], uint16 port) diff --git a/src/socket_tcp.c b/src/socket_tcp.c index 70ada37..f350330 100644 --- a/src/socket_tcp.c +++ b/src/socket_tcp.c @@ -15,54 +15,51 @@ #endif /** - @file socket_tcp.c - @author djb, fefe, feh - @source ucspi-tcp6 - @brief setup TCP stream socket + @file socket_tcp.c + @author djb, fefe, feh + @source ucspi-tcp6 + @brief setup TCP stream socket */ int socket_tcp4(void) { - int s; - - s = socket(AF_INET, SOCK_STREAM, 0); - if (s != -1) + int s = socket(AF_INET, SOCK_STREAM, 0); + if (s != -1) { if (ndelay_on(s) == -1) { close(s); return -1; } + } return s; } int socket_tcp6(void) { - int s; - - s = socket(AF_INET6, SOCK_STREAM, 0); - if (s != -1) + int s = socket(AF_INET6, SOCK_STREAM, 0); + if (s != -1) { if (ndelay_on(s) == -1) { close(s); return -1; } + } return s; } int socket_tcp(void) { - int s; - - s = socket(AF_INET6, SOCK_STREAM, 0); + int s = socket(AF_INET6, SOCK_STREAM, 0); if (s == -1) if (errno == EINVAL || errno == EAFNOSUPPORT || errno == EPROTO || errno == EPROTONOSUPPORT) s = socket(AF_INET, SOCK_STREAM, 0); - if (s != -1) + if (s != -1) { if (ndelay_on(s) == -1) { close(s); return -1; } + } return s; } diff --git a/src/socket_udp.c b/src/socket_udp.c index 2ac6068..59af450 100644 --- a/src/socket_udp.c +++ b/src/socket_udp.c @@ -15,17 +15,15 @@ #endif /** - @file socket_udp.c - @author djb, fefe, feh - @source ucspi-tcp6 - @brief setup a UDP message socket + @file socket_udp.c + @author djb, fefe, feh + @source ucspi-tcp6 + @brief setup a UDP message socket */ int socket_udp6(void) { - int s; - - s = socket(AF_INET6, SOCK_DGRAM, 0); + int s = socket(AF_INET6, SOCK_DGRAM, 0); if (s != -1) if (ndelay_on(s) == -1) { close(s); @@ -37,9 +35,7 @@ int socket_udp6(void) int socket_udp4(void) { - int s; - - s = socket(AF_INET, SOCK_DGRAM, 0); + int s = socket(AF_INET, SOCK_DGRAM, 0); if (s != -1) if (ndelay_on(s) == -1) { close(s); @@ -51,9 +47,7 @@ int socket_udp4(void) int socket_udp(void) { - int s; - - s = socket(AF_INET6, SOCK_DGRAM, 0); + int s = socket(AF_INET6, SOCK_DGRAM, 0); if (s == -1) if (errno == EINVAL || errno == EAFNOSUPPORT || errno == EPROTO || errno == EPROTONOSUPPORT) s = socket(AF_INET, SOCK_DGRAM, 0); @@ -3,20 +3,19 @@ #include "stralloc.h" /** - @file str.c - @author djb - @source qmail - @brief string handling functions + @file str.c + @author djb + @source qmail + @brief string handling functions */ -unsigned int str_copy(register char *s, register const char *t) +unsigned int str_copy(char *s, const char *t) { - register int len; + int len = 0; - len = 0; for (;;) { // clang-format off - if (!(*s = *t)) { return len; } ++s; ++t; ++len; + if (!(*s = *t)) { return len; } ++s; ++t; ++len; if (!(*s = *t)) { return len; } ++s; ++t; ++len; if (!(*s = *t)) { return len; } ++s; ++t; ++len; if (!(*s = *t)) { return len; } ++s; ++t; ++len; @@ -24,11 +23,9 @@ unsigned int str_copy(register char *s, register const char *t) } } -unsigned int str_copyb(register char *s, register const char *t, unsigned int max) +unsigned int str_copyb(char *s, const char *t, unsigned int max) { - register int len; - - len = 0; + int len = 0; while (max-- > 0) { // clang-format off @@ -42,9 +39,9 @@ unsigned int str_copyb(register char *s, register const char *t, unsigned int ma return len; } -int str_diff(register const char *s, register const char *t) +int str_diff(const char *s, const char *t) { - register char x; + char x; for (;;) { // clang-format off @@ -57,9 +54,9 @@ int str_diff(register const char *s, register const char *t) return ((int)(unsigned int)(unsigned char)x) - ((int)(unsigned int)(unsigned char)*t); } -int str_diffn(register const char *s, register const char *t, unsigned int len) +int str_diffn(const char *s, const char *t, unsigned int len) { - register char x; + char x; for (;;) { // clang-format off @@ -72,11 +69,10 @@ int str_diffn(register const char *s, register const char *t, unsigned int len) return ((int)(unsigned int)(unsigned char)x) - ((int)(unsigned int)(unsigned char)*t); } -unsigned int str_len(register const char *s) +unsigned int str_len(const char *s) { - register const char *t; + const char *t = s; - t = s; for (;;) { // clang-format off if (!*t) { return t - s; } ++t; @@ -87,13 +83,11 @@ unsigned int str_len(register const char *s) } } -unsigned int str_chr(register const char *s, int c) +unsigned int str_chr(const char *s, int c) { - register char ch; - register const char *t; + char ch = c; + const char *t = s; - ch = c; - t = s; for (;;) { // clang-format off if (!*t) { break; } if (*t == ch) { break; } ++t; @@ -105,15 +99,12 @@ unsigned int str_chr(register const char *s, int c) return t - s; } -unsigned int str_rchr(register const char *s, int c) +unsigned int str_rchr(const char *s, int c) { - register char ch; - register const char *t; - register const char *u; + char ch = c; + const char *t = s; + const char *u = 0; - ch = c; - t = s; - u = 0; for (;;) { // clang-format off if (!*t) { break; } if (*t == ch) { u = t; } ++t; @@ -126,9 +117,9 @@ unsigned int str_rchr(register const char *s, int c) return u - s; } -int str_start(register const char *s, register const char *t) +int str_start(const char *s, const char *t) { - register char x; + char x; for (;;) { // clang-format off diff --git a/src/stralloc.c b/src/stralloc.c index 8cd8a10..8351473 100644 --- a/src/stralloc.c +++ b/src/stralloc.c @@ -7,10 +7,10 @@ #include "str.h" /** - @file stralloc.c - @author djb - @source qmail, ucspi-tcp - @brief genious dynamic string handling + @file stralloc.c + @author djb + @source qmail, ucspi-tcp + @brief genious dynamic string handling */ int stralloc_starts(stralloc *sa, const char *s) @@ -48,10 +48,10 @@ int stralloc_copy(stralloc *sato, stralloc *safrom) int stralloc_ready(stralloc *sa, size_t len) { - register size_t wanted = len + (len >> 3) + 30; /* heuristic from djb */ + size_t wanted = len + (len >> 3) + 30; /* heuristic from djb */ if (wanted < len) wanted = len; if (!sa->s || sa->a < len) { - register char *tmp; + char *tmp; if (!(tmp = realloc(sa->s, wanted))) // !!! needs stdlib (realloc) return 0; sa->a = wanted; @@ -3,10 +3,10 @@ #include <time.h> /** - @file tai.c - @author djb - @source qmail - @brief 'temps atomic' time handling + @file tai.c + @author djb + @source qmail + @brief 'temps atomic' time handling */ void tai_add(struct tai *t, const struct tai *u, const struct tai *v) @@ -4,10 +4,10 @@ #include <sys/types.h> /** - @file taia.c - @author djb - @source qmail - @brief 'tai' attosecond time handling + @file taia.c + @author djb + @source qmail + @brief 'tai' attosecond time handling */ /* XXX: breaks tai encapsulation */ diff --git a/src/timeout.c b/src/timeout.c index bdc2949..9d34e69 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -6,10 +6,10 @@ #include "iopause.h" /** - @file timeout.c - @author djb - @source qmail - @brief read/write timeout handling + @file timeout.c + @author djb + @source qmail + @brief read/write timeout handling */ int timeoutread(int t, int fd, char *buf, int len) diff --git a/src/timeoutconn.c b/src/timeoutconn.c index 714faef..205db0a 100644 --- a/src/timeoutconn.c +++ b/src/timeoutconn.c @@ -30,9 +30,9 @@ int timeoutconn4(int s, char ip[4], uint16 port, unsigned int timeout) for (;;) { taia_now(&now); iopause(&x, 1, &deadline, &now); - if (x.revents) break; /* 's' available */ + if (x.revents) break; // 's' available if (taia_less(&deadline, &now)) { - errno = ETIMEDOUT; /* note that connect attempt is continuing */ + errno = ETIMEDOUT; // note that connect attempt is continuing return -1; } p++; @@ -61,9 +61,9 @@ int timeoutconn6(int s, char ip[16], uint16 port, unsigned int timeout, uint32 n for (;;) { taia_now(&now); iopause(&x, 1, &deadline, &now); - if (x.revents) break; /* 's' available */ + if (x.revents) break; // 's' available if (taia_less(&deadline, &now)) { - errno = ETIMEDOUT; /* note that connect attempt is continuing */ + errno = ETIMEDOUT; // note that connect attempt is continuing return -1; } p++; @@ -98,9 +98,9 @@ int timeoutconn(int s, char ip[16], uint16 port, unsigned int timeout, uint32 ne for (;;) { taia_now(&now); iopause(&x, 1, &deadline, &now); - if (x.revents) break; /* 's' available */ + if (x.revents) break; // 's' available if (taia_less(&deadline, &now)) { - errno = ETIMEDOUT; /* note that connect attempt is continuing */ + errno = ETIMEDOUT; // note that connect attempt is continuing return -1; } p++; diff --git a/src/uint128p.c b/src/uint128p.c index a06da72..e92b5a7 100644 --- a/src/uint128p.c +++ b/src/uint128p.c @@ -1,10 +1,10 @@ #include "uint_t.h" /** - @file uint128p.c - @author feh, jannis - @source djbdns6 - @brief packing/unpacking 128 bit integer to/from char string + @file uint128p.c + @author feh, jannis + @source djbdns6 + @brief packing/unpacking 128 bit integer to/from char string */ void uint128_pack(char s[16], uint128 u) @@ -29,6 +29,7 @@ void uint128_pack(char s[16], uint128 u) s[15] = u.hi & 255; // clang-format on } + void uint128_pack_big(char s[16], uint128 u) { // clang-format off @@ -67,7 +68,7 @@ void uint128_unpack(char s[16], uint128 *u) result.hi += (unsigned char) s[9]; result.hi <<= 8; result.hi += (unsigned char) s[8]; //correct - result.lo += (unsigned char) s[7]; result.lo <<= 8; + result.lo += (unsigned char) s[7]; result.lo <<= 8; result.lo += (unsigned char) s[6]; result.lo <<= 8; result.lo += (unsigned char) s[5]; result.lo <<= 8; result.lo += (unsigned char) s[4]; result.lo <<= 8; @@ -93,7 +94,7 @@ void uint128_unpack_big(char s[16], uint128 *u) result.hi += (unsigned char) s[5]; result.hi <<= 8; result.hi += (unsigned char) s[6]; result.hi <<= 8; result.hi += (unsigned char) s[7]; - + result.lo += (unsigned char) s[8]; result.lo <<= 8; result.lo += (unsigned char) s[9]; result.lo <<= 8; result.lo += (unsigned char) s[10]; result.lo <<= 8; diff --git a/src/uint16p.c b/src/uint16p.c index b470e50..06556e4 100644 --- a/src/uint16p.c +++ b/src/uint16p.c @@ -1,10 +1,10 @@ #include "uint_t.h" /** - @file uint16p.c - @author djb - @source qmail - @brief packing/unpacking 16 bit integer to/from char string + @file uint16p.c + @author djb + @source qmail + @brief packing/unpacking 16 bit integer to/from char string */ void uint16_pack(char s[2], uint16 u) diff --git a/src/uint32p.c b/src/uint32p.c index 7fe5237..de96958 100644 --- a/src/uint32p.c +++ b/src/uint32p.c @@ -1,10 +1,10 @@ #include "uint_t.h" /** - @file uint32p.c - @author djb - @source qmail - @brief packing/unpacking 32 bit integer to/from char string + @file uint32p.c + @author djb + @source qmail + @brief packing/unpacking 32 bit integer to/from char string */ void uint32_pack(char s[4], uint32 u) diff --git a/src/uint64p.c b/src/uint64p.c index 84a4885..4631bce 100644 --- a/src/uint64p.c +++ b/src/uint64p.c @@ -1,10 +1,10 @@ #include "uint_t.h" /** - @file uint64p.c - @author feh, jannis - @source djbdns6 - @brief packing/unpacking 64 bit integer to/from char string + @file uint64p.c + @author feh, jannis + @source djbdns6 + @brief packing/unpacking 64 bit integer to/from char string */ void uint64_pack(char s[8], uint64 u) diff --git a/src/uint8p.c b/src/uint8p.c index 71513cd..d3921d9 100644 --- a/src/uint8p.c +++ b/src/uint8p.c @@ -1,9 +1,9 @@ #include "uint_t.h" /** - @file uint8x.c - @author feh - @brief packing/unpacking 8 bit int to/from char string + @file uint8x.c + @author feh + @brief packing/unpacking 8 bit int to/from char string */ void uint8_pack(char s[2], uint8 u) @@ -1,13 +1,15 @@ +#include "wait.h" + #include <sys/types.h> #include <sys/wait.h> #include "logmsg.h" /** - @file wait.c - @author djb - @source qmail - @brief wait for forked processes + @file wait.c + @author djb + @source qmail + @brief wait for forked processes */ int wait_nohang(int *wstat) |