Skip to content

Commit

Permalink
Fix some compile warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
SadPencil committed May 26, 2022
1 parent 5da8c53 commit fa647a8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CFLAGS = -g -Wall

objects = client.o dns_c.h socket_utils.o constructor.o c_utils.o parser.o

all: build

build: shell_lib.a
$(CC) $(CFLAGS) -o client client.c dns_client.a
Expand Down
1 change: 1 addition & 0 deletions Makefile.musl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CFLAGS = -g -Wall -static

objects = client.o dns_c.h socket_utils.o constructor.o c_utils.o parser.o

all: build

build: shell_lib.a
$(CC) $(CFLAGS) -o client client.c dns_client.a
Expand Down
1 change: 1 addition & 0 deletions c_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ void get_msg(char *msg, char *handle);
void get_port(char *PORT, char *arg);
int get_socket(char *PORT);
int wait_and_listen(int listener);
int client_get_socket(char *PORT, char *remote_host);
13 changes: 8 additions & 5 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <unistd.h>
#include <sys/types.h>
#include "socket_utils.h"
#include "c_utils.h"
#include "constructor.h"
#include "parser.h"
#include "dns_c.h"
Expand All @@ -30,8 +31,9 @@ long long current_timestamp()

int sockfd = 0;

void *SendDNS(void *threadid)
void *SendDNS(void *arg)
{
int thread_id = (int)arg;
struct DNS_REQUEST question;
unsigned char answer[SIZE_OF_RESP];
memset(answer, 0, SIZE_OF_RESP);
Expand Down Expand Up @@ -77,12 +79,12 @@ void *SendDNS(void *threadid)
* Sending request
*/
assert(sockfd != 0);
printf("Thread %d sent a DNS query.\n", (int)threadid);
printf("Thread %d sent a DNS query.\n", thread_id);
send(sockfd, question.query, question.size, 0);
long long start_time = current_timestamp();
int nb = recv(sockfd, answer, 512, 0);
long long end_time = current_timestamp();
printf("Thread %d received a DNS answer with %d bytes. Time: %ld ms.\n", (int)threadid, nb, end_time - start_time);
printf("Thread %d received a DNS answer with %d bytes. Time: %lld ms.\n", thread_id, nb, end_time - start_time);
// printf("====== %d ========\n", (long)threadid);
// printf("RESPONSE:\n");
// _hex_print(answer, 512);
Expand All @@ -94,9 +96,10 @@ void *SendDNS(void *threadid)
int main(int argc, char **argv)
{
sockfd = client_get_socket(DNS_PORT, NAME_SERVER);

int num_threads = DEFAULT_NUM_THREADS;
if (argc >=2) num_threads = atoi(argv[1]);
if (argc >= 2)
num_threads = atoi(argv[1]);

pthread_t threads[num_threads];
for (int i = 0; i < num_threads; i++)
Expand Down
2 changes: 1 addition & 1 deletion socket_utils.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "socket_utils.h"
#include "c_utils.c"
#include "c_utils.h"

void *get_in_addr(struct sockaddr *sa){
if (sa->sa_family == AF_INET) {
Expand Down

0 comments on commit fa647a8

Please sign in to comment.