Update
This commit is contained in:
Binary file not shown.
+23
-6
@@ -37,7 +37,7 @@ struct arguments {
|
||||
*/
|
||||
|
||||
static char doc[] = "DNS Trace usage:";
|
||||
static char args_doc[] = "ARG1 ARG2";
|
||||
static char args_doc[] = "[ARGS]";
|
||||
|
||||
static error_t parse_opts(int key, char *arg, struct argp_state *state){
|
||||
struct arguments *arguments = state->input;
|
||||
@@ -86,8 +86,10 @@ struct arguments parse_args(int argc, char *argv[]){
|
||||
static void signalHandler(int signum){
|
||||
running = 0;
|
||||
}
|
||||
|
||||
static int open_raw_sock(const char *name) {
|
||||
/*
|
||||
* This function create a raw socket and bind it to the ifname
|
||||
*/
|
||||
static int create_rsock(const char *name) {
|
||||
struct sockaddr_ll sll;
|
||||
int sock;
|
||||
|
||||
@@ -110,6 +112,9 @@ static int open_raw_sock(const char *name) {
|
||||
return sock;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function map the type of DNS request
|
||||
*/
|
||||
static char *mapReqType(const int req){
|
||||
char *tmp = malloc(8);
|
||||
if (tmp == NULL)
|
||||
@@ -127,6 +132,9 @@ static char *mapReqType(const int req){
|
||||
};
|
||||
return tmp;
|
||||
}
|
||||
/*
|
||||
* This function map the DNS class RR
|
||||
*/
|
||||
static char *mapClass(const int class){
|
||||
char *tmp = malloc(8);
|
||||
if (tmp == NULL)
|
||||
@@ -152,6 +160,9 @@ static char *mapClass(const int class){
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
/*
|
||||
* This function map the DNS type RR
|
||||
*/
|
||||
static char *mapType(const int type){
|
||||
char *tmp = malloc(8);
|
||||
if (tmp == NULL)
|
||||
@@ -231,6 +242,10 @@ static int syslog_time(time_t ts, char t[32], size_t l){
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* This function get the hostname of the system
|
||||
* If not find, the hostname is ubuntu
|
||||
*/
|
||||
static void get_hostname(){
|
||||
/* Get the hostname */
|
||||
if (gethostname(hostname, 127) == -1){
|
||||
@@ -264,6 +279,7 @@ static void print_query(struct event *s_event){
|
||||
free(type);
|
||||
|
||||
printf("%s", s_event->qname);
|
||||
printf("\n");
|
||||
}
|
||||
/*
|
||||
* This function save to log file the query section in rsylog format
|
||||
@@ -413,6 +429,9 @@ static void print_answer(struct event *s_event){
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This function is called when a new event is pushed in the ring buffer from the eBPf program
|
||||
*/
|
||||
int handle_event(void *ctx, void *data, size_t data_sz){
|
||||
struct event *s_event = (struct event*)data;
|
||||
if (s_event->req_type == REQ_QUERY){
|
||||
@@ -428,8 +447,6 @@ int handle_event(void *ctx, void *data, size_t data_sz){
|
||||
answer_to_log(s_event);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
int main(int argc, char *argv[]){
|
||||
@@ -449,7 +466,7 @@ int main(int argc, char *argv[]){
|
||||
}
|
||||
printf("Listen to %s\n", arguments.interface);
|
||||
|
||||
sock = open_raw_sock(arguments.interface);
|
||||
sock = create_rsock(arguments.interface);
|
||||
if (sock == -1){
|
||||
printf("Failed to listen to the interface %s\n", arguments.interface);
|
||||
exit(-1);
|
||||
|
||||
Reference in New Issue
Block a user