actube/src/cw/cw_detect_nat.c

38 lines
847 B
C
Raw Normal View History

#include <sys/socket.h>
#include "dbg.h"
#include "cw.h"
/**
* @brief Detect NAT after a join/discovery request
* @param conn Connection object
* @retval 1 NAT detected
* @retval 0 no NAT was detected
*/
2022-08-13 09:47:12 +02:00
int cw_detect_nat(struct cw_ElemHandlerParams *params)
{
2022-08-13 09:47:12 +02:00
const char * remote_str;
char local_str[128];
2022-08-13 09:47:12 +02:00
remote_str = cw_cfg_get(params->cfg,"capwap-local-ip-address",NULL);
if (remote_str == NULL){
cw_dbg(DBG_WARN,"Can't detect NAT. No local IP from peer received.");
return 0;
}
/* convert remote connected and sent ip addresse to
* strings */
2022-08-13 09:47:12 +02:00
sock_addrtostr((struct sockaddr*)&(params->conn->addr),local_str,128,0);
/* if connected and sent address is the same, there is
* no NAT */
if (strcmp(remote_str,local_str)==0)
return 0;
/* otherwise ther must be something between AC and WTP */
return 1;
}
2022-08-13 09:47:12 +02:00