int32_t nbytes;
int32_t pktsiz;
+ ASSERT(bsock != NULL);
mp_chr(bsock->msg)[0] = 0;
if (bsock->errors || bsock->terminated) {
return BNET_HARDEOF;
if (nbytes != sizeof(int32_t)) {
bsock->errors++;
bsock->b_errno = EIO;
- Jmsg3(bsock->jcr, M_ERROR, 0, _("Read %d expected %d from %s\n"), nbytes, sizeof(int32_t),
- bsock->who);
+ Jmsg5(bsock->jcr, M_ERROR, 0, _("Read expected %d got %d from %s:%s:%d\n"), pktsiz, nbytes,
+ bsock->who, bsock->host, bsock->port);
return BNET_ERROR;
}
/* If signal or packet size too big */
if (pktsiz < 0 || pktsiz > 1000000) {
if (pktsiz > 0) { /* if packet too big */
+ Jmsg3(bsock->jcr, M_FATAL, 0,
+ _("Packet size too big from \"%s:%s:%d. Terminating connection.\n"),
+ bsock->who, bsock->host, bsock->port);
pktsiz = BNET_TERMINATE; /* hang up */
}
if (pktsiz == BNET_TERMINATE) {
bsock->msglen = ntohl(pktsiz);
if (bsock->msglen > 0) {
if (bsock->msglen > (int32_t)sizeof_pool_memory(bsock->msg)) {
- bsock->msg = realloc_pool_memory(bsock->msg, bsock->msglen);
+ bsock->msg = realloc_pool_memory(bsock->msg, bsock->msglen + 1);
}
nbytes = fread(bsock->msg, 1, bsock->msglen, bsock->spool_fd);
if (nbytes != (size_t)bsock->msglen) {
{
int32_t rc;
int32_t pktsiz;
+ int32_t msglen;
if (bsock->errors || bsock->terminated) {
return 0;
}
+ msglen = bsock->msglen;
+ ASSERT(bsock->msglen < 1000000);
pktsiz = htonl((int32_t)bsock->msglen);
/* send int32_t containing size of data packet */
bsock->timer_start = watchdog_time; /* start timer */
bsock->b_errno = errno;
}
if (rc < 0) {
- if (!bsock->suppress_error_msgs) {
+ if (!bsock->suppress_error_msgs && !bsock->timed_out) {
Jmsg4(bsock->jcr, M_ERROR, 0, _("Write error sending to %s:%s:%d: ERR=%s\n"),
bsock->who, bsock->host, bsock->port, bnet_strerror(bsock));
}
bsock->out_msg_no++; /* increment message number */
if (bsock->msglen <= 0) { /* length only? */
+ ASSERT(msglen == bsock->msglen);
return 1; /* yes, no data */
}
}
return 0;
}
+ ASSERT(msglen == bsock->msglen);
return 1;
}
}
}
+#ifndef NETDB_INTERNAL
+#define NETDB_INTERNAL -1 /* See errno. */
+#endif
+#ifndef NETDB_SUCCESS
+#define NETDB_SUCCESS 0 /* No problem. */
+#endif
+#ifndef HOST_NOT_FOUND
+#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
+#endif
+#ifndef TRY_AGAIN
+#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL. */
+#endif
+#ifndef NO_RECOVERY
+#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP. */
+#endif
+#ifndef NO_DATA
+#define NO_DATA 4 /* Valid name, no data record of requested type. */
+#endif
+
+extern int h_errno; /* On error has one of the above */
+
+/*
+ * Get human readable error for gethostbyname()
+ */
+static char *gethost_strerror()
+{
+ switch (h_errno) {
+ case NETDB_INTERNAL:
+ return strerror(errno);
+ case NETDB_SUCCESS:
+ return "No problem.";
+ case HOST_NOT_FOUND:
+ return "Authoritative answer Host not found.";
+ case TRY_AGAIN:
+ return "Non-authoritative Host not found, or ServerFail.";
+ case NO_RECOVERY:
+ return "Non-recoverable errors, FORMERR, REFUSED, or NOTIMP.";
+ case NO_DATA:
+ return "Valid name, no data record of resquested type.";
+ default:
+ return "Unknown error.";
+ }
+}
+
static pthread_mutex_t ip_mutex = PTHREAD_MUTEX_INITIALIZER;
P(ip_mutex);
if ((hp = gethostbyname(host)) == NULL) {
Jmsg2(jcr, M_ERROR, 0, "gethostbyname() for %s failed: ERR=%s\n",
- host, strerror(errno));
+ host, gethost_strerror());
V(ip_mutex);
return NULL;
}
i++;
}
i++;
- addr_list = (uint32_t *) malloc(sizeof(uint32_t) * i);
+ addr_list = (uint32_t *)malloc(sizeof(uint32_t) * i);
i = 0;
for (p = hp->h_addr_list; *p != 0; p++) {
addr_list[i++] = (*(struct in_addr **)p)->s_addr;
va_list arg_ptr;
int maxlen;
+ if (bs->errors || bs->terminated) {
+ return 0;
+ }
/* This probably won't work, but we vsnprintf, then if we
* get a negative length or a length greater than our buffer
* (depending on which library is used), the printf was truncated, so
bs->msglen = bvsnprintf(mp_chr(bs->msg), maxlen, fmt, arg_ptr);
va_end(arg_ptr);
if (bs->msglen < 0 || bs->msglen >= maxlen) {
- bs->msg = realloc_pool_memory(bs->msg, maxlen + 200);
+ bs->msg = realloc_pool_memory(bs->msg, maxlen + maxlen / 2);
goto again;
}
- return bnet_send(bs) < 0 ? 0 : 1;
+ return bnet_send(bs);
}
/*