-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreadsoper.c
More file actions
46 lines (39 loc) · 1.22 KB
/
threadsoper.c
File metadata and controls
46 lines (39 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#define _POSIX_C_SOURCE 200809L
#include <signal.h>
#include <ifaddrs.h>
#include <stdlib.h>
#include <string.h>
#include "threadsoper.h"
void fillArgStruct(ArgListIntInt* arg, List* list1, List* list2, List* list3, int in1, int in2){
arg->list1 = list1;
arg->list2 = list2;
arg->list3 = list3;
arg->in1 = in1;
arg->in2 = in2;
}
void closeThread(pthread_t* thread) {
pthread_kill(*thread,SIGUSR1);
pthread_join(*thread, NULL);
}
void sig_nop(int sig){
return;
}
void ipbroadcastAdresses(List *ipList,List *broadList ) {
struct ifaddrs* ifap, *current;
getifaddrs(&ifap);
if (!ifap) {
perror("No interfaces found\n");
exit(1);
}
for(current=ifap;current;current = current->ifa_next){
if (current->ifa_addr->sa_family==AF_INET && strcmp(current->ifa_name,"lo")){
struct sockaddr_in* ip = malloc(sizeof(struct sockaddr_in ));
*ip = *(struct sockaddr_in *) current->ifa_addr;
struct sockaddr_in* broad = malloc(sizeof(struct sockaddr_in ));
*broad = *(struct sockaddr_in *) current->ifa_dstaddr;
addEnd(ipList,newElem(ip));
addEnd(broadList,newElem(broad));
}
}
freeifaddrs(ifap);
}