You've not reduced your code to an an SSCCE (Short, Self-Contained, Correct Example) so we can't tell what you're doing wrong. However, it is most likely that the data you think has two carriage returns actually doesn't contain the two adjacent carriage returns. However, only some sort of hex dump or something similar will show that for sure.
Here's an SSCCE which shows that your code can work if given the correct data:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *examples[] =
{
"YYYYGET / HTTP/1.0\r\nExample 1 Single CRLF",
"YYYYGET / HTTP/1.0\r\n\r\nExample 2 Double CRLF",
"YYYYGET / HTTP/1.0\r\r\nExample 3 Double CR",
"YYYYGET / HTTP/1.0\n\nExample 4 Double NL",
};
for (int i = 0; i < 4; i++)
{
char *recBuff = examples[i];
printf("Data:\n%s\n", recBuff);
if (strstr(recBuff, "GET / HTTP/1.0\r\n\r\n") != NULL)
printf("Option 1 - double CRLF\n");
else if (strstr(recBuff, "GET / HTTP/1.0\r\r") != NULL)
printf("Option 2 - double CR\n");
else if (strstr(recBuff, "GET / HTTP/1.0\r\n") != NULL)
printf("Option 3 - single CRLF\n");
else
printf("Option 4 - no match\n");
}
return 0;
}
Sample output
$ ./counter-example
Data:
YYYYGET / HTTP/1.0
Example 1 Single CRLF
Option 3 - single CRLF
Data:
YYYYGET / HTTP/1.0
Example 2 Double CRLF
Option 1 - double CRLF
Data:
YYYYGET / HTTP/1.0
Example 3 Double CR
Option 2 - double CR
Data:
YYYYGET / HTTP/1.0
Example 4 Double NL
Option 4 - no match
$
So, if you are not seeing something similar with your code, you aren't getting the data you thought you were getting.
The YYYY
part is not necessary to the reproduction; neither is the Example n
information. The trailing part makes sure the fairly difficult to discriminate strings are recognizable; the YYYY
is arguably fluff since the HTTP protocol would not start with such garbage.