Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ extern int opt_debug,
icmp_ip_tos,
icmp_ip_tot_len,
icmp_ip_id,
icmp_id,
icmp_ip_srcport,
icmp_ip_dstport,
opt_force_icmp,
Expand Down
1 change: 1 addition & 0 deletions hping2.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
#define DEFAULT_ICMP_IP_TOS 0
#define DEFAULT_ICMP_IP_TOT_LEN 0 /* computed by send_icmp_*() */
#define DEFAULT_ICMP_IP_ID 0 /* rand */
#define DEFAULT_ICMP_ID -1 /* -1 means rand */
#define DEFAULT_ICMP_CKSUM -1 /* -1 means compute the cksum */
#define DEFAULT_ICMP_IP_PROTOCOL 6 /* TCP */
#define DEFAULT_RAW_IP_PROTOCOL 6 /* TCP */
Expand Down
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ int
icmp_ip_tos = DEFAULT_ICMP_IP_TOS,
icmp_ip_tot_len = DEFAULT_ICMP_IP_TOT_LEN,
icmp_ip_id = DEFAULT_ICMP_IP_ID,
icmp_id = DEFAULT_ICMP_ID,
icmp_ip_protocol= DEFAULT_ICMP_IP_PROTOCOL,
icmp_ip_srcport = DEFAULT_DPORT,
icmp_ip_dstport = DEFAULT_DPORT,
Expand Down
9 changes: 8 additions & 1 deletion parseoptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum { OPT_COUNT, OPT_INTERVAL, OPT_NUMERIC, OPT_QUIET, OPT_INTERFACE,
OPT_SAFE, OPT_TRACEROUTE, OPT_TOS, OPT_MTU, OPT_SEQNUM, OPT_BADCKSUM,
OPT_SETSEQ, OPT_SETACK, OPT_ICMPTYPE, OPT_ICMPCODE, OPT_END,
OPT_RROUTE, OPT_IPPROTO, OPT_ICMP_IPVER, OPT_ICMP_IPHLEN,
OPT_ICMP_IPLEN, OPT_ICMP_IPID, OPT_ICMP_IPPROTO, OPT_ICMP_CKSUM,
OPT_ICMP_IPLEN, OPT_ICMP_IPID, OPT_ICMP_IPPROTO, OPT_ICMP_CKSUM, OPT_ICMP_ID,
OPT_ICMP_TS, OPT_ICMP_ADDR, OPT_TCPEXITCODE, OPT_FAST, OPT_TR_KEEP_TTL,
OPT_TCP_TIMESTAMP, OPT_TR_STOP, OPT_TR_NO_RTT, OPT_ICMP_HELP,
OPT_RAND_DEST, OPT_RAND_SOURCE, OPT_LSRR, OPT_SSRR, OPT_ROUTE_HELP,
Expand Down Expand Up @@ -102,6 +102,7 @@ static struct ago_optlist hping_optlist[] = {
{ '\0', "icmp-ipid", OPT_ICMP_IPID, AGO_NEEDARG|AGO_EXCEPT0 },
{ '\0', "icmp-ipproto", OPT_ICMP_IPPROTO, AGO_NEEDARG|AGO_EXCEPT0 },
{ '\0', "icmp-cksum", OPT_ICMP_CKSUM, AGO_NEEDARG|AGO_EXCEPT0 },
{ '\0', "icmp-id", OPT_ICMP_ID, AGO_NEEDARG|AGO_EXCEPT0 },
{ '\0', "icmp-ts", OPT_ICMP_TS, AGO_NOARG },
{ '\0', "icmp-addr", OPT_ICMP_ADDR, AGO_NOARG },
{ '\0', "tcpexitcode", OPT_TCPEXITCODE, AGO_NOARG },
Expand Down Expand Up @@ -469,6 +470,9 @@ int parse_options(int argc, char **argv)
case OPT_ICMP_IPID:
icmp_ip_id = strtol(ago_optarg, NULL, 0);
break;
case OPT_ICMP_ID:
icmp_id = strtol(ago_optarg, NULL, 0);
break;
case OPT_ICMP_IPPROTO:
icmp_ip_protocol = strtol(ago_optarg, NULL, 0);
break;
Expand Down Expand Up @@ -687,6 +691,9 @@ int parse_options(int argc, char **argv)
usec_delay.it_value.tv_usec =
usec_delay.it_interval.tv_usec = 0;
}

if (icmp_id == -1)
icmp_id=getpid();

return 1;
}
9 changes: 6 additions & 3 deletions sendicmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ void send_icmp_echo(void)
icmp->type = opt_icmptype; /* echo replay or echo request */
icmp->code = opt_icmpcode; /* should be indifferent */
icmp->checksum = 0;
icmp->un.echo.id = getpid() & 0xffff;
/* icmp->un.echo.id = getpid() & 0xffff; */
icmp->un.echo.id = icmp_id & 0xffff;
icmp->un.echo.sequence = _icmp_seq;

/* data */
Expand Down Expand Up @@ -127,7 +128,8 @@ void send_icmp_timestamp(void)
icmp->type = opt_icmptype; /* echo replay or echo request */
icmp->code = 0;
icmp->checksum = 0;
icmp->un.echo.id = getpid() & 0xffff;
/* icmp->un.echo.id = getpid() & 0xffff; */
icmp->un.echo.id = icmp_id & 0xffff;
icmp->un.echo.sequence = _icmp_seq;
tstamp_data->orig = htonl(get_midnight_ut_ms());
tstamp_data->recv = tstamp_data->tran = 0;
Expand Down Expand Up @@ -169,7 +171,8 @@ void send_icmp_address(void)
icmp->type = opt_icmptype; /* echo replay or echo request */
icmp->code = 0;
icmp->checksum = 0;
icmp->un.echo.id = getpid() & 0xffff;
/* icmp->un.echo.id = getpid() & 0xffff; */
icmp->un.echo.id = icmp_id & 0xffff;
icmp->un.echo.sequence = _icmp_seq;
memset(packet+ICMPHDR_SIZE, 0, 4);

Expand Down
1 change: 1 addition & 0 deletions usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void icmp_help(void)
" --icmp-srcport set tcp/udp source port ( default random )\n"
" --icmp-dstport set tcp/udp destination port ( default random )\n"
" --icmp-cksum set icmp checksum ( default the right cksum)\n"
" --icmp-id set icmp id ( default random )\n"
);
exit(0);
}
Expand Down
5 changes: 3 additions & 2 deletions waitpacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ int recv_icmp(void *packet, size_t size)
if ((icmp.type == ICMP_ECHOREPLY ||
icmp.type == ICMP_TIMESTAMPREPLY ||
icmp.type == ICMP_ADDRESSREPLY) &&
icmp.un.echo.id == (getpid() & 0xffff))
icmp.un.echo.id == ( icmp_id & 0xffff))
/* icmp.un.echo.id == (getpid() & 0xffff)) */
{
int icmp_seq = icmp.un.echo.sequence;
int status;
Expand All @@ -254,7 +255,7 @@ int recv_icmp(void *packet, size_t size)
status = rtt(&icmp_seq, 0, &ms_delay);
log_ip(status, icmp_seq);

printf("icmp_seq=%d rtt=%.1f ms\n", icmp_seq, ms_delay);
printf("icmp_id=%d icmp_seq=%d rtt=%.1f ms\n",icmp_id, icmp_seq, ms_delay);
if (icmp.type == ICMP_TIMESTAMPREPLY) {
if ((size - ICMPHDR_SIZE) >= 12)
log_icmp_ts(packet+ICMPHDR_SIZE);
Expand Down