aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormaximilian attems <max@stro.at>2010-03-23 02:56:05 +0100
committermaximilian attems <max@stro.at>2010-03-23 03:00:02 +0100
commite8070f0bc724fb307b45c5c23e53f5fce5cc4083 (patch)
treefd1dec8e2c6d81fa7e4c3d523759643c270cb911
parent7a6d1c10d85cf5606c577b80c257907c920e6674 (diff)
downloadklibc-e8070f0bc724fb307b45c5c23e53f5fce5cc4083.tar.gz
[klibc] ipconfig: use dprintf on DEBUG
compile the relevant printfs if DEBUG is defined at compile time or nothing if not. dprintf uses simply printf as definition, no need to badly invent a new marcro. nuke comment related to old gcc. the line ending story of those printf needs to be fixed another time. Put some dprintf back in, that went missing in latest fixes. Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r--usr/kinit/ipconfig/bootp_proto.c4
-rw-r--r--usr/kinit/ipconfig/dhcp_proto.c22
-rw-r--r--usr/kinit/ipconfig/ipconfig.h15
-rw-r--r--usr/kinit/ipconfig/main.c15
-rw-r--r--usr/kinit/ipconfig/packet.c27
5 files changed, 38 insertions, 45 deletions
diff --git a/usr/kinit/ipconfig/bootp_proto.c b/usr/kinit/ipconfig/bootp_proto.c
index 7df313717534f..42dfad3cda620 100644
--- a/usr/kinit/ipconfig/bootp_proto.c
+++ b/usr/kinit/ipconfig/bootp_proto.c
@@ -49,8 +49,8 @@ int bootp_send_request(struct netdev *dev)
bootp.secs = htons(time(NULL) - dev->open_time);
memcpy(bootp.chaddr, dev->hwaddr, 16);
- DEBUG(("-> bootp xid 0x%08x secs 0x%08x ",
- bootp.xid, ntohs(bootp.secs)));
+ dprintf("-> bootp xid 0x%08x secs 0x%08x ",
+ bootp.xid, ntohs(bootp.secs));
return packet_send(dev, iov, 2);
}
diff --git a/usr/kinit/ipconfig/dhcp_proto.c b/usr/kinit/ipconfig/dhcp_proto.c
index 9b78d7820ead8..2a2651a1abd90 100644
--- a/usr/kinit/ipconfig/dhcp_proto.c
+++ b/usr/kinit/ipconfig/dhcp_proto.c
@@ -111,17 +111,17 @@ static int dhcp_parse(struct netdev *dev, struct bootp_hdr *hdr,
ret = bootp_parse(dev, hdr, exts, extlen) ? DHCPOFFER : 0;
if (ret == DHCPOFFER && serverid != INADDR_NONE)
dev->serverid = serverid;
- DEBUG(("\n dhcp offer\n"));
+ dprintf("\n dhcp offer\n");
break;
case DHCPACK:
ret = bootp_parse(dev, hdr, exts, extlen) ? DHCPACK : 0;
- DEBUG(("\n dhcp ack\n"));
+ dprintf("\n dhcp ack\n");
break;
case DHCPNAK:
ret = DHCPNAK;
- DEBUG(("\n dhcp nak\n"));
+ dprintf("\n dhcp nak\n");
break;
}
return ret;
@@ -151,7 +151,7 @@ static int dhcp_recv(struct netdev *dev)
if (ret == 0)
return -1;
- DEBUG(("\n dhcp xid %08x ", dev->bootp.xid));
+ dprintf("\n dhcp xid %08x ", dev->bootp.xid);
if (ret < sizeof(struct bootp_hdr) || bootp.op != BOOTP_REPLY ||
/* RFC951 7.5 */ bootp.xid != dev->bootp.xid ||
@@ -184,16 +184,16 @@ static int dhcp_send(struct netdev *dev, struct iovec *vec)
vec[1].iov_base = &bootp;
vec[1].iov_len = sizeof(struct bootp_hdr);
- DEBUG(("xid %08x secs %d ", bootp.xid, ntohs(bootp.secs)));
+ dprintf("xid %08x secs %d ", bootp.xid, ntohs(bootp.secs));
if (vendor_class_identifier_len > 2) {
vec[i].iov_base = vendor_class_identifier;
vec[i].iov_len = vendor_class_identifier_len;
i++;
- DEBUG(("vendor_class_identifier \"%.*s\" ",
- vendor_class_identifier_len-2,
- vendor_class_identifier+2));
+ dprintf("vendor_class_identifier \"%.*s\" ",
+ vendor_class_identifier_len-2,
+ vendor_class_identifier+2);
}
if (dev->reqhostname[0] != '\0') {
@@ -206,7 +206,7 @@ static int dhcp_send(struct netdev *dev, struct iovec *vec)
vec[i].iov_len = len+2;
i++;
- DEBUG(("hostname %.*s ", len, dhcp_hostname+2));
+ printf("hostname %.*s ", len, dhcp_hostname+2);
}
vec[i].iov_base = dhcp_end;
@@ -223,7 +223,7 @@ int dhcp_send_discover(struct netdev *dev)
dev->ip_addr = INADDR_ANY;
dev->ip_gateway = INADDR_ANY;
- DEBUG(("-> dhcp discover "));
+ dprintf("-> dhcp discover ");
return dhcp_send(dev, dhcp_discover_iov);
}
@@ -244,7 +244,7 @@ int dhcp_send_request(struct netdev *dev)
memcpy(&dhcp_request_hdr[SERVER_IP_OFF], &dev->serverid, 4);
memcpy(&dhcp_request_hdr[REQ_IP_OFF], &dev->ip_addr, 4);
- DEBUG(("-> dhcp request "));
+ dprintf("-> dhcp request ");
return dhcp_send(dev, dhcp_request_iov);
}
diff --git a/usr/kinit/ipconfig/ipconfig.h b/usr/kinit/ipconfig/ipconfig.h
index 6d776e0c82564..d1d7e42d0524f 100644
--- a/usr/kinit/ipconfig/ipconfig.h
+++ b/usr/kinit/ipconfig/ipconfig.h
@@ -16,19 +16,10 @@ extern int vendor_class_identifier_len;
int ipconfig_main(int argc, char *argv[]);
uint32_t ipconfig_server_address(void *next);
-/*
- * Note for gcc 3.2.2:
- *
- * If you're turning on debugging, make sure you get rid of -Os from
- * the gcc command line, or else ipconfig will fail to link.
- */
-#undef IPC_DEBUG
-
-#undef DEBUG
-#ifdef IPC_DEBUG
-#define DEBUG(x) printf x
+#ifdef DEBUG
+# define dprintf printf
#else
-#define DEBUG(x) do { } while(0)
+# define dprintf(...) ((void)0)
#endif
#endif /* IPCONFIG_IPCONFIG_H */
diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c
index c2795d2cc2feb..d46aa5ed6447e 100644
--- a/usr/kinit/ipconfig/main.c
+++ b/usr/kinit/ipconfig/main.c
@@ -187,7 +187,7 @@ static int process_receive_event(struct state *s, time_t now)
break;
case 1:
s->state = DEVST_COMPLETE;
- DEBUG(("\n bootp reply\n"));
+ dprintf("\n bootp reply\n");
break;
}
break;
@@ -221,6 +221,7 @@ static int process_receive_event(struct state *s, time_t now)
break;
default:
+ dprintf("\n");
handled = 0;
break;
}
@@ -350,7 +351,7 @@ static int loop(void)
int x;
for (s = slist; s; s = s->next) {
- DEBUG(("%s: state = %d\n", s->dev->name, s->state));
+ dprintf("%s: state = %d\n", s->dev->name, s->state);
if (s->state == DEVST_COMPLETE) {
done++;
@@ -360,7 +361,7 @@ static int loop(void)
pending++;
if (s->expire - now.tv_sec <= 0) {
- DEBUG(("timeout\n"));
+ dprintf("timeout\n");
process_timeout_event(s, now.tv_sec);
}
@@ -398,7 +399,7 @@ static int loop(void)
delta_ms = (now.tv_sec - prev.tv_sec) * 1000;
delta_ms += (now.tv_usec - prev.tv_usec) / 1000;
- DEBUG(("Delta: %d ms\n", delta_ms));
+ dprintf("Delta: %d ms\n", delta_ms);
timeout_ms -= delta_ms;
}
@@ -482,7 +483,7 @@ static int parse_device(struct netdev *dev, const char *ip)
int i, opt;
int is_ip = 0;
- DEBUG(("IP-Config: parse_device: \"%s\"\n", ip));
+ dprintf("IP-Config: parse_device: \"%s\"\n", ip);
if (strncmp(ip, "ip=", 3) == 0) {
ip += 3;
@@ -514,7 +515,7 @@ static int parse_device(struct netdev *dev, const char *ip)
if (*ip == '\0')
continue;
- DEBUG(("IP-Config: opt #%d: '%s'\n", opt, ip));
+ dprintf("IP-Config: opt #%d: '%s'\n", opt, ip);
switch (opt) {
case 0:
parse_addr(&dev->ip_addr, ip);
@@ -665,7 +666,7 @@ static int add_all_devices(struct netdev *template)
logic the in-kernel ipconfig uses... */
if (!(flags & IFF_LOOPBACK) &&
(flags & (IFF_BROADCAST | IFF_POINTOPOINT))) {
- DEBUG(("Trying to bring up %s\n", de->d_name));
+ dprintf("Trying to bring up %s\n", de->d_name);
if (!(dev = add_device(de->d_name)))
continue;
diff --git a/usr/kinit/ipconfig/packet.c b/usr/kinit/ipconfig/packet.c
index 619ac0a31c12d..508c7ba156e0f 100644
--- a/usr/kinit/ipconfig/packet.c
+++ b/usr/kinit/ipconfig/packet.c
@@ -99,13 +99,13 @@ static struct header ipudp_hdrs = {
},
};
-#ifdef IPC_DEBUG /* Only used by DEBUG(()) */
+#ifdef DEBUG /* Only used with dprintf() */
static char *ntoa(uint32_t addr)
{
struct in_addr in = { addr };
return inet_ntoa(in);
}
-#endif
+#endif /* DEBUG */
/*
* Send a packet. The options are listed in iov[1...iov_len-1].
@@ -130,11 +130,11 @@ int packet_send(struct netdev *dev, struct iovec *iov, int iov_len)
ipudp_hdrs.udp.dest = htons(cfg_remote_port);
}
- DEBUG(("\n udp src %d dst %d", ntohs(ipudp_hdrs.udp.source),
- ntohs(ipudp_hdrs.udp.dest)));
+ dprintf("\n udp src %d dst %d", ntohs(ipudp_hdrs.udp.source),
+ ntohs(ipudp_hdrs.udp.dest));
- DEBUG(("\n ip src %s ", ntoa(ipudp_hdrs.ip.saddr)));
- DEBUG(("dst %s ", ntoa(ipudp_hdrs.ip.daddr)));
+ dprintf("\n ip src %s ", ntoa(ipudp_hdrs.ip.saddr));
+ dprintf("dst %s ", ntoa(ipudp_hdrs.ip.daddr));
/*
* Glue in the ip+udp header iovec
@@ -160,7 +160,7 @@ int packet_send(struct netdev *dev, struct iovec *iov, int iov_len)
ipudp_hdrs.udp.len = htons(len - sizeof(struct iphdr));
- DEBUG(("\n bytes %d\n", len));
+ dprintf("\n bytes %d\n", len);
return sendmsg(pkt_fd, &msg, 0);
}
@@ -255,21 +255,21 @@ int packet_recv(struct iovec *iov, int iov_len)
if (ret == -1)
goto free_pkt;
- DEBUG(("<- bytes %d ", ret));
+ dprintf("<- bytes %d ", ret);
if (ip_checksum((uint16_t *) ip, ip->ihl) != 0)
goto free_pkt;
- DEBUG(("\n ip src %s ", ntoa(ip->saddr)));
- DEBUG(("dst %s ", ntoa(ip->daddr)));
+ dprintf("\n ip src %s ", ntoa(ip->saddr));
+ dprintf("dst %s ", ntoa(ip->daddr));
if (ntohs(ip->tot_len) > ret || ip->protocol != IPPROTO_UDP)
goto free_pkt;
ret -= 4 * ip->ihl;
- DEBUG(("\n udp src %d dst %d ", ntohs(udp->source),
- ntohs(udp->dest)));
+ dprintf("\n udp src %d dst %d ", ntohs(udp->source),
+ ntohs(udp->dest));
if (udp->source != htons(cfg_remote_port) ||
udp->dest != htons(cfg_local_port))
@@ -285,11 +285,12 @@ int packet_recv(struct iovec *iov, int iov_len)
return ret;
free_pkt:
+ dprintf("freed\n");
free(ip);
return 0;
discard_pkt:
- DEBUG(("discarded\n"));
+ dprintf("discarded\n");
packet_discard();
return 0;
}