diff options
author | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-03-18 17:14:01 +0100 |
---|---|---|
committer | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-03-18 17:14:01 +0100 |
commit | a3085918e686b3e027ab831b77acda615e12460d (patch) | |
tree | 4e915860f598a3f110d3630c182208cb6dec8f71 | |
parent | a52f462140e3a38fb0f08d5ea74bdafe039bb428 (diff) |
cos tam
-rw-r--r-- | Semestr 4/aisd/Wykłady/Notatka 7 - Programowanie Dynamiczne cd.pdf | bin | 0 -> 214965 bytes | |||
-rw-r--r-- | Semestr 4/sieci/pracownia1/traceroute.c | 21 |
2 files changed, 18 insertions, 3 deletions
diff --git a/Semestr 4/aisd/Wykłady/Notatka 7 - Programowanie Dynamiczne cd.pdf b/Semestr 4/aisd/Wykłady/Notatka 7 - Programowanie Dynamiczne cd.pdf Binary files differnew file mode 100644 index 0000000..7040119 --- /dev/null +++ b/Semestr 4/aisd/Wykłady/Notatka 7 - Programowanie Dynamiczne cd.pdf diff --git a/Semestr 4/sieci/pracownia1/traceroute.c b/Semestr 4/sieci/pracownia1/traceroute.c index 7918957..88d233a 100644 --- a/Semestr 4/sieci/pracownia1/traceroute.c +++ b/Semestr 4/sieci/pracownia1/traceroute.c @@ -7,6 +7,7 @@ #include <stdlib.h> #include <netinet/ip_icmp.h> #include <assert.h> +#include <time.h> #define MAX_TTL 30 #define MESSAGES_PER_TTL 3 @@ -84,12 +85,26 @@ void send_icmp_packet(int sockfd, struct sockaddr_in *destination, int ttl) { fprintf(stdout, "Bytes sent: %ld\n", bytes_sent); } +/* Return ip address of the sender of recceived package */ +in_addr_t recv_dontwait(int sockfd) { + struct sockaddr_in sender; + socklen_t sender_len = sizeof(sender); + uint8_t buffer[IP_MAXPACKET]; + + ssize_t packet_len = recvfrom(sockfd, buffer, IP_MAXPACKET, MSG_DONTWAIT, + (struct sockaddr*)&sender, &sender_len); + + if (packet_len == -1) { + fprintf(stderr, "Error while recieving a packet: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + + return sender.sin_addr.s_addr; +} + int traceroute(struct sockaddr_in *destination) { int sockfd = create_raw_icmp_socket(); - struct sockaddr_in sender; - socklen_t sender_len = sizeof(sender); - uint8_t buffer[IP_MAXPACKET]; for (int ttl = 1; ttl <= MAX_TTL; ++ttl) { send_icmp_packet(sockfd, destination, ttl); } |