# STUN problems - chan\_sip.c: stun failed

**URL:** <https://community.asterisk.org/t/stun-problems-chan-sip-c-stun-failed/31587>\
**Category:** Asterisk Support\
**Created:** [June 5, 2010, 8:57pm UTC](https://community.asterisk.org/t/stun-problems-chan-sip-c-stun-failed/31587 "2010-06-05T20:57:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [June 5, 2010, 8:57pm UTC](https://community.asterisk.org/t/stun-problems-chan-sip-c-stun-failed/31587/1 "2010-06-05T20:57:00Z")

</div>

My public IP changes less frequently than once a month but I decided to use STUN just in case it happens.  
Unfortunately STUN support in asterisk is rather flaky at this point. I regularly get messages in my log:

`[2010-06-05 13:44:55] WARNING[20697] chan_sip.c: stun failed
[2010-06-05 13:44:55] WARNING[20697] chan_sip.c: stun failed
[2010-06-05 13:44:56] WARNING[20697] chan_sip.c: stun failed
[2010-06-05 13:44:56] WARNING[20697] chan_sip.c: stun failed
[2010-06-05 13:44:56] WARNING[20697] chan_sip.c: stun failed
[2010-06-05 13:44:56] WARNING[20697] chan_sip.c: stun failed
[2010-06-05 13:44:56] WARNING[20697] chan_sip.c: stun failed
[2010-06-05 13:44:56] WARNING[20697] chan_sip.c: stun failed
[2010-06-05 13:44:56] WARNING[20697] chan_sip.c: stun failed`

and then asterisk has no idea what my public IP is and I get one way audio.  
sip show settings gives empty Externip in “Network Settings:”

I increased the log level to 99 and there are stun related messages when STUN packet is sent/received:

```auto

```

the problem is the packet from the STUN server is 96 bytes, not 4, yet asterisk has problems reading it.

My version is 1.6.0.22-samy-r60

UPDATE: Some more STUN related entries:

`[2010-06-05 13:44:55] DEBUG[20697] rtp.c: Scrambled STUN packet length (got 20527, expecting 396)
[2010-06-05 13:50:55] DEBUG[20697] rtp.c: Scrambled STUN packet length (got 18249, expecting 438)
[2010-06-05 14:00:57] DEBUG[20697] rtp.c: Scrambled STUN packet length (got 18249, expecting 638)`

which does not make sense at all …

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [June 6, 2010, 6:52am UTC](https://community.asterisk.org/t/stun-problems-chan-sip-c-stun-failed/31587/2 "2010-06-06T06:52:21Z")

</div>

more sniffing on the network explains why this problem happens. when sending stun request asterisk uses the sip socket as the source and the first packet after that, arriving on the sip socket, is assumed to be the stun reply. If it happens to be another sip message then asterisk throws an error because it does not verify if the packet is actually a stun reply and blindly tries to parse it. this makes stun unusable with asterisk.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [August 3, 2010, 12:48am UTC](https://community.asterisk.org/t/stun-problems-chan-sip-c-stun-failed/31587/3 "2010-08-03T00:48:23Z")

</div>

The issue is currently being worked on:

[issues.asterisk.org/view.php?id=17622](https://issues.asterisk.org/view.php?id=17622)

It might allow v1.8 to be the first version with a working STUN support.
