@@ -121,8 +121,8 @@ int cksum(struct mbuf *m, int len)
cont:
if (len) {
- DEBUG_ERROR("cksum: out of data\n");
- DEBUG_ERROR(" len = %d\n", len);
+ DEBUG_ERROR("cksum: out of data");
+ DEBUG_ERROR(" len = %d", len);
}
if (mlen == -1) {
/* The last mbuf has odd # of bytes. Follow the
@@ -12,38 +12,29 @@
#define DBG_MISC 0x2
#define DBG_ERROR 0x4
-#define dfd stderr
-
extern int slirp_debug;
#define DEBUG_CALL(fmt, ...) do { \
if (slirp_debug & DBG_CALL) { \
- fprintf(dfd, fmt, ##__VA_ARGS__); \
- fprintf(dfd, "...\n"); \
- fflush(dfd); \
+ g_debug(fmt "...", ##__VA_ARGS__); \
} \
} while (0)
#define DEBUG_ARG(fmt, ...) do { \
if (slirp_debug & DBG_CALL) { \
- fputc(' ', dfd); \
- fprintf(dfd, fmt, ##__VA_ARGS__); \
- fputc('\n', dfd); \
- fflush(dfd); \
+ g_debug(" " fmt, ##__VA_ARGS__); \
} \
} while (0)
#define DEBUG_MISC(fmt, ...) do { \
if (slirp_debug & DBG_MISC) { \
- fprintf(dfd, fmt, ##__VA_ARGS__); \
- fflush(dfd); \
+ g_debug(fmt, ##__VA_ARGS__); \
} \
} while (0)
#define DEBUG_ERROR(fmt, ...) do { \
if (slirp_debug & DBG_ERROR) { \
- fprintf(dfd, fmt, ##__VA_ARGS__); \
- fflush(dfd); \
+ g_debug(fmt, ##__VA_ARGS__); \
} \
} while (0)
@@ -92,13 +92,13 @@ static int dhcpv6_parse_info_request(Slirp *slirp, uint8_t *odata, int olen,
ri->want_boot_url = true;
break;
default:
- DEBUG_MISC("dhcpv6: Unsupported option request %d\n",
+ DEBUG_MISC("dhcpv6: Unsupported option request %d",
req_opt);
}
}
break;
default:
- DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d\n",
+ DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d",
option, len);
}
@@ -203,6 +203,6 @@ void dhcpv6_input(struct sockaddr_in6 *srcsas, struct mbuf *m)
dhcpv6_info_request(m->slirp, srcsas, xid, &data[4], data_len - 4);
break;
default:
- DEBUG_MISC("dhcpv6_input: Unsupported message type 0x%x\n", data[0]);
+ DEBUG_MISC("dhcpv6_input: Unsupported message type 0x%x", data[0]);
}
}
@@ -103,7 +103,7 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
if (sendto(so->s, m->m_data + hlen, m->m_len - hlen, 0,
(struct sockaddr *)&addr, sizeof(addr)) == -1) {
- DEBUG_MISC("icmp_input icmp sendto tx errno = %d-%s\n",
+ DEBUG_MISC("icmp_input icmp sendto tx errno = %d-%s",
errno, strerror(errno));
icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
icmp_detach(so);
@@ -169,7 +169,7 @@ icmp_input(struct mbuf *m, int hlen)
return;
}
if (udp_attach(so, AF_INET) == -1) {
- DEBUG_MISC("icmp_input udp_attach errno = %d-%s\n",
+ DEBUG_MISC("icmp_input udp_attach errno = %d-%s",
errno,strerror(errno));
sofree(so);
m_free(m);
@@ -192,7 +192,7 @@ icmp_input(struct mbuf *m, int hlen)
if(sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0,
(struct sockaddr *)&addr, sockaddr_size(&addr)) == -1) {
- DEBUG_MISC("icmp_input udp sendto tx errno = %d-%s\n",
+ DEBUG_MISC("icmp_input udp sendto tx errno = %d-%s",
errno,strerror(errno));
icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
udp_detach(so);
@@ -261,7 +261,7 @@ icmp_send_error(struct mbuf *msrc, u_char type, u_char code, int minsize,
char bufa[20], bufb[20];
strcpy(bufa, inet_ntoa(ip->ip_src));
strcpy(bufb, inet_ntoa(ip->ip_dst));
- DEBUG_MISC(" %.16s to %.16s\n", bufa, bufb);
+ DEBUG_MISC(" %.16s to %.16s", bufa, bufb);
}
if(ip->ip_off & IP_OFFMASK) goto end_error; /* Only reply to fragment 0 */
@@ -458,7 +458,7 @@ void icmp_receive(struct socket *so)
} else {
error_code = ICMP_UNREACH_HOST;
}
- DEBUG_MISC(" udp icmp rx errno = %d-%s\n", errno,
+ DEBUG_MISC(" udp icmp rx errno = %d-%s", errno,
strerror(errno));
icmp_send_error(so->so_m, ICMP_UNREACH, error_code, 0, strerror(errno));
} else {
@@ -166,7 +166,7 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr,
if (!f)
return -1;
- DEBUG_MISC("IP address of your DNS(s): ");
+ DEBUG_MISC("IP address of your DNS(s):");
while (fgets(buff, 512, f) != NULL) {
if (sscanf(buff, "nameserver%*[ \t]%256s", buff2) == 1) {
char *c = strchr(buff2, '%');
@@ -188,20 +188,18 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr,
*scope_id = if_index;
}
*cached_time = curtime;
- } else {
- DEBUG_MISC(", ");
}
if (++found > 3) {
- DEBUG_MISC("(more)");
+ DEBUG_MISC(" (more)");
break;
} else if (slirp_debug & DBG_MISC) {
char s[INET6_ADDRSTRLEN];
const char *res = inet_ntop(af, tmp_addr, s, sizeof(s));
if (!res) {
- res = "(string conversion error)";
+ res = " (string conversion error)";
}
- DEBUG_MISC("%s", res);
+ DEBUG_MISC(" %s", res);
}
}
}
@@ -208,7 +208,8 @@ soread(struct socket *so)
}
}
- DEBUG_MISC(" --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno));
+ DEBUG_MISC(" --- soread() disconnected, nn = %d, errno = %d-%s",
+ nn, errno,strerror(errno));
sofcantrcvmore(so);
if (err == ECONNRESET || err == ECONNREFUSED
@@ -237,7 +238,7 @@ soread(struct socket *so)
nn += ret;
}
- DEBUG_MISC(" ... read nn = %d bytes\n", nn);
+ DEBUG_MISC(" ... read nn = %d bytes", nn);
/* Update fields */
sb->sb_cc += nn;
@@ -370,7 +371,7 @@ sosendoob(struct socket *so)
n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */
#ifdef DEBUG
if (n != len) {
- DEBUG_ERROR("Didn't send all data urgently XXXXX\n");
+ DEBUG_ERROR("Didn't send all data urgently XXXXX");
}
#endif
}
@@ -379,7 +380,7 @@ sosendoob(struct socket *so)
return n;
}
so->so_urgc -= n;
- DEBUG_MISC(" ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc);
+ DEBUG_MISC(" ---2 sent %d bytes urgent data, %d urgent bytes left", n, so->so_urgc);
sb->sb_cc -= n;
sb->sb_rptr += n;
@@ -460,7 +461,7 @@ sowrite(struct socket *so)
if (ret > 0)
nn += ret;
}
- DEBUG_MISC(" ... wrote nn = %d bytes\n", nn);
+ DEBUG_MISC(" ... wrote nn = %d bytes", nn);
/* Update sbuf */
sb->sb_cc -= nn;
@@ -478,7 +479,7 @@ sowrite(struct socket *so)
return nn;
err_disconnected:
- DEBUG_MISC(" --- sowrite disconnected, so->so_state = %x, errno = %d\n",
+ DEBUG_MISC(" --- sowrite disconnected, so->so_state = %x, errno = %d",
so->so_state, errno);
sofcantsendmore(so);
tcp_sockclosed(sototcpcb(so));
@@ -512,7 +513,7 @@ sorecvfrom(struct socket *so)
if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET;
- DEBUG_MISC(" udp icmp rx errno = %d-%s\n",
+ DEBUG_MISC(" udp icmp rx errno = %d-%s",
errno,strerror(errno));
icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno));
} else {
@@ -564,7 +565,7 @@ sorecvfrom(struct socket *so)
m->m_len = recvfrom(so->s, m->m_data, len, 0,
(struct sockaddr *)&addr, &addrlen);
- DEBUG_MISC(" did recvfrom %d, errno = %d-%s\n",
+ DEBUG_MISC(" did recvfrom %d, errno = %d-%s",
m->m_len, errno,strerror(errno));
if(m->m_len<0) {
/* Report error as ICMP */
@@ -579,7 +580,7 @@ sorecvfrom(struct socket *so)
code = ICMP_UNREACH_NET;
}
- DEBUG_MISC(" rx error, tx icmp ICMP_UNREACH:%i\n", code);
+ DEBUG_MISC(" rx error, tx icmp ICMP_UNREACH:%i", code);
icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno));
break;
case AF_INET6:
@@ -591,7 +592,7 @@ sorecvfrom(struct socket *so)
code = ICMP6_UNREACH_NO_ROUTE;
}
- DEBUG_MISC(" rx error, tx icmp6 ICMP_UNREACH:%i\n", code);
+ DEBUG_MISC(" rx error, tx icmp6 ICMP_UNREACH:%i", code);
icmp6_send_error(so->so_m, ICMP6_UNREACH, code);
break;
default:
@@ -839,8 +840,7 @@ void sotranslate_out(struct socket *so, struct sockaddr_storage *addr)
}
}
- DEBUG_MISC(" addr.sin_port=%d, "
- "addr.sin_addr.s_addr=%.16s\n",
+ DEBUG_MISC(" addr.sin_port=%d, addr.sin_addr.s_addr=%.16s",
ntohs(sin->sin_port), inet_ntoa(sin->sin_addr));
break;
@@ -641,8 +641,7 @@ findso:
(errno != EINPROGRESS) && (errno != EWOULDBLOCK)
) {
uint8_t code;
- DEBUG_MISC(" tcp fconnect errno = %d-%s\n",
- errno,strerror(errno));
+ DEBUG_MISC(" tcp fconnect errno = %d-%s", errno, strerror(errno));
if(errno == ECONNREFUSED) {
/* ACK the SYN, send RST to refuse the connection */
tcp_respond(tp, ti, m, ti->ti_seq + 1, (tcp_seq) 0,
@@ -1011,7 +1010,7 @@ trimthenstep6:
if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) {
if (ti->ti_len == 0 && tiwin == tp->snd_wnd) {
- DEBUG_MISC(" dup ack m = %p so = %p\n", m, so);
+ DEBUG_MISC(" dup ack m = %p so = %p", m, so);
/*
* If we have outstanding data (other than
* a window probe), this is a completely
@@ -1550,7 +1549,7 @@ tcp_mss(struct tcpcb *tp, u_int offer)
(mss - (TCP_RCVSPACE % mss)) :
0));
- DEBUG_MISC(" returning mss = %d\n", mss);
+ DEBUG_MISC(" returning mss = %d", mss);
return mss;
}
@@ -92,7 +92,7 @@ again:
flags = tcp_outflags[tp->t_state];
- DEBUG_MISC(" --- tcp_output flags = 0x%x\n", flags);
+ DEBUG_MISC(" --- tcp_output flags = 0x%x", flags);
/*
* If in persist timeout with window of 0, send 1 byte.
@@ -964,7 +964,7 @@ int tcp_ctl(struct socket *so)
so->chardev = ex_ptr->ex_chardev;
return 1;
}
- DEBUG_MISC(" executing %s\n", ex_ptr->ex_exec);
+ DEBUG_MISC(" executing %s", ex_ptr->ex_exec);
return fork_exec(so, ex_ptr->ex_exec);
}
}
@@ -172,8 +172,7 @@ udp_input(register struct mbuf *m, int iphlen)
*/
so = socreate(slirp);
if (udp_attach(so, AF_INET) == -1) {
- DEBUG_MISC(" udp_attach errno = %d-%s\n",
- errno, strerror(errno));
+ DEBUG_MISC(" udp_attach errno = %d-%s", errno, strerror(errno));
sofree(so);
goto bad;
}
@@ -209,7 +208,7 @@ udp_input(register struct mbuf *m, int iphlen)
m->m_len += iphlen;
m->m_data -= iphlen;
*ip=save_ip;
- DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno));
+ DEBUG_MISC("udp tx errno = %d-%s", errno, strerror(errno));
icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0,
strerror(errno));
goto bad;
@@ -92,8 +92,7 @@ void udp6_input(struct mbuf *m)
/* If there's no socket for this packet, create one. */
so = socreate(slirp);
if (udp_attach(so, AF_INET6) == -1) {
- DEBUG_MISC(" udp6_attach errno = %d-%s\n",
- errno, strerror(errno));
+ DEBUG_MISC(" udp6_attach errno = %d-%s", errno, strerror(errno));
sofree(so);
goto bad;
}
@@ -119,7 +118,7 @@ void udp6_input(struct mbuf *m)
m->m_len += iphlen;
m->m_data -= iphlen;
*ip = save_ip;
- DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno));
+ DEBUG_MISC("udp tx errno = %d-%s", errno, strerror(errno));
icmp6_send_error(m, ICMP6_UNREACH, ICMP6_UNREACH_NO_ROUTE);
goto bad;
}