「🔨」 fix: fixed loop issue (yes when i ping my self i recieve my pings D:)
This commit is contained in:
@ -15,7 +15,6 @@
|
||||
#include <unistd.h>
|
||||
|
||||
int send_icmp(int socket, char *buf, struct sockaddr_in *addr, uint32_t size) {
|
||||
printf("sending\n");
|
||||
int bytes_send = sendto(socket, buf, (unsigned long)size, 0,
|
||||
(struct sockaddr *)addr, sizeof(*addr));
|
||||
|
||||
@ -28,12 +27,14 @@ int send_icmp(int socket, char *buf, struct sockaddr_in *addr, uint32_t size) {
|
||||
|
||||
int receive_icmp(int socket, char *buf, uint32_t size,
|
||||
struct sockaddr_in *addr) {
|
||||
printf("received\n");
|
||||
socklen_t addr_len = sizeof(*addr);
|
||||
int bytes =
|
||||
recvfrom(socket, buf, size, 0, (struct sockaddr *)addr, &addr_len);
|
||||
|
||||
printf("%d\n", bytes);
|
||||
struct icmphdr *icmp =
|
||||
(struct icmphdr *)(buf + (((struct ip *)buf)->ip_hl << 2));
|
||||
if (icmp->type == ICMP_ECHO)
|
||||
bytes =
|
||||
recvfrom(socket, buf, size, 0, (struct sockaddr *)addr, &addr_len);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
@ -50,8 +51,8 @@ void process_icmp(char *buf, int bytes, struct sockaddr_in *addr, int seq,
|
||||
struct icmphdr *icmp = (struct icmphdr *)(buf + len);
|
||||
|
||||
if (icmp->type == ICMP_ECHOREPLY &&
|
||||
ntohs(icmp->un.echo.id) == (getpid() & 0xffff)) {
|
||||
// ntohs(icmp->un.echo.sequence) == seq) {
|
||||
ntohs(icmp->un.echo.id) == (getpid() & 0xffff) &&
|
||||
ntohs(icmp->un.echo.sequence) == (seq & 0xffff)) {
|
||||
|
||||
rx_count++;
|
||||
|
||||
|
@ -58,9 +58,7 @@ int send_ping(int socket, struct sockaddr_in *dest, options_t opt) {
|
||||
while (727) {
|
||||
int seq = tx_count;
|
||||
|
||||
printf("seq = %d\n", seq);
|
||||
init_packet(sendbuf, seq, opt.size);
|
||||
// write(1, sendbuf, opt.size);
|
||||
|
||||
gettimeofday(&pkt_start, NULL);
|
||||
bytes = send_icmp(socket, sendbuf, &addr, opt.size);
|
||||
@ -92,7 +90,6 @@ int send_ping(int socket, struct sockaddr_in *dest, options_t opt) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
// TODO: fix this shitty loop
|
||||
int ping(args_t *args) {
|
||||
int ret;
|
||||
options_t opt = init_opt(args);
|
||||
|
Reference in New Issue
Block a user