Hi,
Maybe this source (on attachment) can help.
it returns the IP interface used to reach a host.
Best regards,
Paulo Pizarro
2009/10/15 <mikhail.zabal...@nokia.com>
> Hi,
>
> >-----Original Message-----
> >From: ext ggb [mailto:g...@tid.es]
> >Sent: Wednesday, October 14, 2009 7:11 PM
> >To: sofia-sip-devel@lists.sourceforge.net
> >Subject: [Sofia-sip-devel] Network interface selection for
> >sending messages
> >
> >I'm having problems with the network interface selection made by
> >sofia-sip when sending messages. My PC have 2 interfaces and
> >the stack
> >doesn't select the correct interface (I think the correct would be the
> >one the PC routing table points to for the message target).
> >
> >Somebody is facing the same problem?
>
> Yes.
>
> >Any solution?
>
> None written yet, AFAIK. A patch to make a practical interface selection
> based on the default route would be most welcome.
>
> >I'm using sofia-sip 1.12.10 under Windows Vista.
>
> Then, your change would have to be specific to Windows. So even if, for
> example, we come up with a patch using Linux rtnetlink or something like
> that, it won't immediately help you.
>
> Best regards,
> Mikhail
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Sofia-sip-devel mailing list
> Sofia-sip-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel
>
#include <string.h>
#ifdef WIN32
#include <Ws2tcpip.h>
#include <Wspiapi.h>
static int find_ip(const char *host, char *address, int size)
{
char* port_ptr = NULL;
SOCKET sock;
struct sockaddr_in local_addr;
unsigned long local_addr_len;
struct addrinfo aiHints;
struct addrinfo *addrf = NULL;
memset(&aiHints, 0, sizeof(aiHints));
aiHints.ai_family = AF_INET;
aiHints.ai_socktype = SOCK_DGRAM;
aiHints.ai_protocol = IPPROTO_UDP;
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock == INVALID_SOCKET) {
return -1;
}
port_ptr = strrstr(host, ":");
if (port_ptr)
port_ptr[0] = 0;
if (getaddrinfo(host, NULL, &aiHints, &addrf) != 0) {
closesocket(sock);
if (port_ptr)
port_ptr[0] = ':';
return -1;
}
if (port_ptr)
port_ptr[0] = ':';
if (WSAIoctl(sock,
SIO_ROUTING_INTERFACE_QUERY,
addrf->ai_addr,
addrf->ai_addrlen,
&local_addr,
sizeof(local_addr),
&local_addr_len,
NULL,
NULL) == SOCKET_ERROR) {
closesocket(sock);
freeaddrinfo(addrf);
return -1;
}
closesocket(sock);
freeaddrinfo(addrf);
local_addr.sin_family = AF_INET;
if (getnameinfo((const struct sockaddr *) &local_addr,
sizeof (struct sockaddr),
address,
size,
NULL,
0,
NI_NUMERICHOST)) {
return -1;
}
return 0;
}
#else
static int find_ip(const char *host, char *address, int size)
{
#ifdef __APPLE_CC__
int len;
#else
unsigned int len;
#endif
int sock_rt, on = 1;
struct sockaddr_in iface_out;
struct sockaddr_in remote;
memset(&remote, 0, sizeof (struct sockaddr_in));
remote.sin_family = AF_INET;
remote.sin_addr.s_addr = inet_addr (host);
remote.sin_port = htons (5060);
memset(&iface_out, 0, sizeof (iface_out));
sock_rt = socket(AF_INET, SOCK_DGRAM, 0);
if (setsockopt(sock_rt, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) == -1) {
close (sock_rt);
return -1;
}
if (connect(sock_rt, (struct sockaddr *)&remote, sizeof(struct sockaddr_in)) == -1) {
close(sock_rt);
return -1;
}
len = sizeof (iface_out);
if (getsockname(sock_rt, (struct sockaddr *)&iface_out, &len) == -1) {
close(sock_rt);
return -1;
}
close(sock_rt);
if (iface_out.sin_addr.s_addr == 0) {
return -1;
}
strncpy(address, inet_ntoa(iface_out.sin_addr), size - 1);
return 0;
}
#endif
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel