Skip to content
Snippets Groups Projects
Commit a5da339b authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#2623] Add client method to resolve interface address from interface name

parent ea17dd19
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,17 @@ ...@@ -31,6 +31,17 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/if.h>
GHashTable * ip2ip_profile=NULL; GHashTable * ip2ip_profile=NULL;
void void
...@@ -1305,7 +1316,6 @@ void sflphone_save_history (void) ...@@ -1305,7 +1316,6 @@ void sflphone_save_history (void)
void void
sflphone_srtp_sdes_on(callable_obj_t * c) sflphone_srtp_sdes_on(callable_obj_t * c)
{ {
DEBUG("*************** Srtp SDES ON *************");
c->_srtp_state = SRTP_STATE_SDES_SUCCESS; c->_srtp_state = SRTP_STATE_SDES_SUCCESS;
...@@ -1403,3 +1413,39 @@ sflphone_call_state_changed( callable_obj_t * c, const gchar * description, cons ...@@ -1403,3 +1413,39 @@ sflphone_call_state_changed( callable_obj_t * c, const gchar * description, cons
calltree_update_call(current_calls, c, NULL); calltree_update_call(current_calls, c, NULL);
update_actions(); update_actions();
} }
void sflphone_get_interface_addr_from_name(char *iface_name) {
struct ifreq ifr;
int fd;
int err;
static char iface_addr[18];
char *tmp_addr;
struct sockaddr_in *saddr_in;
struct in_addr *addr_in;
if((fd = socket (AF_INET, SOCK_DGRAM,0)) < 0)
DEBUG("getInterfaceAddrFromName error could not open socket\n");
memset (&ifr, 0, sizeof (struct ifreq));
strcpy (ifr.ifr_name, iface_name);
ifr.ifr_addr.sa_family = AF_INET;
if((err = ioctl(fd, SIOCGIFADDR, &ifr)) < 0)
DEBUG("getInterfaceAddrFromName use default interface (0.0.0.0)\n");
saddr_in = (struct sockaddr_in *)&ifr.ifr_addr;
addr_in = &(saddr_in->sin_addr);
tmp_addr = (char *)addr_in;
snprintf(iface_addr, sizeof(iface_addr), "%d.%d.%d.%d",
UC(tmp_addr[0]), UC(tmp_addr[1]), UC(tmp_addr[2]), UC(tmp_addr[3]));
printf("************************************* %s ****************************\n", iface_addr);
}
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include <errors.h> #include <errors.h>
#include <conference_obj.h> #include <conference_obj.h>
#define UC(b) (((int)b)&0xff)
/** @file actions.h /** @file actions.h
* @brief General functions that change the state of the application. * @brief General functions that change the state of the application.
* All of these functions are called when dbus signals are triggered. Exceptions * All of these functions are called when dbus signals are triggered. Exceptions
...@@ -284,5 +286,8 @@ void sflphone_request_go_clear(void); ...@@ -284,5 +286,8 @@ void sflphone_request_go_clear(void);
*/ */
void sflphone_call_state_changed(callable_obj_t * c, const gchar * description, const guint code); void sflphone_call_state_changed(callable_obj_t * c, const gchar * description, const guint code);
/**
* Resolve an interface address given its name
*/
void sflphone_get_interface_addr_from_name(char *iface_name);
#endif #endif
...@@ -566,6 +566,7 @@ static local_interface_changed_cb(GtkWidget * widget, gpointer data UNUSED) { ...@@ -566,6 +566,7 @@ static local_interface_changed_cb(GtkWidget * widget, gpointer data UNUSED) {
gchar *local_address; gchar *local_address;
local_interface = (gchar *) gtk_combo_box_get_active_text (GTK_COMBO_BOX (localAddressCombo)); local_interface = (gchar *) gtk_combo_box_get_active_text (GTK_COMBO_BOX (localAddressCombo));
// sflphone_get_interface_addr_from_name((char *)local_interface);
local_address = dbus_get_address_from_interface_name (local_interface); local_address = dbus_get_address_from_interface_name (local_interface);
gtk_entry_set_text (GTK_ENTRY(publishedAddressEntry), local_address); gtk_entry_set_text (GTK_ENTRY(publishedAddressEntry), local_address);
...@@ -646,6 +647,7 @@ static same_as_local_cb(GtkWidget * widget, gpointer data UNUSED) ...@@ -646,6 +647,7 @@ static same_as_local_cb(GtkWidget * widget, gpointer data UNUSED)
gchar * local_address; gchar * local_address;
local_interface = (gchar *) gtk_combo_box_get_active_text(GTK_COMBO_BOX(localAddressCombo)); local_interface = (gchar *) gtk_combo_box_get_active_text(GTK_COMBO_BOX(localAddressCombo));
// sflphone_get_interface_addr_from_name((char *)local_interface);
local_address = dbus_get_address_from_interface_name(local_interface); local_address = dbus_get_address_from_interface_name(local_interface);
gtk_entry_set_text(GTK_ENTRY(publishedAddressEntry), local_address); gtk_entry_set_text(GTK_ENTRY(publishedAddressEntry), local_address);
......
...@@ -396,8 +396,6 @@ std::string SIPVoIPLink::getInterfaceAddrFromName(std::string ifaceName) { ...@@ -396,8 +396,6 @@ std::string SIPVoIPLink::getInterfaceAddrFromName(std::string ifaceName) {
if((err = ioctl(fd, SIOCGIFADDR, &ifr)) < 0) if((err = ioctl(fd, SIOCGIFADDR, &ifr)) < 0)
_debug("getInterfaceAddrFromName use default interface (0.0.0.0)\n"); _debug("getInterfaceAddrFromName use default interface (0.0.0.0)\n");
// printf("Local address: %s\n", inet_ntos( ((struct sockaddr_in *) &ifr.ifr_ifru.ifru_addr)->sin_addr ));
saddr_in = (struct sockaddr_in *)&ifr.ifr_addr; saddr_in = (struct sockaddr_in *)&ifr.ifr_addr;
addr_in = &(saddr_in->sin_addr); addr_in = &(saddr_in->sin_addr);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment