refactor: use union instead of bit shifting for echo header
This commit is contained in:
parent
1c60852520
commit
29904cbec6
1 changed files with 7 additions and 6 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
#include "icmp.h"
|
#include "icmp.h"
|
||||||
#include "internal/icmp_send.h"
|
|
||||||
#include "icmp_types.h"
|
#include "icmp_types.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
@ -7,11 +6,13 @@ int
|
||||||
icmp_send_echo(icmp_handle_t *h, struct in_addr dest, uint16_t id,
|
icmp_send_echo(icmp_handle_t *h, struct in_addr dest, uint16_t id,
|
||||||
uint16_t seq, uint8_t ttl)
|
uint16_t seq, uint8_t ttl)
|
||||||
{
|
{
|
||||||
if (0 == send_validate_handle(h))
|
union {
|
||||||
return -1;
|
struct { uint16_t id; uint16_t seq; } echo;
|
||||||
|
uint32_t raw;
|
||||||
|
} hdr_rest;
|
||||||
|
|
||||||
uint32_t header_rest = (uint32_t)id | ((uint32_t)seq << 16);
|
hdr_rest.echo.id = id;
|
||||||
|
hdr_rest.echo.seq = seq;
|
||||||
return icmp_send_raw(h, ICMP_TYPE_ECHO_REQUEST, 0, header_rest,
|
return icmp_send_raw(h, ICMP_TYPE_ECHO_REQUEST, 0, hdr_rest.raw,
|
||||||
NULL, 0, dest, ttl);
|
NULL, 0, dest, ttl);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue