If not set into wtp.conf the client bind to any port

This commit is contained in:
vemax78 2013-05-28 22:22:16 +02:00
parent 16fe0bb6bd
commit 37e60bb755
4 changed files with 35 additions and 20 deletions

View File

@ -20,6 +20,7 @@ static int ac_init(void) {
capwap_network_init(&g_ac.net);
g_ac.mtu = CAPWAP_MTU_DEFAULT;
g_ac.binding = capwap_array_create(sizeof(unsigned short), 0);
g_ac.net.bind_sock_ctrl_port = CAPWAP_CONTROL_PORT;
/* Standard name */
strcpy((char*)g_ac.acname.name, AC_STANDARD_NAME);
@ -477,6 +478,16 @@ static int ac_parsing_configuration_1_0(config_t* config) {
}
}
/* Set network port of WTP */
if (config_lookup_int(config, "application.network.port", &configLongInt) == CONFIG_TRUE) {
if ((configLongInt > 0) && (configLongInt < 65535)) {
g_ac.net.bind_sock_ctrl_port = (unsigned short)configLongInt;
} else {
capwap_logging_error("Invalid configuration file, invalid application.network.port value");
return 0;
}
}
/* Set transport of AC */
if (config_lookup_string(config, "application.network.transport", &configString) == CONFIG_TRUE) {
if (!strcmp(configString, "udp")) {

View File

@ -145,7 +145,6 @@ static int capwap_prepare_bind_socket(struct capwap_network* net, int socketfami
struct sockaddr_storage bindaddr;
ASSERT(net != NULL);
ASSERT(net->bind_sock_ctrl_port != 0);
ASSERT((socketfamily == AF_INET) || (socketfamily == AF_INET6));
ASSERT((socketprotocol == IPPROTO_UDP) || (socketprotocol == IPPROTO_UDPLITE));
@ -170,7 +169,7 @@ static int capwap_prepare_bind_socket(struct capwap_network* net, int socketfami
if (sock_data >= 0) {
if (!capwap_configure_socket(sock_data, socketfamily, socketprotocol, 0, net->bind_interface, net->bind_data_flags)) {
/* Bind address */
CAPWAP_SET_NETWORK_PORT(&bindaddr, net->bind_sock_ctrl_port + 1);
CAPWAP_SET_NETWORK_PORT(&bindaddr, (!net->bind_sock_ctrl_port ? 0 : net->bind_sock_ctrl_port + 1));
if (!bind(sock_data, (struct sockaddr*)&bindaddr, sizeof(struct sockaddr_storage))) {
result = 1;
capwap_save_socket(net, socketfamily, socketprotocol, sock_ctrl, sock_data);
@ -453,8 +452,12 @@ void capwap_network_init(struct capwap_network* net) {
ASSERT(net != NULL);
/* */
memset(net, 0, sizeof(struct capwap_network));
/* */
net->sock_family = AF_UNSPEC;
net->bind_sock_ctrl_port = CAPWAP_CONTROL_PORT;
net->bind_sock_ctrl_port = INADDR_ANY;
for (i = 0; i < CAPWAP_MAX_SOCKETS; i++) {
net->sock_ctrl[i] = -1;
net->sock_data[i] = -1;
@ -1216,8 +1219,9 @@ void capwap_interface_list(struct capwap_network* net, struct capwap_list* list)
ASSERT(list != NULL);
/* Get interface list */
if (getifaddrs(&ifaddrlist) != 0)
return;
if (getifaddrs(&ifaddrlist) != 0) {
return;
}
/* */
for (ifcurrentpos = ifaddrlist; ifcurrentpos != NULL; ifcurrentpos = ifcurrentpos->ifa_next) {

View File

@ -753,7 +753,7 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
/* Set network port of WTP */
if (config_lookup_int(config, "application.network.port", &configLongInt) == CONFIG_TRUE) {
if ((configLongInt > 0) && (configLongInt < 65536)) {
if ((configLongInt > 0) && (configLongInt < 65535)) {
g_wtp.net.bind_sock_ctrl_port = (unsigned short)configLongInt;
} else {
capwap_logging_error("Invalid configuration file, invalid application.network.port value");