added errors, removed util.c, and sperated install and build in make
This commit is contained in:
4
Makefile
4
Makefile
@ -24,7 +24,9 @@ SUBDIRECTORIES =
|
|||||||
|
|
||||||
# -- Make Recipes --
|
# -- Make Recipes --
|
||||||
# DO NOT TOUCH BELOW UNLESS YOU KNOW WHAT YOU ARE DOING :)
|
# DO NOT TOUCH BELOW UNLESS YOU KNOW WHAT YOU ARE DOING :)
|
||||||
all: $(NAME)
|
all: $(BUILD_DIR)/$(NAME)
|
||||||
|
|
||||||
|
install: $(NAME)
|
||||||
|
|
||||||
re: fclean all
|
re: fclean all
|
||||||
|
|
||||||
|
29
srcs/main.c
29
srcs/main.c
@ -147,7 +147,7 @@ int main(int argc, char** argv) {
|
|||||||
int timeout = 3000;
|
int timeout = 3000;
|
||||||
struct timespec recvt;
|
struct timespec recvt;
|
||||||
struct addrinfo hints = {0};
|
struct addrinfo hints = {0};
|
||||||
struct addrinfo *res = NULL;
|
struct addrinfo* res = NULL;
|
||||||
struct pollfd fds[1];
|
struct pollfd fds[1];
|
||||||
double min = INT32_MAX;
|
double min = INT32_MAX;
|
||||||
double max = 0;
|
double max = 0;
|
||||||
@ -182,10 +182,20 @@ int main(int argc, char** argv) {
|
|||||||
inet_ntop(res->ai_family, &destination.sin_addr, ip_str, INET_ADDRSTRLEN);
|
inet_ntop(res->ai_family, &destination.sin_addr, ip_str, INET_ADDRSTRLEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
|
struct protoent *proto = getprotobyname("icmp");
|
||||||
|
if (!proto) {
|
||||||
|
dprintf (STDERR_FILENO, "%s: unknown protocol icmp.\n", argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
sock = socket(AF_INET, SOCK_RAW, proto->p_proto);
|
||||||
|
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
dprintf(STDERR_FILENO, "%s: socket() failed: %s\n", argv[0], strerror(errno));
|
if (errno == EPERM || errno == EACCES || errno == EPROTONOSUPPORT) {
|
||||||
|
dprintf(STDERR_FILENO, "%s: Lacking privilege for icmp socket.\n", argv[0]);
|
||||||
|
} else {
|
||||||
|
dprintf(STDERR_FILENO, "%s: %s\n", argv[0], strerror(errno));
|
||||||
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,10 +278,9 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
} else if (ret == 0) {
|
} else if (ret == 0) {
|
||||||
printf("No reply received within the timeout period\n");
|
printf("No reply received within the timeout period\n");
|
||||||
|
} else {
|
||||||
|
perror("Poll failed");
|
||||||
}
|
}
|
||||||
// else {
|
|
||||||
// perror("Poll failed");
|
|
||||||
// }
|
|
||||||
|
|
||||||
pause();
|
pause();
|
||||||
}
|
}
|
||||||
@ -281,7 +290,13 @@ int main(int argc, char** argv) {
|
|||||||
if (rept) {
|
if (rept) {
|
||||||
printf("+%zu duplicates, ", rept);
|
printf("+%zu duplicates, ", rept);
|
||||||
}
|
}
|
||||||
printf("%zu%% packet loss\n", (xmit - recvd) / xmit * 100);
|
if (xmit) {
|
||||||
|
if (recvd > xmit) {
|
||||||
|
printf("-- somebody is printing forged packets!\n");
|
||||||
|
} else {
|
||||||
|
printf("%zu%% packet loss\n", (xmit - recvd) / xmit * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
double total = recvd + rept;
|
double total = recvd + rept;
|
||||||
avg /= total;
|
avg /= total;
|
||||||
stddev = stddev / total - avg * avg;
|
stddev = stddev / total - avg * avg;
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by jrathelo on 2/24/25.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <main.h>
|
|
Reference in New Issue
Block a user