Re: [Openslp-devel] [PATCH] simplify interface list parsing
Brought to you by:
jcalcote
|
From: John C. <joh...@gm...> - 2012-11-28 18:10:19
|
David,
Thanks for the patches. In case you haven't been following for the last
couple of weeks, we switched to a mercurial repository. The three patches
you submitted have been applied to tip of default and should be in the 2.0
release when it goes out in a week or so here.
Regards,
John
> -----Original Message-----
> From: David L Stevens [mailto:dls...@us...]
> Sent: Tuesday, November 27, 2012 10:07 AM
> To: ope...@li...
> Subject: [Openslp-devel] [PATCH] simplify interface list parsing
>
>
> This patch replaces by-hand pointer tracking while parsing comma-separated
> IP addresses with a simple loop using the POSIX standard strtok_r()
function.
>
> Signed-Off-By: David L Stevens <dls...@us...>
>
> diff --git a/common/slp_iface.c b/common/slp_iface.c index
> b512986..e1423a3 100644
> --- a/common/slp_iface.c
> +++ b/common/slp_iface.c
> @@ -737,29 +737,24 @@ int SLPIfaceGetInfo(const char * useifaces,
> SLPIfaceInfo * ifaceinfo,
>
> if (p)
> {
> - char * ep = p + strlen(p);
> - char * slider1 = p;
> - char * slider2 = p;
> + char *token, *saveptr;
> char interface[MAX_IFACE_LEN];
> int ret = 0;
>
> - while (slider1 < ep)
> + for (token = strtok_r(p, ",", &saveptr); token;
> + token = strtok_r(NULL, ",", &saveptr))
> {
> - while (*slider2 != 0 && *slider2 != ',')
> - slider2++;
> - *slider2 = 0;
> -
> - ret = SLPD_Get_Iface_From_Ip(slider1, (char *)&interface);
> + ret = SLPD_Get_Iface_From_Ip(token, (char *)&interface);
>
> if (SLPIfaceContainsAddr(useifaceslen, useifaces,
> - strlen(slider1), slider1))
> + strlen(token), token))
> {
> sockfd_t fd;
> struct sockaddr_in v4addr;
> struct sockaddr_in6 v6addr;
>
> /* check if an ipv4 address was given */
> - if (SLP_inet_pton(AF_INET, slider1, &v4addr.sin_addr) ==
1)
> + if (SLP_inet_pton(AF_INET, token, &v4addr.sin_addr) ==
> + 1)
> {
> if (SLPNetIsIPV4() && ((family == AF_INET) || (family
==
> AF_UNSPEC)))
> {
> @@ -776,7 +771,7 @@ int SLPIfaceGetInfo(const char * useifaces,
> SLPIfaceInfo * ifaceinfo,
> }
> }
> }
> - else if (SLP_inet_pton(AF_INET6, slider1,
&v6addr.sin6_addr) == 1)
> + else if (SLP_inet_pton(AF_INET6, token,
> + &v6addr.sin6_addr) == 1)
> {
> if (SLPNetIsIPV6() && ((family == AF_INET6) || (family
==
> AF_UNSPEC)))
> {
> @@ -798,7 +793,6 @@ int SLPIfaceGetInfo(const char * useifaces,
> SLPIfaceInfo * ifaceinfo,
> else
> sts = (errno = EINVAL), -1; /* not v4, not v6 */
> }
> - slider1 = ++slider2;
> }
> }
> xfree(p);
>
>
>
----------------------------------------------------------------------------
--
> 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
> Ope...@li...
> https://lists.sourceforge.net/lists/listinfo/openslp-devel
|