「🔨」 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>
|
#include <unistd.h>
|
||||||
|
|
||||||
int send_icmp(int socket, char *buf, struct sockaddr_in *addr, uint32_t size) {
|
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,
|
int bytes_send = sendto(socket, buf, (unsigned long)size, 0,
|
||||||
(struct sockaddr *)addr, sizeof(*addr));
|
(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,
|
int receive_icmp(int socket, char *buf, uint32_t size,
|
||||||
struct sockaddr_in *addr) {
|
struct sockaddr_in *addr) {
|
||||||
printf("received\n");
|
|
||||||
socklen_t addr_len = sizeof(*addr);
|
socklen_t addr_len = sizeof(*addr);
|
||||||
int bytes =
|
int bytes =
|
||||||
recvfrom(socket, buf, size, 0, (struct sockaddr *)addr, &addr_len);
|
recvfrom(socket, buf, size, 0, (struct sockaddr *)addr, &addr_len);
|
||||||
|
struct icmphdr *icmp =
|
||||||
printf("%d\n", bytes);
|
(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;
|
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);
|
struct icmphdr *icmp = (struct icmphdr *)(buf + len);
|
||||||
|
|
||||||
if (icmp->type == ICMP_ECHOREPLY &&
|
if (icmp->type == ICMP_ECHOREPLY &&
|
||||||
ntohs(icmp->un.echo.id) == (getpid() & 0xffff)) {
|
ntohs(icmp->un.echo.id) == (getpid() & 0xffff) &&
|
||||||
// ntohs(icmp->un.echo.sequence) == seq) {
|
ntohs(icmp->un.echo.sequence) == (seq & 0xffff)) {
|
||||||
|
|
||||||
rx_count++;
|
rx_count++;
|
||||||
|
|
||||||
|
@ -58,9 +58,7 @@ int send_ping(int socket, struct sockaddr_in *dest, options_t opt) {
|
|||||||
while (727) {
|
while (727) {
|
||||||
int seq = tx_count;
|
int seq = tx_count;
|
||||||
|
|
||||||
printf("seq = %d\n", seq);
|
|
||||||
init_packet(sendbuf, seq, opt.size);
|
init_packet(sendbuf, seq, opt.size);
|
||||||
// write(1, sendbuf, opt.size);
|
|
||||||
|
|
||||||
gettimeofday(&pkt_start, NULL);
|
gettimeofday(&pkt_start, NULL);
|
||||||
bytes = send_icmp(socket, sendbuf, &addr, opt.size);
|
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;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fix this shitty loop
|
|
||||||
int ping(args_t *args) {
|
int ping(args_t *args) {
|
||||||
int ret;
|
int ret;
|
||||||
options_t opt = init_opt(args);
|
options_t opt = init_opt(args);
|
||||||
|
Reference in New Issue
Block a user