[sr-dev] git:master:cd6d509d: core: compare parsed ipv6 addresses in ipv6_get_netif_scope()
Daniel-Constantin Mierla
miconda at gmail.com
Wed Apr 24 11:34:41 CEST 2019
Module: kamailio
Branch: master
Commit: cd6d509d4030143364a50971870d02ffdc83c175
URL: https://github.com/kamailio/kamailio/commit/cd6d509d4030143364a50971870d02ffdc83c175
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2019-04-24T11:33:53+02:00
core: compare parsed ipv6 addresses in ipv6_get_netif_scope()
---
Modified: src/core/socket_info.c
Modified: src/core/socket_info.h
---
Diff: https://github.com/kamailio/kamailio/commit/cd6d509d4030143364a50971870d02ffdc83c175.diff
Patch: https://github.com/kamailio/kamailio/commit/cd6d509d4030143364a50971870d02ffdc83c175.patch
---
diff --git a/src/core/socket_info.c b/src/core/socket_info.c
index c77e4b8227..4ed7b56487 100644
--- a/src/core/socket_info.c
+++ b/src/core/socket_info.c
@@ -105,7 +105,7 @@
* return the scope for IPv6 interface matching the ipval parameter
* - needed for binding to link local IPv6 addresses
*/
-unsigned int ipv6_get_netif_scope(const char *ipval)
+unsigned int ipv6_get_netif_scope(char *ipval)
{
struct ifaddrs *netiflist = NULL;
struct ifaddrs *netif = NULL;
@@ -113,6 +113,20 @@ unsigned int ipv6_get_netif_scope(const char *ipval)
unsigned int iscope = 0;
int i = 0;
int r = 0;
+ ip_addr_t *ipa = NULL;
+ ip_addr_t vaddr;
+ str ips;
+
+ ips.s = ipval;
+ ips.len = strlen(ipval);
+
+ ipa = str2ip6(&ips);
+ if(ipa==NULL) {
+ LM_ERR("could not parse ipv6 address: %s\n", ipval);
+ return 0;
+ }
+ memcpy(&vaddr, ipa, sizeof(ip_addr_t));
+ ipa = NULL;
/* walk over the list of all network interface addresses */
if(getifaddrs(&netiflist)!=0) {
@@ -136,10 +150,15 @@ unsigned int ipv6_get_netif_scope(const char *ipval)
break;
}
}
- /* if the ips matche, get scope index from interface name */
- if(strcmp(ipaddr, ipval)==0){
- iscope=if_nametoindex(netif->ifa_name);
- goto done;
+ ips.s = ipaddr;
+ ips.len = strlen(ipaddr);
+ ipa = str2ip6(&ips);
+ if(ipa!=NULL) {
+ /* if the ips match, get scope index from interface name */
+ if(ip_addr_cmp(&vaddr, ipa)) {
+ iscope=if_nametoindex(netif->ifa_name);
+ goto done;
+ }
}
}
}
diff --git a/src/core/socket_info.h b/src/core/socket_info.h
index e8c684407c..37bfd897f1 100644
--- a/src/core/socket_info.h
+++ b/src/core/socket_info.h
@@ -151,6 +151,6 @@ typedef struct _sr_phostp {
struct socket_info* lookup_local_socket(str *phostp);
int parse_protohostport(str* ins, sr_phostp_t *r);
-unsigned int ipv6_get_netif_scope(const char *ipval);
+unsigned int ipv6_get_netif_scope(char *ipval);
#endif
More information about the sr-dev
mailing list