Loading etc/client.conf +4 −4 Original line number Diff line number Diff line # client.conf sample daemon_mode=0 mac_address=90fd61e61902 its_nic=en1 mac_address=080027d6c900 its_nic=en0 udp_nic=en0 udp_address=224.168.1.101 udp_nic=en1 udp_address=239.0.102.102 udp_protocol=multicast udp_port=5000 etc/server.conf +3 −3 Original line number Diff line number Diff line # server.conf sample daemon_mode=0 mac_address=90fd61e61902 its_nic=en1 its_nic=en0 udp_nic=en0 udp_address=224.168.1.100;224.168.1.101;224.168.1.102 udp_nic=en1 udp_address=239.0.101.101 udp_protocol=multicast udp_port=5000 include/utils.h +1 −1 Original line number Diff line number Diff line Loading @@ -69,4 +69,4 @@ int32_t load_binary_file(const char *p_filename, uint8_t** p_buffer, size_t* p_s int32_t save_configuration_file(const char *p_filename, const char* progname, ...); char** str_split(const char* p_string, const char p_separator); char** str_split(const char* p_string, const char p_separator, size_t* p_num_addresses); src/its_bridge_server.c +28 −16 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ extern state_t state; bool running = false; int32_t socket_hd = -1; size_t num_addresses = -1; char** udp_addresses = NULL; struct ip_mreq** mreq = NULL; #define PID_FILE_NAME "/var/run/its_bridge_server.pid" #define LOCK_FILE_NAME "/var/run/its_bridge_server.lock" Loading Loading @@ -78,7 +80,8 @@ int main(const int32_t p_argc, char* const p_argv[]) { fprintf(stderr, "Failed to parse command line arguments: UDP address missing, exit.\n"); return -1; } else { udp_addresses = str_split(udp_address, ';'); udp_addresses = str_split(udp_address, ';', &num_addresses); printf("num_addresses = %ld.\n", num_addresses); if (udp_addresses == NULL) { fprintf(stderr, "Failed to parse multicqst adresses (%s), exit.\n", udp_address); return -1; Loading Loading @@ -169,13 +172,20 @@ int main(const int32_t p_argc, char* const p_argv[]) { } printf("Interface address for %s: %s\n", ifr.ifr_name, inet_ntoa(((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr)); /* Join the multicast group */ for (int32_t i = 0; *(udp_addresses + i); i++) { struct ip_mreq mreq = {0}; mreq.imr_interface.s_addr = inet_addr(inet_ntoa(((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr)); /* Local address */ mreq.imr_multiaddr.s_addr = inet_addr(*(udp_addresses + i)); /* IP multicast address of group */ printf("mreq.imr_interface.s_addr = %s.\n", inet_ntoa(mreq.imr_interface)); printf("mreq.imr_multiaddr.s_addr = %s.\n", inet_ntoa(mreq.imr_multiaddr)); if (setsockopt(socket_hd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mreq, sizeof(mreq)) < 0) { mreq = (struct ip_mreq*)malloc(num_addresses * sizeof(struct ip_mreq*)); fprintf(stderr, "0000\n"); memset((void*)mreq, 0x00, num_addresses * sizeof(struct ip_mreq*)); fprintf(stderr, "1111\n"); for (size_t i = 0; i < num_addresses; i++) { fprintf(stderr, "2222\n"); struct ip_mreq* mr = (struct ip_mreq*)malloc(sizeof(struct ip_mreq)); *(mreq + i) = mr; fprintf(stderr, "3333\n"); mr->imr_interface.s_addr = inet_addr(inet_ntoa(((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr)); /* Local address */ mr->imr_multiaddr.s_addr = inet_addr(*(udp_addresses + i)); /* IP multicast address of group */ printf("mreq.imr_interface.s_addr = %s.\n", inet_ntoa(mr->imr_interface)); printf("mreq.imr_multiaddr.s_addr = %s.\n", inet_ntoa(mr->imr_multiaddr)); if (setsockopt(socket_hd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)mr, sizeof(struct ip_mreq)) < 0) { fprintf(stderr, "Failed to set option IP_ADD_MEMBERSHIP: %s.\n", strerror(errno)); close(socket_hd); goto error; Loading Loading @@ -228,19 +238,17 @@ int main(const int32_t p_argc, char* const p_argv[]) { if (socket_hd != -1) { if (strcmp(udp_protocol, "multicast") == 0) { /* Leave the multicast group */ for (int32_t i = 0; *(udp_addresses + i); i++) { struct ip_mreq mreq = {0}; mreq.imr_interface.s_addr = inet_addr(inet_ntoa(((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr)); /* Local address */ mreq.imr_multiaddr.s_addr = inet_addr(*(udp_addresses + i)); /* IP multicast address of group */ printf("mreq.imr_interface.s_addr = %s.\n", inet_ntoa(mreq.imr_interface)); printf("mreq.imr_multiaddr.s_addr = %s.\n", inet_ntoa(mreq.imr_multiaddr)); if (setsockopt(socket_hd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char*)&mreq, sizeof(mreq)) < 0) { for (size_t i = 0; *(udp_addresses + i); i++) { struct ip_mreq* mr = *(mreq + i); if (setsockopt(socket_hd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char*)mr, sizeof(struct ip_mreq)) < 0) { fprintf(stderr, "Failed to set option IP_DROP_MEMBERSHIP: %s.\n", strerror(errno)); continue; } free(*(udp_addresses + i)); free(mr); } free(udp_addresses); free(mreq); } shutdown(socket_hd, SHUT_RDWR); close(socket_hd); Loading Loading @@ -271,10 +279,14 @@ int main(const int32_t p_argc, char* const p_argv[]) { return 0; error: for (int32_t i = 0; *(udp_addresses + i); i++) { for (size_t i = 0; *(udp_addresses + i); i++) { free(*(udp_addresses + i)); if (*(mreq + i) != NULL) { free(*(mreq + i)); } } free(udp_addresses); free(mreq); unlink(PID_FILE_NAME); unlink(LOCK_FILE_NAME); return -1; Loading src/its_web_server_config.c +2 −2 Original line number Diff line number Diff line Loading @@ -105,7 +105,7 @@ static int32_t web_client_page(struct MHD_Connection *p_connection) { "<form action=\"/client_url\" method=\"POST\">" "<label for=\"its_nic\">NIC ITS:</label><br>" "<input type=\"text\" id=\"its_nic\" name=\"its_nic\" value=\"%s\"><br>" "<label for=\"mac_address\">Mac Address:</label><br>" "<label for=\"mac_address\">Source MAC address of ITS messages:</label><br>" "<input type=\"text\" id=\"mac_address\" name=\"mac_address\" value=\"%s\"><br>" "<label for=\"udp_nic\">NIC multicast:</label><br>" "<input type=\"text\" id=\"udp_nic\" name=\"udp_nic\" value=\"%s\"><br>" Loading Loading @@ -151,7 +151,7 @@ static int32_t web_server_page(struct MHD_Connection *p_connection) { "<form action=\"/server_url\" method=\"POST\">" "<label for=\"its_nic\">NIC ITS:</label><br>" "<input type=\"text\" id=\"its_nic\" name=\"its_nic\" value=\"%s\"><br>" "<label for=\"mac_address\">Mac Address:</label><br>" "<label for=\"mac_address\">Mac Address for injection filtering:</label><br>" "<input type=\"text\" id=\"mac_address\" name=\"mac_address\" value=\"%s\"><br>" "<label for=\"udp_nic\">NIC multicast:</label><br>" "<input type=\"text\" id=\"udp_nic\" name=\"udp_nic\" value=\"%s\"><br>" Loading Loading
etc/client.conf +4 −4 Original line number Diff line number Diff line # client.conf sample daemon_mode=0 mac_address=90fd61e61902 its_nic=en1 mac_address=080027d6c900 its_nic=en0 udp_nic=en0 udp_address=224.168.1.101 udp_nic=en1 udp_address=239.0.102.102 udp_protocol=multicast udp_port=5000
etc/server.conf +3 −3 Original line number Diff line number Diff line # server.conf sample daemon_mode=0 mac_address=90fd61e61902 its_nic=en1 its_nic=en0 udp_nic=en0 udp_address=224.168.1.100;224.168.1.101;224.168.1.102 udp_nic=en1 udp_address=239.0.101.101 udp_protocol=multicast udp_port=5000
include/utils.h +1 −1 Original line number Diff line number Diff line Loading @@ -69,4 +69,4 @@ int32_t load_binary_file(const char *p_filename, uint8_t** p_buffer, size_t* p_s int32_t save_configuration_file(const char *p_filename, const char* progname, ...); char** str_split(const char* p_string, const char p_separator); char** str_split(const char* p_string, const char p_separator, size_t* p_num_addresses);
src/its_bridge_server.c +28 −16 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ extern state_t state; bool running = false; int32_t socket_hd = -1; size_t num_addresses = -1; char** udp_addresses = NULL; struct ip_mreq** mreq = NULL; #define PID_FILE_NAME "/var/run/its_bridge_server.pid" #define LOCK_FILE_NAME "/var/run/its_bridge_server.lock" Loading Loading @@ -78,7 +80,8 @@ int main(const int32_t p_argc, char* const p_argv[]) { fprintf(stderr, "Failed to parse command line arguments: UDP address missing, exit.\n"); return -1; } else { udp_addresses = str_split(udp_address, ';'); udp_addresses = str_split(udp_address, ';', &num_addresses); printf("num_addresses = %ld.\n", num_addresses); if (udp_addresses == NULL) { fprintf(stderr, "Failed to parse multicqst adresses (%s), exit.\n", udp_address); return -1; Loading Loading @@ -169,13 +172,20 @@ int main(const int32_t p_argc, char* const p_argv[]) { } printf("Interface address for %s: %s\n", ifr.ifr_name, inet_ntoa(((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr)); /* Join the multicast group */ for (int32_t i = 0; *(udp_addresses + i); i++) { struct ip_mreq mreq = {0}; mreq.imr_interface.s_addr = inet_addr(inet_ntoa(((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr)); /* Local address */ mreq.imr_multiaddr.s_addr = inet_addr(*(udp_addresses + i)); /* IP multicast address of group */ printf("mreq.imr_interface.s_addr = %s.\n", inet_ntoa(mreq.imr_interface)); printf("mreq.imr_multiaddr.s_addr = %s.\n", inet_ntoa(mreq.imr_multiaddr)); if (setsockopt(socket_hd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mreq, sizeof(mreq)) < 0) { mreq = (struct ip_mreq*)malloc(num_addresses * sizeof(struct ip_mreq*)); fprintf(stderr, "0000\n"); memset((void*)mreq, 0x00, num_addresses * sizeof(struct ip_mreq*)); fprintf(stderr, "1111\n"); for (size_t i = 0; i < num_addresses; i++) { fprintf(stderr, "2222\n"); struct ip_mreq* mr = (struct ip_mreq*)malloc(sizeof(struct ip_mreq)); *(mreq + i) = mr; fprintf(stderr, "3333\n"); mr->imr_interface.s_addr = inet_addr(inet_ntoa(((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr)); /* Local address */ mr->imr_multiaddr.s_addr = inet_addr(*(udp_addresses + i)); /* IP multicast address of group */ printf("mreq.imr_interface.s_addr = %s.\n", inet_ntoa(mr->imr_interface)); printf("mreq.imr_multiaddr.s_addr = %s.\n", inet_ntoa(mr->imr_multiaddr)); if (setsockopt(socket_hd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)mr, sizeof(struct ip_mreq)) < 0) { fprintf(stderr, "Failed to set option IP_ADD_MEMBERSHIP: %s.\n", strerror(errno)); close(socket_hd); goto error; Loading Loading @@ -228,19 +238,17 @@ int main(const int32_t p_argc, char* const p_argv[]) { if (socket_hd != -1) { if (strcmp(udp_protocol, "multicast") == 0) { /* Leave the multicast group */ for (int32_t i = 0; *(udp_addresses + i); i++) { struct ip_mreq mreq = {0}; mreq.imr_interface.s_addr = inet_addr(inet_ntoa(((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr)); /* Local address */ mreq.imr_multiaddr.s_addr = inet_addr(*(udp_addresses + i)); /* IP multicast address of group */ printf("mreq.imr_interface.s_addr = %s.\n", inet_ntoa(mreq.imr_interface)); printf("mreq.imr_multiaddr.s_addr = %s.\n", inet_ntoa(mreq.imr_multiaddr)); if (setsockopt(socket_hd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char*)&mreq, sizeof(mreq)) < 0) { for (size_t i = 0; *(udp_addresses + i); i++) { struct ip_mreq* mr = *(mreq + i); if (setsockopt(socket_hd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char*)mr, sizeof(struct ip_mreq)) < 0) { fprintf(stderr, "Failed to set option IP_DROP_MEMBERSHIP: %s.\n", strerror(errno)); continue; } free(*(udp_addresses + i)); free(mr); } free(udp_addresses); free(mreq); } shutdown(socket_hd, SHUT_RDWR); close(socket_hd); Loading Loading @@ -271,10 +279,14 @@ int main(const int32_t p_argc, char* const p_argv[]) { return 0; error: for (int32_t i = 0; *(udp_addresses + i); i++) { for (size_t i = 0; *(udp_addresses + i); i++) { free(*(udp_addresses + i)); if (*(mreq + i) != NULL) { free(*(mreq + i)); } } free(udp_addresses); free(mreq); unlink(PID_FILE_NAME); unlink(LOCK_FILE_NAME); return -1; Loading
src/its_web_server_config.c +2 −2 Original line number Diff line number Diff line Loading @@ -105,7 +105,7 @@ static int32_t web_client_page(struct MHD_Connection *p_connection) { "<form action=\"/client_url\" method=\"POST\">" "<label for=\"its_nic\">NIC ITS:</label><br>" "<input type=\"text\" id=\"its_nic\" name=\"its_nic\" value=\"%s\"><br>" "<label for=\"mac_address\">Mac Address:</label><br>" "<label for=\"mac_address\">Source MAC address of ITS messages:</label><br>" "<input type=\"text\" id=\"mac_address\" name=\"mac_address\" value=\"%s\"><br>" "<label for=\"udp_nic\">NIC multicast:</label><br>" "<input type=\"text\" id=\"udp_nic\" name=\"udp_nic\" value=\"%s\"><br>" Loading Loading @@ -151,7 +151,7 @@ static int32_t web_server_page(struct MHD_Connection *p_connection) { "<form action=\"/server_url\" method=\"POST\">" "<label for=\"its_nic\">NIC ITS:</label><br>" "<input type=\"text\" id=\"its_nic\" name=\"its_nic\" value=\"%s\"><br>" "<label for=\"mac_address\">Mac Address:</label><br>" "<label for=\"mac_address\">Mac Address for injection filtering:</label><br>" "<input type=\"text\" id=\"mac_address\" name=\"mac_address\" value=\"%s\"><br>" "<label for=\"udp_nic\">NIC multicast:</label><br>" "<input type=\"text\" id=\"udp_nic\" name=\"udp_nic\" value=\"%s\"><br>" Loading