[Asterisk-Dev] how does asterisk choose which network interface tobind with?

Race Vanderdecken asterisk at vanderdecken.com
Mon Mar 7 08:39:30 MST 2005


Liang,

Here is the offending code that is causing the "reload" error. In
channels/chan_sip.c

if (gethostname(ourhost, sizeof(ourhost))) {
                ast_log(LOG_WARNING, "Unable to get hostname, SIP
disabled\n");
                return 0;
        }
...
...
...
hp = ast_gethostbyname(ourhost, &ahp);
                if (!hp) {
                        ast_log(LOG_WARNING, "Unable to get IP address
for %s, SIP disabled\n", ourhost);
                        if (!__ourip.s_addr) {
                                ast_destroy(cfg);
                                return 0;
                        }
                } else
                        memcpy(&__ourip, hp->h_addr, sizeof(__ourip));

A good explanation of gethostname is here. (IBM has excellent resource
pages.)

http://publib.boulder.ibm.com/infocenter/pseries/index.jsp?topic=/com.ib
m.aix.doc/libs/commtrf2/gethostname.htm

Since is passing the first gethostname() call it means that something
was copied into the ourhost variable.

Later the ast_gethostbyname() call then fails because it can't find the
host "(none)" that was returned by gethostname(). At least that is what
I am seeing from the code without running your code on your server.

Did you set the host name for the computer? This is where my knowledge
ends because I don't know how the host name gets set or where it is
stored. But gethostname found the words "(none)" when it was called.

Does anyone else know more about gethostbyname()?

Utils.c shows:
struct hostent *ast_gethostbyname(const char *host, struct ast_hostent
*hp)
{
        int res;
        int herrno;
        const char *s;
        struct hostent *result = NULL;
        /* Although it is perfectly legitimate to lookup a pure integer,
for
           the sake of the sanity of people who like to name their peers
as
           integers, we break with tradition and refuse to look up a
           pure integer */
        s = host;
        while(s && *s) {
                if (!isdigit(*s))
                        break;
                s++;
        }
        if (!s || !*s)
                return NULL;
        res = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf),
&result, &herrno);

        if (res || !result || !hp->hp.h_addr_list ||
!hp->hp.h_addr_list[0])
                return NULL;
        return &hp->hp;
}
As above ast_gethostbyname() does not check errorno for what went wrong,
it it just returns null. (Bad programmer, bad, bad, sit.)

Try to discover why you are getting (none) in your gethostname call.

Plan B:

If you are not seeing SIP messages with sip debug turned on then the
messages are not getting to Asterisk.

So let's work on that problem.

>From the Asterisk server box:

1.

#> ping (ipaddress of phone)
Can asterisk see the phone?

2. Can you http with a browser to the phone?
	Http://ip.adress.of.phone

3.
Have you run tcpdump?

#> tcpdump -X -s0 host (ipaddress of phone )

This will give you the low level conversation between the phone and
asterisk. 

Race "The Tyrant" Vanderdecken

-----Original Message-----
From: asterisk-dev-bounces at lists.digium.com
[mailto:asterisk-dev-bounces at lists.digium.com] On Behalf Of Liang Huang
Sent: Monday, March 07, 2005 1:16 AM
To: asterisk-dev at lists.digium.com
Subject: [Asterisk-Dev] how does asterisk choose which network interface
tobind with?

I am trying to port Asterisk 1.0.3 to an embeded system -- a router+adsl

modem+wlan access point, which has many network interfaces, such as 
ppp0, eth0, l0, wlan0, br0..... When asterisk loads SIP channel module, 
it complains:

# asterisk -vvvcdg
.
.
.
  [res_agi.so] => (Asterisk Gateway Interface (AGI))
   == Registered application 'DeadAGI'
   == Registered application 'EAGI'
   == Registered application 'AGI'
  [chan_sip.so] => (Session Initiation Protocol (SIP))
Sep  8 12:41:19 WARNING[318]: chan_sip.c:8683 reload_config: Unable to 
get IP address for (none), SIP disabled
   == Registered application 'SIPDtmfMode'
  [chan_local.so] => (Local Proxy Channel)
.
.
.

Then I set SIP's binding address to 192.168.1.153, which is the IP 
address of "br0", and br0 is the network interface with which the 
embeded system provides its services: thttpd, telnetd, sshd. So I guess 
I should bind SIP channel module to this IP:

# asterisk -vvvcdg
.
.
  [res_agi.so] => (Asterisk Gateway Interface (AGI))
   == Registered application 'DeadAGI'
   == Registered application 'EAGI'
   == Registered application 'AGI'
  [chan_sip.so] => (Session Initiation Protocol (SIP))
   == SIP Listening on 192.168.1.153:5060
   == Using TOS bits 0
   == Registered application 'SIPDtmfMode'
  [chan_local.so] => (Local Proxy Channel)
.
.

It looks like it works this time, but the problem is that my SIP clients

can't register on this asterisk server. Clients keep sending SIP 
registration packets to the server and get no response. I turned on SIP 
debug of the asterisk server, and there is no SIP message.

Could anyone give me some suggestions? or tell me which part of the code

I should read to understand how asterisk register its services (like sip

gateway) to the embeded system. (BTW, the embeded system is a linux mips

system).

Thanks a lot~~~~

Best Regards,

Liang






_______________________________________________
Asterisk-Dev mailing list
Asterisk-Dev at lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-dev
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev





More information about the asterisk-dev mailing list