6 #include <sys/socket.h>
18 if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &size,
sizeof(
int)) < 0)
19 INFO(
"(no sockopt/1: %m)");
23 if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &size,
sizeof(
int)) < 0)
24 INFO(
"(no sockopt/2: %m)");
28 if (setsockopt(sock, IPPROTO_TCP, TCP_MAXSEG, &size,
sizeof(
int)) < 0)
29 INFO(
"(no sockopt/3: %m)");
36 strncpy(s1, s,
sizeof(s1));
37 if ((s2 = strstr(s,
"%m"))) {
38 strcpy(s1 + (s2 - s), strerror(errno));
40 strcpy(s1 + strlen(s1), s2);
44 else if ((s2 = strstr(s,
"%h"))) {
45 strcpy(s1 + (s2 - s), hstrerror(h_errno));
47 strcpy(s1 + strlen(s1), s2);
51 s1[
sizeof(s1)-1] =
'\0';
53 syslog(LOG_ERR,
"%s", s1);
54 syslog(LOG_ERR,
"Exiting.");
56 fprintf(stderr,
"Error: %s\nExiting.\n", s1);
59 void err(
const char *s) {
66 openlog(name, LOG_PID, LOG_DAEMON);
68 setvbuf(stdout, NULL, _IONBF, 0);
69 setvbuf(stderr, NULL, _IONBF, 0);
73 #ifdef WORDS_BIGENDIAN
74 uint64_t
ntohll(uint64_t a) {
79 u32 lo = a & 0xffffffff;
83 return ((uint64_t) lo) << 32U | hi;
99 res = read(f, buf, len);
103 }
else if (res < 0) {
104 if(errno != EAGAIN) {
105 err(
"Read failed: %m");
108 err(
"Read failed: End of file");
void setmysockopt(int sock)
void err_nonfatal(const char *s)
void readit(int f, void *buf, size_t len)
Read data from a file descriptor into a buffer.
uint64_t ntohll(uint64_t a)
void logging(const char *name)