I using the PJSIP/PJNATH port-punching library (for STUN/TURN/ICE) and want to create my own UDP-based transport over the punched-ports.
I’m unable to find the data-structure that holds the internal port of the NAT mapping. The reason I need the internal port (on both sides) is to bind the UDP socket to the internal port (instead of the OS picking a random port). Please see diagram.
I realize that the icedemo
sample app is able to do send data back-and-forth on the internet (after punching the ports); so it must bind to the internal UDP port. I just need to know which data-structure holds the internal port.
The pj_ice_sess_send_data
function in the in the ice_session.c
file looked like a promising place to dump variables. But none contain the internal port of the NAT mapping.
//my attempt did *not* work
pj_ice_sess_cand *cand;
cand = comp->valid_check->lcand;
char addrinfo[80];
pj_sockaddr_print(&cand->base_addr, addrinfo, sizeof(addrinfo), 3);
printf("***Local address %s\n", addrinfo);
FYI, the public IP:Port is readily available.
Background
The PJNATH library implements a standards-based STUN/TURN/ICE protocol and punches UDP ports using ICE-UDP checks after it has exchanged the host/server-reflexive/relay IP:Port from both sides.