DEBUG_CALL("arp_table_add");
DEBUG_ARG("ip = %s", inet_ntoa((struct in_addr){.s_addr = ip_addr}));
- DEBUG_ARGS((dfd, " hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
- ethaddr[0], ethaddr[1], ethaddr[2],
- ethaddr[3], ethaddr[4], ethaddr[5]));
+ DEBUG_ARGS(" hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+ ethaddr[0], ethaddr[1], ethaddr[2],
+ ethaddr[3], ethaddr[4], ethaddr[5]);
if (ip_addr == 0 || ip_addr == 0xffffffff || ip_addr == broadcast_addr) {
/* Do not register broadcast addresses */
for (i = 0; i < ARP_TABLE_SIZE; i++) {
if (arptbl->table[i].ar_sip == ip_addr) {
memcpy(out_ethaddr, arptbl->table[i].ar_sha, ETH_ALEN);
- DEBUG_ARGS((dfd, " found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
- out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
- out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]));
+ DEBUG_ARGS(" found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+ out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
+ out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]);
return 1;
}
}
static const uint8_t rfc1533_cookie[] = { RFC1533_COOKIE };
#ifdef DEBUG
-#define DPRINTF(fmt, ...) \
-do if (slirp_debug & DBG_CALL) { fprintf(dfd, fmt, ## __VA_ARGS__); fflush(dfd); } while (0)
+#define DPRINTF(fmt, ...) DEBUG_CALL(fmt, ##__VA_ARGS__)
#else
#define DPRINTF(fmt, ...) do{}while(0)
#endif
cont:
#ifdef DEBUG
if (len) {
- DEBUG_ERROR((dfd, "cksum: out of data\n"));
- DEBUG_ERROR((dfd, " len = %d\n", len));
+ DEBUG_ERROR("cksum: out of data\n");
+ DEBUG_ERROR(" len = %d\n", len);
}
#endif
if (mlen == -1) {
extern int slirp_debug;
-#define DEBUG_CALL(x) if (slirp_debug & DBG_CALL) { fprintf(dfd, "%s...\n", x); fflush(dfd); }
-#define DEBUG_ARG(x, y) if (slirp_debug & DBG_CALL) { fputc(' ', dfd); fprintf(dfd, x, y); fputc('\n', dfd); fflush(dfd); }
-#define DEBUG_ARGS(x) if (slirp_debug & DBG_CALL) { fprintf x ; fflush(dfd); }
-#define DEBUG_MISC(x) if (slirp_debug & DBG_MISC) { fprintf x ; fflush(dfd); }
-#define DEBUG_ERROR(x) if (slirp_debug & DBG_ERROR) {fprintf x ; fflush(dfd); }
+#define DEBUG_CALL(fmt, ...) do { \
+ if (slirp_debug & DBG_CALL) { \
+ fprintf(dfd, fmt, ##__VA_ARGS__); \
+ fprintf(dfd, "...\n"); \
+ fflush(dfd); \
+ } \
+} while (0)
+
+#define DEBUG_ARG(fmt, ...) do { \
+ if (slirp_debug & DBG_CALL) { \
+ fputc(' ', dfd); \
+ fprintf(dfd, fmt, ##__VA_ARGS__); \
+ fputc('\n', dfd); \
+ fflush(dfd); \
+ } \
+} while (0)
+
+#define DEBUG_ARGS(fmt, ...) DEBUG_ARG(fmt, ##__VA_ARGS__)
+
+#define DEBUG_MISC(fmt, ...) do { \
+ if (slirp_debug & DBG_MISC) { \
+ fprintf(dfd, fmt, ##__VA_ARGS__); \
+ fflush(dfd); \
+ } \
+} while (0)
+
+#define DEBUG_ERROR(fmt, ...) do { \
+ if (slirp_debug & DBG_ERROR) { \
+ fprintf(dfd, fmt, ##__VA_ARGS__); \
+ fflush(dfd); \
+ } \
+} while (0)
#else
-#define DEBUG_CALL(x)
-#define DEBUG_ARG(x, y)
-#define DEBUG_ARGS(x)
-#define DEBUG_MISC(x)
-#define DEBUG_ERROR(x)
+#define DEBUG_CALL(fmt, ...)
+#define DEBUG_ARG(fmt, ...)
+#define DEBUG_ARGS(fmt, ...)
+#define DEBUG_MISC(fmt, ...)
+#define DEBUG_ERROR(fmt, ...)
#endif
ri->want_boot_url = true;
break;
default:
- DEBUG_MISC((dfd, "dhcpv6: Unsupported option request %d\n",
- req_opt));
+ DEBUG_MISC("dhcpv6: Unsupported option request %d\n",
+ req_opt);
}
}
break;
default:
- DEBUG_MISC((dfd, "dhcpv6 info req: Unsupported option %d, len=%d\n",
- option, len));
+ DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d\n",
+ option, len);
}
odata += len + 4;
dhcpv6_info_request(m->slirp, srcsas, xid, &data[4], data_len - 4);
break;
default:
- DEBUG_MISC((dfd, "dhcpv6_input: Unsupported message type 0x%x\n",
- data[0]));
+ DEBUG_MISC("dhcpv6_input: Unsupported message type 0x%x\n", data[0]);
}
}
struct ip6 *ip = mtod(m, struct ip6 *);
DEBUG_CALL("icmp6_send_error");
- DEBUG_ARGS((dfd, " type = %d, code = %d\n", type, code));
+ DEBUG_ARGS(" type = %d, code = %d\n", type, code);
if (IN6_IS_ADDR_MULTICAST(&ip->ip_src) ||
in6_zero(&ip->ip_src)) {
if (sendto(so->s, m->m_data + hlen, m->m_len - hlen, 0,
(struct sockaddr *)&addr, sizeof(addr)) == -1) {
- DEBUG_MISC((dfd, "icmp_input icmp sendto tx errno = %d-%s\n",
- errno, strerror(errno)));
+ DEBUG_MISC("icmp_input icmp sendto tx errno = %d-%s\n",
+ errno, strerror(errno));
icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
icmp_detach(so);
}
return;
}
if (udp_attach(so, AF_INET) == -1) {
- DEBUG_MISC((dfd,"icmp_input udp_attach errno = %d-%s\n",
- errno,strerror(errno)));
+ DEBUG_MISC("icmp_input udp_attach errno = %d-%s\n",
+ errno,strerror(errno));
sofree(so);
m_free(m);
goto end_error;
if(sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0,
(struct sockaddr *)&addr, sockaddr_size(&addr)) == -1) {
- DEBUG_MISC((dfd,"icmp_input udp sendto tx errno = %d-%s\n",
- errno,strerror(errno)));
+ DEBUG_MISC("icmp_input udp sendto tx errno = %d-%s\n",
+ errno,strerror(errno));
icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
udp_detach(so);
}
{ char bufa[20], bufb[20];
strcpy(bufa, inet_ntoa(ip->ip_src));
strcpy(bufb, inet_ntoa(ip->ip_dst));
- DEBUG_MISC((dfd, " %.16s to %.16s\n", bufa, bufb));
+ DEBUG_MISC(" %.16s to %.16s\n", bufa, bufb);
}
#endif
if(ip->ip_off & IP_OFFMASK) goto end_error; /* Only reply to fragment 0 */
} else {
error_code = ICMP_UNREACH_HOST;
}
- DEBUG_MISC((dfd, " udp icmp rx errno = %d-%s\n", errno,
- strerror(errno)));
+ DEBUG_MISC(" udp icmp rx errno = %d-%s\n", errno,
+ strerror(errno));
icmp_send_error(so->so_m, ICMP_UNREACH, error_code, 0, strerror(errno));
} else {
icmp_reflect(so->so_m);
}
}
- DEBUG_ERROR((dfd, "dtom failed"));
+ DEBUG_ERROR("dtom failed");
return (struct mbuf *)0;
}
inet_ntop(AF_INET6, &(ip_addr), addrstr, INET6_ADDRSTRLEN);
DEBUG_ARG("ip = %s", addrstr);
#endif
- DEBUG_ARGS((dfd, " hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
- ethaddr[0], ethaddr[1], ethaddr[2],
- ethaddr[3], ethaddr[4], ethaddr[5]));
+ DEBUG_ARGS(" hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+ ethaddr[0], ethaddr[1], ethaddr[2],
+ ethaddr[3], ethaddr[4], ethaddr[5]);
if (IN6_IS_ADDR_MULTICAST(&ip_addr) || in6_zero(&ip_addr)) {
/* Do not register multicast or unspecified addresses */
out_ethaddr[3] = ip_addr.s6_addr[13];
out_ethaddr[4] = ip_addr.s6_addr[14];
out_ethaddr[5] = ip_addr.s6_addr[15];
- DEBUG_ARGS((dfd, " multicast addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
- out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
- out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]));
+ DEBUG_ARGS(" multicast addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+ out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
+ out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]);
return 1;
}
for (i = 0; i < NDP_TABLE_SIZE; i++) {
if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) {
memcpy(out_ethaddr, ndp_table->table[i].eth_addr, ETH_ALEN);
- DEBUG_ARGS((dfd, " found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
- out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
- out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]));
+ DEBUG_ARGS(" found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+ out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
+ out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]);
return 1;
}
}
}
memcpy(eh->h_dest, ethaddr, ETH_ALEN);
- DEBUG_ARGS((dfd, " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
- eh->h_source[0], eh->h_source[1], eh->h_source[2],
- eh->h_source[3], eh->h_source[4], eh->h_source[5]));
- DEBUG_ARGS((dfd, " dst = %02x:%02x:%02x:%02x:%02x:%02x\n",
- eh->h_dest[0], eh->h_dest[1], eh->h_dest[2],
- eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]));
+ DEBUG_ARGS(" src = %02x:%02x:%02x:%02x:%02x:%02x\n",
+ eh->h_source[0], eh->h_source[1], eh->h_source[2],
+ eh->h_source[3], eh->h_source[4], eh->h_source[5]);
+ DEBUG_ARGS(" dst = %02x:%02x:%02x:%02x:%02x:%02x\n",
+ eh->h_dest[0], eh->h_dest[1], eh->h_dest[2],
+ eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]);
memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len);
slirp->cb->output(slirp->opaque, buf, ifm->m_len + ETH_HLEN);
return 1;
}
}
- DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno)));
+ DEBUG_MISC(" --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno));
sofcantrcvmore(so);
if (err == ECONNRESET || err == ECONNREFUSED
nn += ret;
}
- DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
+ DEBUG_MISC(" ... read nn = %d bytes\n", nn);
/* Update fields */
sb->sb_cc += nn;
n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */
#ifdef DEBUG
if (n != len) {
- DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n"));
+ DEBUG_ERROR("Didn't send all data urgently XXXXX\n");
}
#endif
}
return n;
}
so->so_urgc -= n;
- DEBUG_MISC((dfd, " ---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", n, so->so_urgc);
sb->sb_cc -= n;
sb->sb_rptr += n;
if (ret > 0)
nn += ret;
}
- DEBUG_MISC((dfd, " ... wrote nn = %d bytes\n", nn));
+ DEBUG_MISC(" ... wrote nn = %d bytes\n", nn);
/* Update sbuf */
sb->sb_cc -= nn;
return nn;
err_disconnected:
- DEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state = %x, errno = %d\n",
- so->so_state, errno));
+ DEBUG_MISC(" --- sowrite disconnected, so->so_state = %x, errno = %d\n",
+ so->so_state, errno);
sofcantsendmore(so);
tcp_sockclosed(sototcpcb(so));
return -1;
if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET;
- DEBUG_MISC((dfd," udp icmp rx errno = %d-%s\n",
- errno,strerror(errno)));
+ DEBUG_MISC(" udp icmp rx errno = %d-%s\n",
+ errno,strerror(errno));
icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno));
} else {
icmp_reflect(so->so_m);
m->m_len = recvfrom(so->s, m->m_data, len, 0,
(struct sockaddr *)&addr, &addrlen);
- DEBUG_MISC((dfd, " did recvfrom %d, errno = %d-%s\n",
- m->m_len, errno,strerror(errno)));
+ DEBUG_MISC(" did recvfrom %d, errno = %d-%s\n",
+ m->m_len, errno,strerror(errno));
if(m->m_len<0) {
/* Report error as ICMP */
switch (so->so_lfamily) {
code = ICMP_UNREACH_NET;
}
- DEBUG_MISC((dfd, " rx error, tx icmp ICMP_UNREACH:%i\n", code));
+ DEBUG_MISC(" rx error, tx icmp ICMP_UNREACH:%i\n", code);
icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno));
break;
case AF_INET6:
code = ICMP6_UNREACH_NO_ROUTE;
}
- DEBUG_MISC((dfd, " rx error, tx icmp6 ICMP_UNREACH:%i\n", code));
+ DEBUG_MISC(" rx error, tx icmp6 ICMP_UNREACH:%i\n", code);
icmp6_send_error(so->so_m, ICMP6_UNREACH, code);
break;
default:
}
}
- DEBUG_MISC((dfd, " addr.sin_port=%d, "
- "addr.sin_addr.s_addr=%.16s\n",
- ntohs(sin->sin_port), inet_ntoa(sin->sin_addr)));
+ DEBUG_MISC(" addr.sin_port=%d, "
+ "addr.sin_addr.s_addr=%.16s\n",
+ ntohs(sin->sin_port), inet_ntoa(sin->sin_addr));
break;
case AF_INET6:
Slirp *slirp;
DEBUG_CALL("tcp_input");
- DEBUG_ARGS((dfd, " m = %p iphlen = %2d inso = %p\n",
- m, iphlen, inso));
+ DEBUG_ARGS(" m = %p iphlen = %2d inso = %p\n",
+ m, iphlen, inso);
/*
* If called with m == 0, then we're continuing the connect
(errno != EINPROGRESS) && (errno != EWOULDBLOCK)
) {
uint8_t code;
- DEBUG_MISC((dfd, " tcp fconnect errno = %d-%s\n",
- errno,strerror(errno)));
+ DEBUG_MISC(" tcp fconnect errno = %d-%s\n",
+ 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,
if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) {
if (ti->ti_len == 0 && tiwin == tp->snd_wnd) {
- DEBUG_MISC((dfd, " dup ack m = %p so = %p\n",
- m, so));
+ DEBUG_MISC(" dup ack m = %p so = %p\n", m, so);
/*
* If we have outstanding data (other than
* a window probe), this is a completely
int opt, optlen;
DEBUG_CALL("tcp_dooptions");
- DEBUG_ARGS((dfd, " tp = %p cnt=%i\n", tp, cnt));
+ DEBUG_ARGS(" tp = %p cnt=%i\n", tp, cnt);
for (; cnt > 0; cnt -= optlen, cp += optlen) {
opt = cp[0];
(mss - (TCP_RCVSPACE % mss)) :
0));
- DEBUG_MISC((dfd, " returning mss = %d\n", mss));
+ DEBUG_MISC(" returning mss = %d\n", mss);
return mss;
}
flags = tcp_outflags[tp->t_state];
- DEBUG_MISC((dfd, " --- tcp_output flags = 0x%x\n",flags));
+ DEBUG_MISC(" --- tcp_output flags = 0x%x\n", flags);
/*
* If in persist timeout with window of 0, send 1 byte.
qemu_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
addr = so->fhost.ss;
- DEBUG_CALL(" connect()ing")
+ DEBUG_CALL(" connect()ing");
sotranslate_out(so, &addr);
/* We don't care what port we get */
so->chardev = ex_ptr->ex_chardev;
return 1;
}
- DEBUG_MISC((dfd, " executing %s\n", ex_ptr->ex_exec));
+ DEBUG_MISC(" executing %s\n", ex_ptr->ex_exec);
return fork_exec(so, ex_ptr->ex_exec);
}
}
*/
so = socreate(slirp);
if (udp_attach(so, AF_INET) == -1) {
- DEBUG_MISC((dfd," udp_attach errno = %d-%s\n",
- errno,strerror(errno)));
+ DEBUG_MISC(" udp_attach errno = %d-%s\n",
+ errno, strerror(errno));
sofree(so);
goto bad;
}
m->m_len += iphlen;
m->m_data -= iphlen;
*ip=save_ip;
- DEBUG_MISC((dfd,"udp tx errno = %d-%s\n",errno,strerror(errno)));
+ DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno));
icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0,
strerror(errno));
goto bad;
/* If there's no socket for this packet, create one. */
so = socreate(slirp);
if (udp_attach(so, AF_INET6) == -1) {
- DEBUG_MISC((dfd, " udp6_attach errno = %d-%s\n",
- errno, strerror(errno)));
+ DEBUG_MISC(" udp6_attach errno = %d-%s\n",
+ errno, strerror(errno));
sofree(so);
goto bad;
}
m->m_len += iphlen;
m->m_data -= iphlen;
*ip = save_ip;
- DEBUG_MISC((dfd, "udp tx errno = %d-%s\n", errno, strerror(errno)));
+ DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno));
icmp6_send_error(m, ICMP6_UNREACH, ICMP6_UNREACH_NO_ROUTE);
goto bad;
}