linphone-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Linphone-developers] getsockname misbehavior in linphone 0.12.0 and


From: KUNITAKE Koichi
Subject: Re: [Linphone-developers] getsockname misbehavior in linphone 0.12.0 and 0.12.1pre3
Date: Wed, 12 Nov 2003 17:07:55 +0900

  Hello,

On Wed, 12 Nov 2003 13:13:07 +0900
KUNITAKE Koichi <address@hidden> wrote:

>>I'm trying to run linphone over ipv6 but the code for determining local 
>>IP address does not seem to be working.  With /64 addresses, getsockname 
>>is only returning the routing prefix and not the full IP address of the 
>>machine running linphone.  Has anyone else seen this?  Is there a 
>>solution available?
>
>  I'd like to fixed this problem, but I can't take time for it now.
> (I'm very sorry, I think I told same thing few month ago....)
>  I think this cause of this problem is size of structure. getsockname()
>will return IPv6 address(128bit), but size of "struct sockaddr" is not
>enough.

  I fixed this bug by following patch. But SDP is still wrong....
( linphone should use IP6 instead of IP4 in this case.)

v=0
o=kunitake 123456 654321 IN IP4 2001:240:7a:0:209:6bff:fed0:c4d5
s=A conversation
c=IN IP4 2001:240:7a:0:209:6bff:fed0:c4d5

  Umm...Should we check the address family at sdp_handler_generate_template()
instead of presetting address family to [ua->ua_family]? (It seems this is
better way than my previous code's...)
  Any comments?(If there is no comment, I'd like to new code ASAP.)

--- linphone-0.12.0/osipua/src/utils.c  2003-07-19 00:39:35.000000000 +0900
+++ linphone-0.12.0/osipua/src/utils.c  2003-11-12 17:06:23.000000000 +0900
@@ -28,7 +28,9 @@
 #include "resolver.h"
 #include "uatransaction.h"
 
-
+#ifdef INET6
+#include <sys/param.h>
+#endif
 
 
 void
@@ -351,19 +353,28 @@
 }
 
 int guess_local_address(char *address_to_reach,char **loc){
-       int s,err;
+       int err;
+       socklen_t s;
        struct addrinfo hints;
        struct addrinfo *res=NULL;
+#ifdef INET6
+       struct sockaddr_storage addr;
+#else
        struct sockaddr addr;
+#endif
        int sock;
-       
        *loc=NULL;
        
        memset(&hints,0,sizeof(hints));
+#ifdef INET6
        hints.ai_family=PF_UNSPEC;
+#else
+       hints.ai_family=AF_INET;
+#endif
        hints.ai_socktype=SOCK_DGRAM;
        //hints.ai_flags=AI_NUMERICHOST|AI_CANONNAME;
-       
+
+       // I think linphone fallback to IPv4 from IPv6 if it be needed.
        err=getaddrinfo(address_to_reach,NULL,&hints,&res);
        if (err<0){
                osip_trace(OSIP_ERROR,("Error in getaddrinfo for %s: 
%s\n",address_to_reach,gai_strerror(err)));
@@ -375,21 +386,21 @@
                return -1;
        }
        sock=socket(res->ai_family,SOCK_DGRAM,0);
-       s=1;
-       err=setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&s,sizeof(int));
+       err=setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&s,sizeof(s));
        if (err<0){
                osip_trace(OSIP_ERROR,("Error in setsockopt: 
%s\n",strerror(errno)));
+               close(sock);
                abort();
                return -1;
        }
        err=connect(sock,res->ai_addr,res->ai_addrlen);
        if (err<0) {
                osip_trace(OSIP_ERROR,("Error in connect: 
%s\n",strerror(errno)));
+               close(sock);
                abort();
                return -1;
        }
        freeaddrinfo(res);
-       res=NULL;
        s=sizeof(addr);
        err=getsockname(sock,(struct sockaddr*)&addr,&s);
        if (err<0) {
@@ -397,8 +408,8 @@
                close(sock);
                return -1;
        }
-       *loc=smalloc(30);
-       err=getnameinfo(&addr,s,*loc,30,NULL,0,NI_NUMERICHOST);
+       *loc=smalloc(MAXHOSTNAMELEN);
+       err=getnameinfo(&addr,s,*loc,MAXHOSTNAMELEN,NULL,0,NI_NUMERICHOST);
        if (err<0){
                osip_trace(OSIP_ERROR,("getnameinfo error:%s",strerror(errno)));
                abort();


Thank you,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]