[Openslp-devel] [PATCH] simplify/speed-up SLPD_Get_Iface_From_Ip()
Brought to you by:
jcalcote
From: David L S. <dls...@us...> - 2012-11-27 17:15:35
|
This patch simplifies SLPD_Get_Iface_From_Ip(). Instead of repeatedly calling strlen(), it uses strchr() to get interface names from IP address specifications. Signed-Off-By: David L Stevens <dls...@us...> diff --git a/common/slp_iface.c b/common/slp_iface.c index 8876873..b512986 100644 --- a/common/slp_iface.c +++ b/common/slp_iface.c @@ -675,30 +675,19 @@ int SLPIfaceGetDefaultInfo(SLPIfaceInfo* ifaceinfo, int family) */ static int SLPD_Get_Iface_From_Ip(char *ip, char *iface) { - char *ip_ptr = ip; - unsigned int i = 0; - int ret = -1; - - if(iface == NULL) - return ret; - - while(i != strlen(ip)) { - if(*ip_ptr != '%') { - ip_ptr++; - i++; - continue; - } else { - ip_ptr++; - if (strlen(ip_ptr) >= MAX_IFACE_LEN) { - break; - } else { - strcpy(iface, ip_ptr); - ret = 0; - break; - } - } - } - return ret; + char *p; + + if (iface == NULL) + return -1; + + p = strchr(ip, '%'); + if (p == NULL) + return -1; + ++p; + if (strlen(p) >= MAX_IFACE_LEN) + return -1; + (void) strcpy(iface, p); + return 0; } /** Get the network interface addresses for this host. |