diff options
author | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-04-19 08:41:26 +0200 |
---|---|---|
committer | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-04-19 08:41:26 +0200 |
commit | 1078d2387db43d0c7e982d1ba3340dc67fe0fed9 (patch) | |
tree | ebb144225320e2559b29cc49efb6b5eea03183c5 /Semestr 4/sieci/pracownia2/router/utils.h | |
parent | 4167f191cec04314082896ca4618663e97b4f4f1 (diff) |
Router update
Diffstat (limited to 'Semestr 4/sieci/pracownia2/router/utils.h')
-rw-r--r-- | Semestr 4/sieci/pracownia2/router/utils.h | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Semestr 4/sieci/pracownia2/router/utils.h b/Semestr 4/sieci/pracownia2/router/utils.h index 3d36aed..63ad6fb 100644 --- a/Semestr 4/sieci/pracownia2/router/utils.h +++ b/Semestr 4/sieci/pracownia2/router/utils.h @@ -2,22 +2,35 @@ #define UTILS_H #define UTILS_H +#include "config.h" #include <stdint.h> #include <time.h> #include <poll.h> -#include "router_addr.h" +#include "network_addr.h" #define NS_TO_MS(X) ((long)(X) / (long)1000000) #define S_TO_MS(X) ((long)(X) * (long)1000) +/* Returns a UDP socket. */ int get_socket(); +/* Binds socket to given port and set the broadcast permission. */ void bind_to_port(int sockfd, uint16_t port); +/* Computes the time elapsed between start and finish in miliseconds. */ long get_time_interval(struct timespec start, struct timespec finish); +/* Polls given socket with given timeout and changes the timeout accordingly. */ int poll_socket_modify_timeout(int sockfd, int *timeout); -void recv_and_print(int sockfd, int networks_number, struct router_addr *networks); +/* For debug purposes only. Recieves and prints UDP message. */ +void recv_and_print(int sockfd, int networks_number, struct network_addr *networks); + +/* Sends message in buffer of length buffer_len to addr through given socket. + * IT DOES NOT TERMINATE THE PROGRAM IF SENDTO RETURNS ANY ERRORS! + * One must handle the errors on their own. + */ +size_t send_message(int sockfd, char *buffer, int buffer_len, struct in_addr addr); + #endif
\ No newline at end of file |