mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
move tcp
This commit is contained in:
parent
d9be2da7b4
commit
8a735577c4
4 changed files with 115 additions and 116 deletions
|
@ -187,8 +187,6 @@ pthread_mutex_t client_array_mutex;
|
||||||
struct ap_s ap_array[ARRAY_AP_LEN];
|
struct ap_s ap_array[ARRAY_AP_LEN];
|
||||||
pthread_mutex_t ap_array_mutex;
|
pthread_mutex_t ap_array_mutex;
|
||||||
|
|
||||||
void print_tcp_array();
|
|
||||||
|
|
||||||
int mac_is_equal(uint8_t addr1[], uint8_t addr2[]);
|
int mac_is_equal(uint8_t addr1[], uint8_t addr2[]);
|
||||||
|
|
||||||
int mac_is_greater(uint8_t addr1[], uint8_t addr2[]);
|
int mac_is_greater(uint8_t addr1[], uint8_t addr2[]);
|
||||||
|
@ -261,9 +259,5 @@ node *probe_list_head;
|
||||||
|
|
||||||
#define ARRAY_NETWORK_LEN 50
|
#define ARRAY_NETWORK_LEN 50
|
||||||
struct network_con_s network_array[ARRAY_NETWORK_LEN];
|
struct network_con_s network_array[ARRAY_NETWORK_LEN];
|
||||||
pthread_mutex_t tcp_array_mutex;
|
|
||||||
int insert_to_tcp_array(struct network_con_s entry);
|
|
||||||
int tcp_array_contains_address(struct sockaddr_in entry);
|
|
||||||
void send_tcp(char* msg);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -6,9 +6,7 @@
|
||||||
#define DAWN_TCPSOCKET_H
|
#define DAWN_TCPSOCKET_H
|
||||||
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <pthread.h>
|
||||||
void *run_tcp_socket(void *arg);
|
|
||||||
int add_tcp_conncection(char* ipv4, int port);
|
|
||||||
|
|
||||||
struct network_con_s
|
struct network_con_s
|
||||||
{
|
{
|
||||||
|
@ -16,4 +14,15 @@ struct network_con_s
|
||||||
struct sockaddr_in sock_addr;
|
struct sockaddr_in sock_addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void *run_tcp_socket(void *arg);
|
||||||
|
int add_tcp_conncection(char* ipv4, int port);
|
||||||
|
|
||||||
|
void print_tcp_array();
|
||||||
|
pthread_mutex_t tcp_array_mutex;
|
||||||
|
int insert_to_tcp_array(struct network_con_s entry);
|
||||||
|
int tcp_array_contains_address(struct sockaddr_in entry);
|
||||||
|
void send_tcp(char* msg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif //DAWN_TCPSOCKET_H
|
#endif //DAWN_TCPSOCKET_H
|
||||||
|
|
|
@ -21,6 +21,14 @@
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
|
|
||||||
|
int tcp_array_insert(struct network_con_s entry);
|
||||||
|
|
||||||
|
int tcp_array_contains_address_help(struct sockaddr_in entry);
|
||||||
|
|
||||||
|
void print_tcp_entry(struct network_con_s entry);
|
||||||
|
|
||||||
|
int tcp_entry_last = -1;
|
||||||
|
|
||||||
void *run_tcp_socket(void *arg)
|
void *run_tcp_socket(void *arg)
|
||||||
{
|
{
|
||||||
int opt = TRUE;
|
int opt = TRUE;
|
||||||
|
@ -213,4 +221,99 @@ int add_tcp_conncection(char* ipv4, int port){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int insert_to_tcp_array(struct network_con_s entry) {
|
||||||
|
pthread_mutex_lock(&tcp_array_mutex);
|
||||||
|
|
||||||
|
int ret = tcp_array_insert(entry);
|
||||||
|
pthread_mutex_unlock(&tcp_array_mutex);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_tcp_entry(struct network_con_s entry)
|
||||||
|
{
|
||||||
|
printf("Conenctin to Port: %d\n", entry.sock_addr.sin_port);
|
||||||
|
}
|
||||||
|
|
||||||
|
void send_tcp(char* msg)
|
||||||
|
{
|
||||||
|
printf("SENDING TCP!\n");
|
||||||
|
pthread_mutex_lock(&tcp_array_mutex);
|
||||||
|
for (int i = 0; i <= tcp_entry_last; i++) {
|
||||||
|
if(send(network_array[i].sockfd, msg, strlen(msg), 0) < 0)
|
||||||
|
{
|
||||||
|
close(network_array->sockfd);
|
||||||
|
printf("Removing bad TCP connection!\n");
|
||||||
|
for (int j = i; j < tcp_entry_last; j++) {
|
||||||
|
network_array[j] = network_array[j + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tcp_entry_last > -1) {
|
||||||
|
tcp_entry_last--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&tcp_array_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void print_tcp_array()
|
||||||
|
{
|
||||||
|
printf("--------Connections------\n");
|
||||||
|
for (int i = 0; i <= tcp_entry_last; i++) {
|
||||||
|
print_tcp_entry(network_array[i]);
|
||||||
|
}
|
||||||
|
printf("------------------\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int tcp_array_insert(struct network_con_s entry) {
|
||||||
|
if (tcp_entry_last == -1) {
|
||||||
|
network_array[0] = entry;
|
||||||
|
tcp_entry_last++;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = 0; i <= tcp_entry_last; i++) {
|
||||||
|
if (entry.sock_addr.sin_addr.s_addr < network_array[i].sock_addr.sin_addr.s_addr) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (entry.sock_addr.sin_addr.s_addr == network_array[i].sock_addr.sin_addr.s_addr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int j = tcp_entry_last; j >= i; j--) {
|
||||||
|
if (j + 1 <= ARRAY_NETWORK_LEN) {
|
||||||
|
network_array[j + 1] = network_array[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
network_array[i] = entry;
|
||||||
|
|
||||||
|
if (tcp_entry_last < ARRAY_NETWORK_LEN) {
|
||||||
|
tcp_entry_last++;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tcp_array_contains_address(struct sockaddr_in entry) {
|
||||||
|
pthread_mutex_lock(&tcp_array_mutex);
|
||||||
|
|
||||||
|
int ret = tcp_array_contains_address_help(entry);
|
||||||
|
pthread_mutex_unlock(&tcp_array_mutex);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tcp_array_contains_address_help(struct sockaddr_in entry) {
|
||||||
|
if (tcp_entry_last == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = 0; i <= tcp_entry_last; i++) {
|
||||||
|
if (entry.sin_addr.s_addr == network_array[i].sock_addr.sin_addr.s_addr) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -37,12 +37,6 @@ void remove_old_ap_entries(time_t current_time, long long int threshold);
|
||||||
|
|
||||||
void print_ap_entry(ap entry);
|
void print_ap_entry(ap entry);
|
||||||
|
|
||||||
int tcp_array_contains_address_help(struct sockaddr_in entry);
|
|
||||||
|
|
||||||
int tcp_array_insert(struct network_con_s entry);
|
|
||||||
|
|
||||||
void print_tcp_entry(struct network_con_s entry);
|
|
||||||
|
|
||||||
int probe_array_update_rssi(uint8_t bssid_addr[], uint8_t client_addr[], uint32_t rssi);
|
int probe_array_update_rssi(uint8_t bssid_addr[], uint8_t client_addr[], uint32_t rssi);
|
||||||
|
|
||||||
int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]);
|
int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]);
|
||||||
|
@ -56,7 +50,6 @@ int compare_ssid(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare);
|
||||||
int probe_entry_last = -1;
|
int probe_entry_last = -1;
|
||||||
int client_entry_last = -1;
|
int client_entry_last = -1;
|
||||||
int ap_entry_last = -1;
|
int ap_entry_last = -1;
|
||||||
int tcp_entry_last = -1;
|
|
||||||
int mac_list_entry_last = -1;
|
int mac_list_entry_last = -1;
|
||||||
|
|
||||||
void remove_probe_array_cb(struct uloop_timeout *t);
|
void remove_probe_array_cb(struct uloop_timeout *t);
|
||||||
|
@ -1324,103 +1317,3 @@ void print_ap_array() {
|
||||||
}
|
}
|
||||||
printf("------------------\n");
|
printf("------------------\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int insert_to_tcp_array(struct network_con_s entry) {
|
|
||||||
pthread_mutex_lock(&tcp_array_mutex);
|
|
||||||
|
|
||||||
int ret = tcp_array_insert(entry);
|
|
||||||
pthread_mutex_unlock(&tcp_array_mutex);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_tcp_entry(struct network_con_s entry)
|
|
||||||
{
|
|
||||||
printf("Conenctin to Port: %d\n", entry.sock_addr.sin_port);
|
|
||||||
}
|
|
||||||
|
|
||||||
void send_tcp(char* msg)
|
|
||||||
{
|
|
||||||
printf("SENDING TCP!\n");
|
|
||||||
pthread_mutex_lock(&tcp_array_mutex);
|
|
||||||
for (int i = 0; i <= tcp_entry_last; i++) {
|
|
||||||
if(send(network_array[i].sockfd, msg, strlen(msg), 0) < 0)
|
|
||||||
{
|
|
||||||
close(network_array->sockfd);
|
|
||||||
printf("Removing bad TCP connection!\n");
|
|
||||||
for (int j = i; j < client_entry_last; j++) {
|
|
||||||
network_array[j] = network_array[j + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tcp_entry_last > -1) {
|
|
||||||
tcp_entry_last--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&tcp_array_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void print_tcp_array()
|
|
||||||
{
|
|
||||||
printf("--------Connections------\n");
|
|
||||||
for (int i = 0; i <= tcp_entry_last; i++) {
|
|
||||||
print_tcp_entry(network_array[i]);
|
|
||||||
}
|
|
||||||
printf("------------------\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
int tcp_array_insert(struct network_con_s entry) {
|
|
||||||
if (tcp_entry_last == -1) {
|
|
||||||
network_array[0] = entry;
|
|
||||||
tcp_entry_last++;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 0; i <= tcp_entry_last; i++) {
|
|
||||||
if (entry.sock_addr.sin_addr.s_addr < network_array[i].sock_addr.sin_addr.s_addr) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (entry.sock_addr.sin_addr.s_addr == network_array[i].sock_addr.sin_addr.s_addr) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int j = tcp_entry_last; j >= i; j--) {
|
|
||||||
if (j + 1 <= ARRAY_NETWORK_LEN) {
|
|
||||||
network_array[j + 1] = network_array[j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
network_array[i] = entry;
|
|
||||||
|
|
||||||
if (tcp_entry_last < ARRAY_NETWORK_LEN) {
|
|
||||||
tcp_entry_last++;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int tcp_array_contains_address(struct sockaddr_in entry) {
|
|
||||||
pthread_mutex_lock(&tcp_array_mutex);
|
|
||||||
|
|
||||||
int ret = tcp_array_contains_address_help(entry);
|
|
||||||
pthread_mutex_unlock(&tcp_array_mutex);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int tcp_array_contains_address_help(struct sockaddr_in entry) {
|
|
||||||
if (tcp_entry_last == -1) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 0; i <= tcp_entry_last; i++) {
|
|
||||||
if (entry.sin_addr.s_addr == network_array[i].sock_addr.sin_addr.s_addr) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
/*if (entry.sin_addr.s_addr > network_array[i].sock_addr.sin_addr.s_addr) {
|
|
||||||
return 0;
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue