summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-09 15:50:21 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-09 15:50:21 +0200
commit795ffc5e62e8ba383575dbcd9943a580d4bd3358 (patch)
treec128889056202b255e2f22afeb7717894d350862 /src
parent5fadc0cbb8577c61d66bd6f19ceaf0507c11e23b (diff)
formatting changes
Manual format adjustments. Comment adjustments. Remove usage of the register keyword.
Diffstat (limited to 'src')
-rw-r--r--src/base64.c8
-rw-r--r--src/buffer.c6
-rw-r--r--src/byte.c46
-rw-r--r--src/case.c36
-rw-r--r--src/cdbmake.c8
-rw-r--r--src/cdbread.c8
-rw-r--r--src/dnsstub/README.md171
-rw-r--r--src/dnsstub/dns_cname.c6
-rw-r--r--src/dnsstub/dns_dfd.c8
-rw-r--r--src/dnsstub/dns_domain.c8
-rw-r--r--src/dnsstub/dns_dtda.c8
-rw-r--r--src/dnsstub/dns_ip.c8
-rw-r--r--src/dnsstub/dns_ipq.c12
-rw-r--r--src/dnsstub/dns_mx.c13
-rw-r--r--src/dnsstub/dns_name.c11
-rw-r--r--src/dnsstub/dns_nd.c8
-rw-r--r--src/dnsstub/dns_packet.c10
-rw-r--r--src/dnsstub/dns_random.c8
-rw-r--r--src/dnsstub/dns_rcip.c28
-rw-r--r--src/dnsstub/dns_rcrw.c14
-rw-r--r--src/dnsstub/dns_resolve.c8
-rw-r--r--src/dnsstub/dns_sortip.c12
-rw-r--r--src/dnsstub/dns_transmit.c10
-rw-r--r--src/dnsstub/dns_txt.c3
-rw-r--r--src/env.c11
-rw-r--r--src/errstr.c271
-rw-r--r--src/fd.c8
-rw-r--r--src/fmt.c41
-rw-r--r--src/getln.c12
-rw-r--r--src/getoptb.c11
-rw-r--r--src/iopause.c12
-rw-r--r--src/ip4.c10
-rw-r--r--src/ip6.c29
-rw-r--r--src/lock.c12
-rw-r--r--src/logmsg.c8
-rw-r--r--src/ndelay.c8
-rw-r--r--src/open.c8
-rw-r--r--src/pathexec.c8
-rw-r--r--src/prot.c12
-rw-r--r--src/readclose.c8
-rw-r--r--src/scan.c54
-rw-r--r--src/seek.c8
-rw-r--r--src/sig.c24
-rw-r--r--src/socket_bind.c8
-rw-r--r--src/socket_connect.c8
-rw-r--r--src/socket_if.c8
-rw-r--r--src/socket_info.c8
-rw-r--r--src/socket_recv.c8
-rw-r--r--src/socket_send.c8
-rw-r--r--src/socket_tcp.c29
-rw-r--r--src/socket_udp.c20
-rw-r--r--src/str.c57
-rw-r--r--src/stralloc.c12
-rw-r--r--src/tai.c8
-rw-r--r--src/taia.c8
-rw-r--r--src/timeout.c8
-rw-r--r--src/timeoutconn.c12
-rw-r--r--src/uint128p.c13
-rw-r--r--src/uint16p.c8
-rw-r--r--src/uint32p.c8
-rw-r--r--src/uint64p.c8
-rw-r--r--src/uint8p.c6
-rw-r--r--src/wait.c10
63 files changed, 555 insertions, 713 deletions
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)
diff --git a/src/byte.c b/src/byte.c
index e113cc3..51f18e1 100644
--- a/src/byte.c
+++ b/src/byte.c
@@ -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;
diff --git a/src/case.c b/src/case.c
index fa5c86b..8303d8f 100644
--- a/src/case.c
+++ b/src/case.c
@@ -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/README.md b/src/dnsstub/README.md
deleted file mode 100644
index 95cd11c..0000000
--- a/src/dnsstub/README.md
+++ /dev/null
@@ -1,171 +0,0 @@
-/*! \mainpage
-
-Stub Resolver
-=============
-
-Simple DJBDNS stub-resolver based on 'djbdns-1.05(IPv6)' allowing for each
-calling application individually to include up to 16 DNSCACHEIP(s)
-as DNS forwarding/resolving servers to be tried sequentially.
-
-IP Addresses
-------------
-
-Here,
- - global IPv6,
- - IPv6 ULA, and
- - IPv6 LLU addresses with a given Interface-Id
-can be specified. The IPv4 format could be either a
- - legacy dotted-decimal or a
- - IPv4-mapped IPv6 address.
-
-In any case, compactified IPv6 addresses are understood.
-IPv4/IPv6 addresses in brackets are understood by dns_ip.
-
-Resolver Call
--------------
-
-If $DNSCACHEIP is not provided as environment variable, the stub-resolver
-will use the system-wide
- - /etc/resolv.conf
-file; however now without the capability for IPv6 LLU addresses.
-While IPv4-mapped IPv6 addresses are supported here by default as well,
-care has to taken not to jeopardize other client's usage.
-
-Name Qualification
-------------------
-
-If provided, the stub-resolver uses either a system-wide configuration file
- - /etc/dnsrewritefile or assumes this file to available as given in
- - $DNSREWRITEFILE
-in order to define persistent mapping-rules of local domain names to public
-ones (for lookup) or IP addresses (for direct matching).
-
-Well-known domain names 'localhost', 'ip4-loopback' and 'ip6-loopback'
-are handled locally, thus no DNS query is used (RFC 6761).
-'localhost' is advertised as '::1' and '::ff:127.0.0.1' in it's native
-IPv6 format. It is up to the caller to convert the IPv6-mapped IPv4
-address to the IPv4 format.
-
-Local domain names can be alternatively specified (per application) using
-the environment variable
- - $LOCALDOMAIN
-to be appended to unqualified hostnames dynamically. This is roughly equivalent
-with the 'search' string in /etc/resolv. Several domains names may be
-specified within $LOCALDOMAIN separated by blanks.
-
-See: https://cr.yp.to/djbdns/qualify.html
-
-
-Specific DNS Record type lookup
--------------------------------
-
-* dns_ip (A, AAAAA)
-* dns_name (PTR)
-* dns_cname (CNAME)
-* dns_txt (TXT) -- now considering several 'labels'
-* dns_mx (MX)
-
-
-Internals
----------
-
-* UDP message size:
-Unlike other implementations, this DNS stub-resolver supports UDP packet
-sizes up to 1028 byte without the need for (E)DNS0 packet enhancements.
-
-* DNS UDP query retrials:
-In case the NS is not able to initally reply to the query,
-it is retried again at the intervalls {1, 2, 4, 8, 16} secs.
-
-* DNS name qualification (dns_ip_qualify):
-Well-known domain names are qualified locally without invoking a DNS query
-while handling IPv4 and IPv6 addresses separately.
-
-* NS qualification/sorting for NS replies:
-NS qualification is not supported (yet), thus we use a randomly sorted
-list of NS IP addresses.
-
-* Query/Reply to/from DNS Cache servers/forwarders:
-Neither message (CurveDNS) nor transport layer (TLS) encryption is provided;
-the sub-resolver 'trusts' it's upstream caches/forwarders. We recommend to
-setup communication on private IPv4/IPv6 addresses; if applicable.
-
-* DNS TXT Records:
-The label substructure is now recognized in the RDATA section;
-each label may have the size of 255 byte.
-The length information is excluded from the output.
-Only printable characters are recognized in the output.
-
-* Return Codes:
-Different from DJB's initial routines, the DNS front-end routines
- dns_cname*, dns_ip*, dns_mx*, dns_name*, dns dns_txt*
-return now the number of replies received (not bytes!).
-Thus, three cases need to be considered:
-
- - rc < 0: Problem occured (SOFTFAIL, HARDFAIL)
- - rc = 0: No answer obtained (but query was successful) = NXDOMAIN
- - rc > 0: rc answers received; positive reply
-
-For return codes < 0, the following conventions have been applied:
-
- include/dnsresolv.h
-
-\#define DNS_NXD 0
-\#define DNS_MEM -1
-\#define DNS_ERR -2 /* parsing errors and others */
-\#define DNS_COM -3 /* (socket) communication errors */
-\#define DNS_INT -4 /* internal errors */
-\#define DNS_SOFT -5 /* either -2 or -3 */
-\#define DNS_HARD -6 /* CNAME loop problem */
-
-The modification of the return code is typically not problematic,
-since mostly just rc = -1 is checked.
-
-In the future, these return codes are subject of change.
-Thus, instead of
-
- if (dns_XX(...) == -1)
-
-one shoud use the more general syntax
-
- if (dns_XX(...) < 0)
-
-to check for 'negative' results, allowing further actions
-and refinements given the calling sequence.
-
-
-
-Environment Variables Read
---------------------------
-
-$DNSCACHEPIP The upstream resolver's IP[v4|v6] addresses (up to 32).
- IPv6 LLU addresses may be suffixed with the interface name.
-$DNSREWRITEFILE Alternate location for the system-wide
- /etc/dnsrewrite
-file
-$LOCALDOMAIN Additional local domain name appended to unqualified
- hostnames dynamically.
-
-Sample for the file /etc/dnsrewrite:
-
-\#annything.local -> me
-\-.example.com:me
-\# me -> 127.0.0.1
-\=me:127.0.0.1
-\# any.name.a -> any.name.af.mil
-\*.a:.af.mil
-\# any-name-without-dots -> any-name-without-dots.heaven.af.mil
-\?:.heaven.af.mil
-\# remove trailing dot
-\*.:
-
-and DJB's explanations are given here:
-
-Instructions are followed in order, each at most once. There are four types of instructions:
-
-\=post:new means that the host name post is replaced by new.
-\*post:new means that any name of the form prepost is replaced by prenew.
-\?post:new means that any name of the form prepost, where pre does not contain dots or brackets, is replaced by prenew.
-\-post:new means that any name of the form prepost is replaced by new.
-
-Erwin Hoffmann, June 2023.
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)
diff --git a/src/env.c b/src/env.c
index 7f4afe5..4d7d2aa 100644
--- a/src/env.c
+++ b/src/env.c
@@ -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
}
diff --git a/src/fd.c b/src/fd.c
index ad20812..f722f1a 100644
--- a/src/fd.c
+++ b/src/fd.c
@@ -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 */
diff --git a/src/fmt.c b/src/fmt.c
index eaf98fb..77a3c93 100644
--- a/src/fmt.c
+++ b/src/fmt.c
@@ -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);
diff --git a/src/ip4.c b/src/ip4.c
index c9ab153..6e522aa 100644
--- a/src/ip4.c
+++ b/src/ip4.c
@@ -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
diff --git a/src/ip6.c b/src/ip6.c
index b7b4540..e5a7214 100644
--- a/src/ip6.c
+++ b/src/ip6.c
@@ -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
*/
diff --git a/src/lock.c b/src/lock.c
index cec290e..cadb07c 100644
--- a/src/lock.c
+++ b/src/lock.c
@@ -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
diff --git a/src/open.c b/src/open.c
index 3e00adb..d2f3f4c 100644
--- a/src/open.c
+++ b/src/open.c
@@ -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;
diff --git a/src/prot.c b/src/prot.c
index 69b2f5b..0fe59c5 100644
--- a/src/prot.c
+++ b/src/prot.c
@@ -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.
*/
diff --git a/src/scan.c b/src/scan.c
index 4d6b918..da271f3 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -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;
diff --git a/src/seek.c b/src/seek.c
index b402625..fd23be2 100644
--- a/src/seek.c
+++ b/src/seek.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);
diff --git a/src/sig.c b/src/sig.c
index 1ea3316..bf8510e 100644
--- a/src/sig.c
+++ b/src/sig.c
@@ -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);
diff --git a/src/str.c b/src/str.c
index 5294f99..5ce8331 100644
--- a/src/str.c
+++ b/src/str.c
@@ -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;
diff --git a/src/tai.c b/src/tai.c
index e83af53..50bb2fe 100644
--- a/src/tai.c
+++ b/src/tai.c
@@ -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)
diff --git a/src/taia.c b/src/taia.c
index 3b8cb8a..df544ac 100644
--- a/src/taia.c
+++ b/src/taia.c
@@ -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)
diff --git a/src/wait.c b/src/wait.c
index ab58828..0888df2 100644
--- a/src/wait.c
+++ b/src/wait.c
@@ -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)