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 <dlstev...@us.ibm.com>

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.


------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Openslp-devel mailing list
Openslp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openslp-devel

Reply via email to