Open mateuszkobak opened 5 months ago
char hostname[60] = "[2001:aaa:aaaa:a::a]:8000";
int len;
sscanf(hostname, "[%45[0123456789abcdefABCDEF:.]]%n", hostname, &len);
printf("%s\n%d\n", hostname, len);
Howcome you need the "endbracket" variable? The code above might help
Side note: curl upstream majorly modified Curl_parse_port function
char hostname[60] = "[2001:aaa:aaaa:a::a]:8000"; int len; sscanf(hostname, "[%45[0123456789abcdefABCDEF:.]]%n", hostname, &len); printf("%s\n%d\n", hostname, len);
Howcome you need the "endbracket" variable? The code above might help
Please note that this is a reproduction code from curl
, so the intent is not to change the code but check why it fails for our implementation of sscanf
.
Regarding why the ]
is not used directly - see the original code (https://github.com/curl/curl/blob/curl-7_64_1/lib/urlapi.c#L501) - it's used to detect the zoneidx encoding (eg. [fe80::20c:29ff:fe9c:409b%eth0]:1234
(if endbracket == '%')
The following code produces a segmentation fault:
This is a reproduction of a situation in function
Curl_parse_port
incurl-7.64.1/lib/urlapi.c
.