6 #include <sys/socket.h>
11 const u64 cliserv_magic
= 0x00420281861253LL
;
12 const u64 opts_magic
= 0x49484156454F5054LL
;
13 const u64 rep_magic
= 0x3e889045565a9LL
;
15 void setmysockopt(int sock
) {
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)");
33 void err_nonfatal(const char *s
) {
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
);
43 /* Solaris doesn't have %h in syslog */
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
) {
64 void logging(const char* name
) {
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
) {
78 uint64_t ntohll(uint64_t a
) {
79 u32 lo
= a
& 0xffffffff;
83 return ((uint64_t) lo
) << 32U | hi
;
89 * Read data from a file descriptor into a buffer
91 * @param f a file descriptor
93 * @param len the number of bytes to be read
95 void readit(int f
, void *buf
, size_t len
) {
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");