summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--ping.c44
2 files changed, 19 insertions, 27 deletions
diff --git a/Makefile b/Makefile
index a0833ad..3a4198e 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ ADDLIB=
LDFLAG_STATIC=-Wl,-Bstatic
LDFLAG_DYNAMIC=-Wl,-Bdynamic
LDFLAG_CAP=-lcap
-LDFLAG_GCRYPT=-lgcrypt
+LDFLAG_GCRYPT=-lgcrypt -lgpg-error
LDFLAG_NETTLE=-lnettle
LDFLAG_CRYPTO=-lcrypto
LDFLAG_IDN=-lidn
diff --git a/ping.c b/ping.c
index 498c0e8..4455091 100644
--- a/ping.c
+++ b/ping.c
@@ -80,8 +80,6 @@ ping_func_set_st ping4_func_set = {
#define NROUTES 9 /* number of record route slots */
#define TOS_MAX 255 /* 8-bit TOS field */
-static const int max_ping4_packet = 0x10000;
-
static int ts_type;
static int nroute = 0;
static __u32 route[10];
@@ -501,6 +499,7 @@ int ping4_run(int argc, char **argv, struct addrinfo *ai, socket_st *sock)
char *target;
char hnamebuf[NI_MAXHOST];
char rspace[3 + 4 * NROUTES + 1]; /* record route space */
+ __u32 *tmp_rspace;
if (argc > 1) {
if (options & F_RROUTE)
@@ -743,8 +742,10 @@ int ping4_run(int argc, char **argv, struct addrinfo *ai, socket_st *sock)
if (ts_type == IPOPT_TS_PRESPEC) {
int i;
rspace[1] = 4+nroute*8;
- for (i=0; i<nroute; i++)
- *(__u32*)&rspace[4+i*8] = route[i];
+ for (i = 0; i < nroute; i++) {
+ tmp_rspace = (__u32*)&rspace[4+i*8];
+ *tmp_rspace = route[i];
+ }
}
if (setsockopt(sock->fd, IPPROTO_IP, IP_OPTIONS, rspace, rspace[1]) < 0) {
rspace[3] = 2;
@@ -763,8 +764,10 @@ int ping4_run(int argc, char **argv, struct addrinfo *ai, socket_st *sock)
: IPOPT_LSRR;
rspace[1+IPOPT_OLEN] = 3 + nroute*4;
rspace[1+IPOPT_OFFSET] = IPOPT_MINOFF;
- for (i=0; i<nroute; i++)
- *(__u32*)&rspace[4+i*4] = route[i];
+ for (i = 0; i < nroute; i++) {
+ tmp_rspace = (__u32*)&rspace[4+i*4];
+ *tmp_rspace = route[i];
+ }
if (setsockopt(sock->fd, IPPROTO_IP, IP_OPTIONS, rspace, 4 + nroute*4) < 0) {
perror("ping: record route");
@@ -806,12 +809,8 @@ int ping4_run(int argc, char **argv, struct addrinfo *ai, socket_st *sock)
}
if (datalen > 0xFFFF - 8 - optlen - 20) {
- if (uid || datalen > max_ping4_packet-8 || datalen > MAXPACKET-8) {
- fprintf(stderr, "Error: packet size %d is too large. Maximum is %d\n", datalen, 0xFFFF-8-20-optlen);
- exit(2);
- }
- /* Allow small oversize to root yet. It will cause EMSGSIZE. */
- fprintf(stderr, "WARNING: packet size %d is too large. Maximum is %d\n", datalen, 0xFFFF-8-20-optlen);
+ fprintf(stderr, "Error: packet size %d is too large. Maximum is %d\n", datalen, 0xFFFF-8-20-optlen);
+ exit(2);
}
if (datalen >= sizeof(struct timeval)) /* can we time transfer */
@@ -1001,7 +1000,7 @@ ping4_parse_reply(struct socket_st *sock, struct msghdr *msg, int cc, void *addr
int csfailed;
struct cmsghdr *cmsg;
int ttl;
- __u8 *opts;
+ __u8 *opts, *tmp_ttl;
int optlen;
/* Check the IP header */
@@ -1028,7 +1027,8 @@ ping4_parse_reply(struct socket_st *sock, struct msghdr *msg, int cc, void *addr
if (cmsg->cmsg_type == IP_TTL) {
if (cmsg->cmsg_len < sizeof(int))
continue;
- ttl = *(int *) CMSG_DATA(cmsg);
+ tmp_ttl = (__u8 *) CMSG_DATA(cmsg);
+ ttl = (int)*tmp_ttl;
} else if (cmsg->cmsg_type == IP_RETOPTS) {
opts = (__u8 *) CMSG_DATA(cmsg);
optlen = cmsg->cmsg_len;
@@ -1052,9 +1052,7 @@ ping4_parse_reply(struct socket_st *sock, struct msghdr *msg, int cc, void *addr
return 0;
}
} else {
- /* We fall here when a redirect or source quench arrived.
- * Also this branch processes icmp errors, when IP_RECVERR
- * is broken. */
+ /* We fall here when a redirect or source quench arrived. */
switch (icp->type) {
case ICMP_ECHO:
@@ -1082,14 +1080,8 @@ ping4_parse_reply(struct socket_st *sock, struct msghdr *msg, int cc, void *addr
acknowledge(ntohs(icp1->un.echo.sequence));
return 0;
}
- nerrors+=error_pkt;
- if (options&F_QUIET)
- return !error_pkt;
- if (options & F_FLOOD) {
- if (error_pkt)
- write_stdout("\bE", 2);
- return !error_pkt;
- }
+ if (options & (F_QUIET | F_FLOOD))
+ return 1;
print_timestamp();
printf("From %s: icmp_seq=%u ",
pr_addr(from, sizeof *from),
@@ -1097,7 +1089,7 @@ ping4_parse_reply(struct socket_st *sock, struct msghdr *msg, int cc, void *addr
if (csfailed)
printf("(BAD CHECKSUM)");
pr_icmph(icp->type, icp->code, ntohl(icp->un.gateway), icp);
- return !error_pkt;
+ return 1;
}
default:
/* MUST NOT */