aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorGravatar Denis Vlasenko <vda.linux@googlemail.com>2007-01-22 14:04:27 +0000
committerGravatar Denis Vlasenko <vda.linux@googlemail.com>2007-01-22 14:04:27 +0000
commit35d4da0fb5884236fa7a131a13416268239c9e69 (patch)
tree1598327194a13be915980de0cb8be6a84e5c362c /networking
parent85629f08bcea5d4a44b6d511422fd608bbc3fc45 (diff)
downloadbusybox-35d4da0fb5884236fa7a131a13416268239c9e69.tar.gz
busybox-35d4da0fb5884236fa7a131a13416268239c9e69.tar.bz2
exterminate u_intXXX.
fix ping6 buglet (memset is too short), minor sync between ping and ping6
Diffstat (limited to 'networking')
-rw-r--r--networking/inetd.c8
-rw-r--r--networking/ping.c47
-rw-r--r--networking/ping6.c45
-rw-r--r--networking/traceroute.c28
-rw-r--r--networking/udhcp/dhcprelay.c8
5 files changed, 71 insertions, 65 deletions
diff --git a/networking/inetd.c b/networking/inetd.c
index 218f85e53..c1f9918f0 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -1707,7 +1707,7 @@ chargen_dg(int s, servtab_t *sep ATTRIBUTE_UNUSED)
* some seventy years Bell Labs was asleep.
*/
-static u_int machtime(void)
+static unsigned machtime(void)
{
struct timeval tv;
@@ -1715,14 +1715,14 @@ static u_int machtime(void)
fprintf(stderr, "Unable to get time of day\n");
return 0L;
}
- return htonl((u_int) tv.tv_sec + 2208988800UL);
+ return htonl((unsigned) tv.tv_sec + 2208988800UL);
}
/* ARGSUSED */
static void
machtime_stream(int s, servtab_t *sep ATTRIBUTE_UNUSED)
{
- u_int result;
+ unsigned result;
result = machtime();
(void) write(s, (char *) &result, sizeof(result));
@@ -1732,7 +1732,7 @@ machtime_stream(int s, servtab_t *sep ATTRIBUTE_UNUSED)
static void
machtime_dg(int s, servtab_t *sep ATTRIBUTE_UNUSED)
{
- u_int result;
+ unsigned result;
/* struct sockaddr_storage ss; */
struct sockaddr sa;
struct sockaddr_in *dg_sin;
diff --git a/networking/ping.c b/networking/ping.c
index 12730bec5..d8a70334d 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -1,13 +1,15 @@
/* vi: set sw=4 ts=4: */
/*
- * $Id: ping.c,v 1.56 2004/03/15 08:28:48 andersen Exp $
* Mini ping implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
*
* Adapted from the ping in netkit-base 0.10:
* Copyright (c) 1989 The Regents of the University of California.
- * Derived from software contributed to Berkeley by Mike Muuss.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Mike Muuss.
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
@@ -74,7 +76,7 @@ static void ping(const char *host)
pingsock = create_icmp_socket();
- memset(&pingaddr, 0, sizeof(struct sockaddr_in));
+ memset(&pingaddr, 0, sizeof(pingaddr));
pingaddr.sin_family = AF_INET;
h = xgethostbyname(host);
@@ -202,7 +204,7 @@ static void sendping(int junk)
pkt->icmp_cksum = 0;
pkt->icmp_seq = htons(ntransmitted); /* don't ++ here, it can be a macro */
pkt->icmp_id = myid;
- CLR(ntohs(pkt->icmp_seq) % MAX_DUP_CHK);
+ CLR((uint16_t)ntransmitted % MAX_DUP_CHK);
ntransmitted++;
gettimeofday((struct timeval *) &pkt->icmp_dun, NULL);
@@ -230,20 +232,20 @@ static void sendping(int junk)
static char *icmp_type_name(int id)
{
switch (id) {
- case ICMP_ECHOREPLY: return "Echo Reply";
- case ICMP_DEST_UNREACH: return "Destination Unreachable";
- case ICMP_SOURCE_QUENCH: return "Source Quench";
- case ICMP_REDIRECT: return "Redirect (change route)";
- case ICMP_ECHO: return "Echo Request";
- case ICMP_TIME_EXCEEDED: return "Time Exceeded";
- case ICMP_PARAMETERPROB: return "Parameter Problem";
- case ICMP_TIMESTAMP: return "Timestamp Request";
- case ICMP_TIMESTAMPREPLY: return "Timestamp Reply";
- case ICMP_INFO_REQUEST: return "Information Request";
- case ICMP_INFO_REPLY: return "Information Reply";
- case ICMP_ADDRESS: return "Address Mask Request";
- case ICMP_ADDRESSREPLY: return "Address Mask Reply";
- default: return "unknown ICMP type";
+ case ICMP_ECHOREPLY: return "Echo Reply";
+ case ICMP_DEST_UNREACH: return "Destination Unreachable";
+ case ICMP_SOURCE_QUENCH: return "Source Quench";
+ case ICMP_REDIRECT: return "Redirect (change route)";
+ case ICMP_ECHO: return "Echo Request";
+ case ICMP_TIME_EXCEEDED: return "Time Exceeded";
+ case ICMP_PARAMETERPROB: return "Parameter Problem";
+ case ICMP_TIMESTAMP: return "Timestamp Request";
+ case ICMP_TIMESTAMPREPLY: return "Timestamp Reply";
+ case ICMP_INFO_REQUEST: return "Information Request";
+ case ICMP_INFO_REPLY: return "Information Reply";
+ case ICMP_ADDRESS: return "Address Mask Request";
+ case ICMP_ADDRESSREPLY: return "Address Mask Reply";
+ default: return "unknown ICMP type";
}
}
@@ -270,7 +272,7 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from)
return; /* not our ping */
if (icmppkt->icmp_type == ICMP_ECHOREPLY) {
- u_int16_t recv_seq = ntohs(icmppkt->icmp_seq);
+ uint16_t recv_seq = ntohs(icmppkt->icmp_seq);
++nreceived;
tp = (struct timeval *) icmppkt->icmp_data;
@@ -307,11 +309,12 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from)
if (dupflag)
printf(" (DUP!)");
puts("");
- } else
+ } else {
if (icmppkt->icmp_type != ICMP_ECHO)
bb_error_msg("warning: got ICMP %d (%s)",
icmppkt->icmp_type,
icmp_type_name(icmppkt->icmp_type));
+ }
fflush(stdout);
}
@@ -326,7 +329,7 @@ static void ping(const char *host)
xbind(pingsock, (struct sockaddr*)&sourceaddr, sizeof(sourceaddr));
}
- memset(&pingaddr, 0, sizeof(struct sockaddr_in));
+ memset(&pingaddr, 0, sizeof(pingaddr));
pingaddr.sin_family = AF_INET;
hostent = xgethostbyname(host);
@@ -339,7 +342,7 @@ static void ping(const char *host)
setsockopt_broadcast(pingsock);
/* set recv buf for broadcast pings */
- sockopt = 48 * 1024;
+ sockopt = 48 * 1024; /* explain why 48k? */
setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, (char *) &sockopt,
sizeof(sockopt));
diff --git a/networking/ping6.c b/networking/ping6.c
index 5cb02f51a..dec3b426a 100644
--- a/networking/ping6.c
+++ b/networking/ping6.c
@@ -1,6 +1,5 @@
/* vi: set sw=4 ts=4: */
/*
- * $Id: ping6.c,v 1.6 2004/03/15 08:28:48 andersen Exp $
* Mini ping implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -67,7 +66,7 @@ static void ping(const char *host)
pingsock = create_icmp6_socket();
- memset(&pingaddr, 0, sizeof(struct sockaddr_in));
+ memset(&pingaddr, 0, sizeof(pingaddr));
pingaddr.sin6_family = AF_INET6;
h = xgethostbyname2(host, AF_INET6);
@@ -196,7 +195,7 @@ static void sendping(int junk)
pkt->icmp6_cksum = 0;
pkt->icmp6_seq = htons(ntransmitted); /* don't ++ here, it can be a macro */
pkt->icmp6_id = myid;
- CLR(pkt->icmp6_seq % MAX_DUP_CHK);
+ CLR((uint16_t)ntransmitted % MAX_DUP_CHK);
ntransmitted++;
gettimeofday((struct timeval *) &pkt->icmp6_data8[4], NULL);
@@ -220,7 +219,7 @@ static void sendping(int junk)
}
}
-/* RFC3542 changed some definitions from RFC2292 for no good reason, whee !
+/* RFC3542 changed some definitions from RFC2292 for no good reason, whee!
* the newer 3542 uses a MLD_ prefix where as 2292 uses ICMP6_ prefix */
#ifndef MLD_LISTENER_QUERY
# define MLD_LISTENER_QUERY ICMP6_MEMBERSHIP_QUERY
@@ -234,16 +233,16 @@ static void sendping(int junk)
static char *icmp6_type_name(int id)
{
switch (id) {
- case ICMP6_DST_UNREACH: return "Destination Unreachable";
- case ICMP6_PACKET_TOO_BIG: return "Packet too big";
- case ICMP6_TIME_EXCEEDED: return "Time Exceeded";
- case ICMP6_PARAM_PROB: return "Parameter Problem";
- case ICMP6_ECHO_REPLY: return "Echo Reply";
- case ICMP6_ECHO_REQUEST: return "Echo Request";
- case MLD_LISTENER_QUERY: return "Listener Query";
- case MLD_LISTENER_REPORT: return "Listener Report";
- case MLD_LISTENER_REDUCTION: return "Listener Reduction";
- default: return "unknown ICMP type";
+ case ICMP6_DST_UNREACH: return "Destination Unreachable";
+ case ICMP6_PACKET_TOO_BIG: return "Packet too big";
+ case ICMP6_TIME_EXCEEDED: return "Time Exceeded";
+ case ICMP6_PARAM_PROB: return "Parameter Problem";
+ case ICMP6_ECHO_REPLY: return "Echo Reply";
+ case ICMP6_ECHO_REQUEST: return "Echo Request";
+ case MLD_LISTENER_QUERY: return "Listener Query";
+ case MLD_LISTENER_REPORT: return "Listener Report";
+ case MLD_LISTENER_REDUCTION: return "Listener Reduction";
+ default: return "unknown ICMP type";
}
}
@@ -266,6 +265,7 @@ static void unpack(char *packet, int sz, struct sockaddr_in6 *from, int hoplimit
return; /* not our ping */
if (icmppkt->icmp6_type == ICMP6_ECHO_REPLY) {
+ uint16_t recv_seq = ntohs(icmppkt->icmp6_seq);
++nreceived;
tp = (struct timeval *) &icmppkt->icmp6_data8[4];
@@ -282,12 +282,12 @@ static void unpack(char *packet, int sz, struct sockaddr_in6 *from, int hoplimit
if (triptime > tmax)
tmax = triptime;
- if (TST(icmppkt->icmp6_seq % MAX_DUP_CHK)) {
+ if (TST(recv_seq % MAX_DUP_CHK)) {
++nrepeats;
--nreceived;
dupflag = 1;
} else {
- SET(icmppkt->icmp6_seq % MAX_DUP_CHK);
+ SET(recv_seq % MAX_DUP_CHK);
dupflag = 0;
}
@@ -297,16 +297,19 @@ static void unpack(char *packet, int sz, struct sockaddr_in6 *from, int hoplimit
printf("%d bytes from %s: icmp6_seq=%u", sz,
inet_ntop(AF_INET6, &pingaddr.sin6_addr,
buf, sizeof(buf)),
- ntohs(icmppkt->icmp6_seq));
+ recv_seq);
printf(" ttl=%d time=%lu.%lu ms", hoplimit,
triptime / 10, triptime % 10);
if (dupflag)
printf(" (DUP!)");
puts("");
- } else
+ } else {
if (icmppkt->icmp6_type != ICMP6_ECHO_REQUEST)
bb_error_msg("warning: got ICMP %d (%s)",
- icmppkt->icmp6_type, icmp6_type_name(icmppkt->icmp6_type));
+ icmppkt->icmp6_type,
+ icmp6_type_name(icmppkt->icmp6_type));
+ }
+ fflush(stdout);
}
static void ping(const char *host)
@@ -321,7 +324,7 @@ static void ping(const char *host)
pingsock = create_icmp6_socket();
- memset(&pingaddr, 0, sizeof(struct sockaddr_in));
+ memset(&pingaddr, 0, sizeof(pingaddr));
pingaddr.sin6_family = AF_INET6;
hostent = xgethostbyname2(host, AF_INET6);
@@ -431,7 +434,7 @@ int ping6_main(int argc, char **argv)
"%s: invalid interface name", opt_I);
}
- myid = (int16_t)getpid();
+ myid = (int16_t) getpid();
ping(argv[optind]);
return EXIT_SUCCESS;
}
diff --git a/networking/traceroute.c b/networking/traceroute.c
index 0f3da90d6..5eac6cd1e 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -268,7 +268,7 @@ struct udpiphdr {
struct hostinfo {
char *name;
int n;
- u_int32_t *addrs;
+ uint32_t *addrs;
};
/* Data section of the probe packet */
@@ -279,7 +279,7 @@ struct outdata {
};
struct IFADDRLIST {
- u_int32_t addr;
+ uint32_t addr;
char device[sizeof(struct ifreq)];
};
@@ -299,9 +299,9 @@ static struct icmp *outicmp; /* last output (icmp) packet */
#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
/* Maximum number of gateways (include room for one noop) */
-#define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(u_int32_t)))
+#define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(uint32_t)))
/* loose source route gateway list (including room for final destination) */
-static u_int32_t gwlist[NGATEWAYS + 1];
+static uint32_t gwlist[NGATEWAYS + 1];
#endif
static int s; /* receive (icmp) socket file descriptor */
@@ -429,7 +429,7 @@ ifaddrlist(struct IFADDRLIST **ipaddrp)
static void
-setsin(struct sockaddr_in *addr_sin, u_int32_t addr)
+setsin(struct sockaddr_in *addr_sin, uint32_t addr)
{
memset(addr_sin, 0, sizeof(*addr_sin));
#ifdef HAVE_SOCKADDR_SA_LEN
@@ -448,8 +448,8 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from)
{
int i, n;
FILE *f;
- u_int32_t mask;
- u_int32_t dest, tmask;
+ uint32_t mask;
+ uint32_t dest, tmask;
struct IFADDRLIST *al;
char buf[256], tdevice[256], device[256];
@@ -641,7 +641,7 @@ send_probe(int seq, int ttl, struct timeval *tp)
int nshorts, i;
sp = (uint16_t *)outip;
- nshorts = (u_int)packlen / sizeof(uint16_t);
+ nshorts = (unsigned)packlen / sizeof(uint16_t);
i = 0;
printf("[ %d bytes", packlen);
while (--nshorts >= 0) {
@@ -776,7 +776,7 @@ packet_ok(unsigned char *buf, int cc, struct sockaddr_in *from, int seq)
#if ENABLE_FEATURE_TRACEROUTE_VERBOSE
if (verbose) {
int i;
- u_int32_t *lp = (u_int32_t *)&icp->icmp_ip;
+ uint32_t *lp = (uint32_t *)&icp->icmp_ip;
printf("\n%d bytes from %s to "
"%s: icmp type %d (%s) code %d\n",
@@ -838,7 +838,7 @@ gethostinfo(const char *host)
struct hostent *hp;
struct hostinfo *hi;
char **p;
- u_int32_t addr, *ap;
+ uint32_t addr, *ap;
hi = xzalloc(sizeof(*hi));
addr = inet_addr(host);
@@ -874,7 +874,7 @@ freehostinfo(struct hostinfo *hi)
#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
static void
-getaddr(u_int32_t *ap, const char *host)
+getaddr(uint32_t *ap, const char *host)
{
struct hostinfo *hi;
@@ -892,7 +892,7 @@ traceroute_main(int argc, char *argv[])
int code, n;
unsigned char *outp;
- u_int32_t *ap;
+ uint32_t *ap;
struct sockaddr_in *from = (struct sockaddr_in *)&wherefrom;
struct sockaddr_in *to = (struct sockaddr_in *)&whereto;
struct hostinfo *hi;
@@ -915,7 +915,7 @@ traceroute_main(int argc, char *argv[])
int nprobes = 3;
char *nprobes_str = NULL;
char *waittime_str = NULL;
- u_int pausemsecs = 0;
+ unsigned pausemsecs = 0;
char *pausemsecs_str = NULL;
int first_ttl = 1;
char *first_ttl_str = NULL;
@@ -1211,7 +1211,7 @@ traceroute_main(int argc, char *argv[])
(void)fflush(stderr);
for (ttl = first_ttl; ttl <= max_ttl; ++ttl) {
- u_int32_t lastaddr = 0;
+ uint32_t lastaddr = 0;
int gotlastaddr = 0;
int got_there = 0;
int unreachable = 0;
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c
index 78a1b5e62..418aa7cbb 100644
--- a/networking/udhcp/dhcprelay.c
+++ b/networking/udhcp/dhcprelay.c
@@ -22,7 +22,7 @@
/* This list holds information about clients. The xid_* functions manipulate this list. */
static struct xid_item {
- u_int32_t xid;
+ uint32_t xid;
struct sockaddr_in ip;
int client;
time_t timestamp;
@@ -30,7 +30,7 @@ static struct xid_item {
} dhcprelay_xid_list = {0, {0}, 0, 0, NULL};
-static struct xid_item * xid_add(u_int32_t xid, struct sockaddr_in *ip, int client)
+static struct xid_item * xid_add(uint32_t xid, struct sockaddr_in *ip, int client)
{
struct xid_item *item;
@@ -67,7 +67,7 @@ static void xid_expire(void)
}
}
-static struct xid_item * xid_find(u_int32_t xid)
+static struct xid_item * xid_find(uint32_t xid)
{
struct xid_item *item = dhcprelay_xid_list.next;
while (item != NULL) {
@@ -79,7 +79,7 @@ static struct xid_item * xid_find(u_int32_t xid)
return NULL;
}
-static void xid_del(u_int32_t xid)
+static void xid_del(uint32_t xid)
{
struct xid_item *item = dhcprelay_xid_list.next;
struct xid_item *last = &dhcprelay_xid_list;