[Asterisk-Dev] how does asterisk choose which network interface
tobind with?
Liang Huang
huangl at parawireless.com
Mon Mar 7 18:02:07 MST 2005
Race Vanderdecken wrote:
>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
>
I checked the hostname of the server, it was set to "(none)".....I have
to manully set it to its IP "192.168.1.153".
Well, SIP module can be bind to all available addresses now instead of
an specified IP "192.168.1.153", but it still can't get any SIP messages
from clients.
>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?
>
>
Yes, ICMP service is provided by the server on which my SIP client is
running
>
>2. Can you http with a browser to the phone?
> Http://ip.adress.of.phone
>
Yes, httpd service is provided by the server on which my SIP client is
running.
And no firewall is set on both server side and client side.
>
>3.
>Have you run tcpdump?
>
>#> tcpdump -X -s0 host (ipaddress of phone )
>
>
Nope, I will try this one later today.
>
>This will give you the low level conversation between the phone and
>asterisk.
>
Thanks a lot!!!
>
>Race "The Tyrant" Vanderdecken
>
>
>
>_______________________________________________
>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
>
>
Best Regards,
Liang
More information about the asterisk-dev
mailing list