Re: [PATCH] Fix IPv6 discovery by stripping Zone ID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 03/04/2013 06:59 PM, FUJITA Tomonori wrote:
> On Mon, 04 Mar 2013 18:34:21 -0800
> Lee Duncan <lduncan@xxxxxxxx> wrote:
> 
>>
>>
>> On 03/04/2013 06:04 PM, FUJITA Tomonori wrote:
>>> On Mon,  4 Mar 2013 15:15:57 -0800
>>> Lee Duncan <lduncan@xxxxxxxx> wrote:
>>>
>>>> This strips off the "%ZONEID" that can be at the end of IPv6
>>>
>>> 'Can' means that possibly the string doesn't exist, right? The
>>> following code works in such case?
>>
>> Yes, correct. The strsep() only puts a NULL in the string if it finds
>> any tokens from the supplied list, "%" in this case. Otherwise, the
>> string is untouched.
> 
> Hmm, looks like the man page says different
> 
> https://www.kernel.org/doc/man-pages/online/pages/man3/strsep.3.html
> 
> In case no delimiter was found, the token is taken to be the entire
> string *stringp, and *stringp is made NULL.
> 

No, that's just poorly worded. They mean that after the whole token,
which is the whole string in this case, they put a NULL. Funny, because
it had better already be a NULL!

This same code (using strsep()) is in iscsitarget, if that reassures you
in any way, but there, it is not conditional on IPv6, so it is used on
all IP addresses. That's fine, because it's a NOOP if there is no "%" in
the string, though it does waste a wee bit of time scanning the string.

Here's a little test program for your edification:

main()
{
        char str1[] = "name%eth0";
        char str2[] = "name";
        char *ptr;

        ptr = str1;
        strsep(&ptr, "%");
        printf("str1=%s\n", str1);

        ptr = str2;
        strsep(&ptr, "%");
        printf("str2=%s\n", str2);
}

Output is:

	str1=name
	str2=name


As you can see, in the second instance, where there is no "%", the
string is left intact.

-- 
Lee Duncan
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux