Skip to content

Commit

Permalink
Added log statements - full test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
traptibalgi authored and traptibalgi committed Oct 5, 2024
1 parent 5d9a30a commit 0903d19
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 130 deletions.
Binary file modified server/aesdsocket
Binary file not shown.
8 changes: 7 additions & 1 deletion server/aesdsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ int sockfd, new_fd;
struct addrinfo *res; // will point to the results
volatile sig_atomic_t caught_signal = 0;
FILE *tmp_file = NULL;
char client_ip[INET_ADDRSTRLEN]; /* Size for IPv4 addresses */

void cleanup()
{
if (new_fd != -1)
{
shutdown(new_fd, SHUT_RDWR);
close(new_fd);
syslog(LOG_DEBUG, "Closed connection from %s", client_ip);
}

if (sockfd != -1)
Expand Down Expand Up @@ -249,7 +251,6 @@ int main ( int argc, char **argv )
exit(1);
}

char client_ip[INET_ADDRSTRLEN]; /* Size for IPv4 addresses */
inet_ntop(their_addr.ss_family, &(((struct sockaddr_in*)&their_addr)->sin_addr), client_ip, sizeof(client_ip));
syslog(LOG_DEBUG, "Accepted connection from %s", client_ip);

Expand All @@ -261,6 +262,7 @@ int main ( int argc, char **argv )
{
syslog(LOG_ERR, "Memory allocation failed for receiving buffer");
close(new_fd);
syslog(LOG_DEBUG, "Closed connection from %s", client_ip);
continue;
}

Expand All @@ -284,6 +286,7 @@ int main ( int argc, char **argv )
syslog(LOG_ERR, "Realloc failed for receiving buffer");
free(buf);
close(new_fd);
syslog(LOG_DEBUG, "Closed connection from %s", client_ip);
continue;
}
memset(new_buf + total_received, 0, receive_buf_size - total_received);
Expand All @@ -297,6 +300,7 @@ int main ( int argc, char **argv )
syslog(LOG_ERR, "Receive failed");
free(buf);
close(new_fd);
syslog(LOG_DEBUG, "Closed connection from %s", client_ip);
continue;
}

Expand Down Expand Up @@ -332,6 +336,7 @@ int main ( int argc, char **argv )
{
syslog(LOG_ERR, "Memory allocation failed for sending buffer");
close(new_fd);
syslog(LOG_DEBUG, "Closed connection from %s", client_ip);
continue;
}

Expand All @@ -346,6 +351,7 @@ int main ( int argc, char **argv )

free(send_buf);
close(new_fd);
syslog(LOG_DEBUG, "Closed connection from %s", client_ip);
}

cleanup();
Expand Down
Loading

0 comments on commit 0903d19

Please sign in to comment.