diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-09-21 00:00:13 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-09-21 00:00:13 -0400 |
commit | 433f6eb3a54881913286aa620db93c003c436c16 (patch) | |
tree | fdcd0a6795d35c0714b6eb74f93a2e55a44fa64b | |
parent | dc5d15064b90f9c25b1b47503e4074dba063db70 (diff) |
good stopping point. added some more edge cases.
-rw-r--r-- | server.c | 40 | ||||
-rwxr-xr-x | snowcast_control | bin | 35565 -> 35565 bytes | |||
-rwxr-xr-x | snowcast_listener | bin | 34654 -> 34654 bytes | |||
-rwxr-xr-x | snowcast_server | bin | 56124 -> 56124 bytes | |||
-rw-r--r-- | snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server | bin | 27319 -> 27644 bytes |
5 files changed, 26 insertions, 14 deletions
@@ -578,7 +578,7 @@ void *select_thread(void *arg) { else { // we got some data from a client - if (command_type == 0) { // we got a hello message + if (command_type == 0) { // we got a Hello commmand // get the udp port uint16_t udp_port = -1; @@ -589,7 +589,19 @@ void *select_thread(void *arg) { } udp_port = ntohs(udp_port); - printf("udpPort (from Hello) for new connection is %d.\n", udp_port); + // check if user has a udpPort, if so, close connection + if (user_data[sockfd_to_user[i]].udpPort != -1) { + // send back in invalid command + char * message = "must not sent more than one Hello message"; + send_invalid_command_reply(i, strlen(message), message); + // drop connection upon invalid command + close(i); + FD_CLR(i, &master); + destroy_user(i); + continue; + } + + // printf("udpPort (from Hello) for new connection is %d.\n", udp_port); // update udp port of user update_user_udpPort(i, udp_port); @@ -601,8 +613,17 @@ void *select_thread(void *arg) { if (send_all(i, &welcome, &bytes_to_send) == -1) perror("send_all"); } - else if (command_type == 1) { // we got a setStation command - // check if user has a udpPort + else if (command_type == 1) { // we got a SetStation command + // get the station number + uint16_t station_number = -1; + int bytes_to_read = sizeof(uint16_t); + if (recv_all(i, &station_number, &bytes_to_read) == -1) { + perror("recv_all"); + exit(1); + } + station_number = ntohs(station_number); + + // check if user has a udpPort to stream to if (user_data[sockfd_to_user[i]].udpPort == -1) { // send back in invalid command char * message = "must send Hello message first"; @@ -614,16 +635,7 @@ void *select_thread(void *arg) { continue; } - // get the station number - uint16_t station_number = -1; - int bytes_to_read = sizeof(uint16_t); - if (recv_all(i, &station_number, &bytes_to_read) == -1) { - perror("recv_all"); - exit(1); - } - station_number = ntohs(station_number); - - // printf("station_num: %d\n", station_num); + // check if station num is in range if (station_number >= num_stations || station_number < 0) { // send back in invalid command char * message = "station number out of range"; diff --git a/snowcast_control b/snowcast_control Binary files differindex ebf8c93..4369180 100755 --- a/snowcast_control +++ b/snowcast_control diff --git a/snowcast_listener b/snowcast_listener Binary files differindex b8357dd..c8765c2 100755 --- a/snowcast_listener +++ b/snowcast_listener diff --git a/snowcast_server b/snowcast_server Binary files differindex 6c3f2dc..f3e7928 100755 --- a/snowcast_server +++ b/snowcast_server diff --git a/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server b/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server Binary files differindex 6f668a7..79dd8f6 100644 --- a/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server +++ b/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server |