2013-05-01 14:52:55 +02:00
|
|
|
#ifndef __CAPWAP_NETWORK_HEADER__
|
|
|
|
#define __CAPWAP_NETWORK_HEADER__
|
|
|
|
|
2016-08-22 16:59:55 +02:00
|
|
|
#include "array.h"
|
|
|
|
#include "list.h"
|
2013-05-01 14:52:55 +02:00
|
|
|
|
|
|
|
/* Standard Configuration */
|
|
|
|
#define CAPWAP_CONTROL_PORT 5246
|
|
|
|
#define CAPWAP_MAX_PACKET_SIZE 65535
|
|
|
|
|
2014-04-06 17:02:31 +02:00
|
|
|
/* */
|
|
|
|
#define CAPWAP_MACADDRESS_EUI48_BUFFER 18
|
|
|
|
#define CAPWAP_MACADDRESS_EUI64_BUFFER 24
|
2016-03-25 12:41:43 +01:00
|
|
|
#define CAPWAP_MAX_FQDN_SIZE 256
|
2014-04-06 17:02:31 +02:00
|
|
|
|
2014-09-10 21:58:23 +02:00
|
|
|
/* */
|
|
|
|
union sockaddr_capwap {
|
|
|
|
struct sockaddr sa;
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
struct sockaddr_in6 sin6;
|
|
|
|
struct sockaddr_storage ss;
|
|
|
|
};
|
|
|
|
|
2016-03-24 07:09:29 +01:00
|
|
|
struct addr_capwap {
|
|
|
|
char fqdn[CAPWAP_MAX_FQDN_SIZE];
|
2016-03-25 12:41:43 +01:00
|
|
|
union sockaddr_capwap sockaddr;
|
2016-03-24 07:09:29 +01:00
|
|
|
char resolved;
|
|
|
|
};
|
|
|
|
|
2013-05-01 14:52:55 +02:00
|
|
|
/* Helper */
|
2014-12-28 15:48:15 +01:00
|
|
|
#define CAPWAP_GET_NETWORK_PORT(addr) ntohs((((addr)->ss.ss_family == AF_INET) ? (addr)->sin.sin_port : (((addr)->ss.ss_family == AF_INET6) ? (addr)->sin6.sin6_port : 0)))
|
2014-09-10 21:58:23 +02:00
|
|
|
#define CAPWAP_SET_NETWORK_PORT(addr, port) if ((addr)->ss.ss_family == AF_INET) { \
|
|
|
|
(addr)->sin.sin_port = htons(port); \
|
|
|
|
} else if ((addr)->ss.ss_family == AF_INET6) { \
|
|
|
|
(addr)->sin6.sin6_port = htons(port); \
|
|
|
|
}
|
|
|
|
#define CAPWAP_COPY_NETWORK_PORT(addr1, addr2) if ((addr1)->ss.ss_family == (addr2)->ss.ss_family) { \
|
|
|
|
if ((addr1)->ss.ss_family == AF_INET) { \
|
|
|
|
(addr1)->sin.sin_port = (addr2)->sin.sin_port; \
|
|
|
|
} else if ((addr1)->ss.ss_family == AF_INET6) { \
|
|
|
|
(addr1)->sin6.sin6_port = (addr2)->sin6.sin6_port; \
|
|
|
|
} \
|
2013-05-01 14:52:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
#define CAPWAP_RECV_ERROR_SOCKET -1
|
|
|
|
#define CAPWAP_RECV_ERROR_TIMEOUT -2
|
|
|
|
#define CAPWAP_RECV_ERROR_INTR -3
|
|
|
|
|
|
|
|
/* Network struct */
|
|
|
|
struct capwap_network {
|
2014-09-10 21:58:23 +02:00
|
|
|
union sockaddr_capwap localaddr;
|
|
|
|
char bindiface[IFNAMSIZ];
|
|
|
|
int socket;
|
2013-05-27 21:33:23 +02:00
|
|
|
};
|
|
|
|
|
2013-05-01 14:52:55 +02:00
|
|
|
void capwap_network_init(struct capwap_network* net);
|
2014-09-10 21:58:23 +02:00
|
|
|
|
2013-05-01 14:52:55 +02:00
|
|
|
int capwap_network_set_pollfd(struct capwap_network* net, struct pollfd* fds, int fdscount);
|
|
|
|
void capwap_interface_list(struct capwap_network* net, struct capwap_list* list);
|
|
|
|
|
|
|
|
int capwap_get_macaddress_from_interface(const char* interface, char* macaddress);
|
2014-09-10 21:58:23 +02:00
|
|
|
int capwap_network_get_localaddress(union sockaddr_capwap* localaddr, union sockaddr_capwap* peeraddr, char* iface);
|
2013-05-01 14:52:55 +02:00
|
|
|
|
|
|
|
int capwap_bind_sockets(struct capwap_network* net);
|
2016-03-02 15:13:56 +01:00
|
|
|
int capwap_connect_socket(struct capwap_network* net, union sockaddr_capwap *peeraddr);
|
2013-05-01 14:52:55 +02:00
|
|
|
void capwap_close_sockets(struct capwap_network* net);
|
|
|
|
|
2016-03-02 15:13:56 +01:00
|
|
|
int capwap_getsockname(struct capwap_network* net, union sockaddr_capwap *addr);
|
|
|
|
|
2014-09-10 21:58:23 +02:00
|
|
|
int capwap_ipv4_mapped_ipv6(union sockaddr_capwap* addr);
|
|
|
|
int capwap_compare_ip(union sockaddr_capwap* addr1, union sockaddr_capwap* addr2);
|
2013-05-01 14:52:55 +02:00
|
|
|
|
2014-09-10 21:58:23 +02:00
|
|
|
int capwap_sendto(int sock, void* buffer, int size, union sockaddr_capwap* toaddr);
|
|
|
|
int capwap_sendto_fragmentpacket(int sock, struct capwap_list* fragmentlist, union sockaddr_capwap* toaddr);
|
2013-11-02 19:08:05 +01:00
|
|
|
|
2016-03-30 10:39:04 +02:00
|
|
|
ssize_t capwap_recvfrom(int sock, void *buffer, size_t len,
|
|
|
|
union sockaddr_capwap* fromaddr,
|
|
|
|
union sockaddr_capwap* toaddr);
|
2013-05-01 14:52:55 +02:00
|
|
|
|
2014-09-10 21:58:23 +02:00
|
|
|
int capwap_address_from_string(const char* ip, union sockaddr_capwap* sockaddr);
|
2014-12-27 18:45:09 +01:00
|
|
|
const char* capwap_address_to_string(union sockaddr_capwap* sockaddr, char* ip, int len);
|
2013-05-01 14:52:55 +02:00
|
|
|
|
2014-04-02 22:40:04 +02:00
|
|
|
char* capwap_printf_macaddress(char* buffer, const uint8_t* macaddress, int type);
|
|
|
|
int capwap_scanf_macaddress(uint8_t* macaddress, const char* buffer, int type);
|
2013-09-30 17:36:43 +02:00
|
|
|
|
2013-05-01 14:52:55 +02:00
|
|
|
#endif /* __CAPWAP_NETWORK_HEADER__ */
|