... use strstr
Like Horace noted, a UDP packet is binary, so it can contain NUL characters. strstr will stop looking at that byte. You have to use memmem. You can't print the packet for the same reason.
For testing, you need to define the test packet with its byte values, thoughtfully provided by Wireshark.
Then the test program is:
uint8_t packet[] =
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x22,
0x68, 0x73, 0x15, 0x3e, 0x08, 0x00, 0x45, 0x00,
0x00, 0x53, 0x30, 0xdd, 0x00, 0x00, 0x80, 0x11,
0x83, 0x3a, 0xc0, 0xa8, 0x02, 0x33, 0xc0, 0xa8,
0x02, 0xff, 0x26, 0x8f, 0x26, 0x8f, 0x00, 0x3f,
0x86, 0xd3, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53,
0x3a, 0x20, 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x2d,
0x31, 0x22, 0x20, 0x22, 0x22, 0x20, 0x30, 0x20,
0x33, 0x20, 0x30, 0x20, 0x30, 0x20, 0x37, 0x30,
0x32, 0x31, 0x30, 0x20, 0x22, 0x30, 0x22, 0x20,
0x30, 0x20, 0x22, 0x31, 0x22, 0x20, 0x20, 0x37,
0x30, 0x33, 0x35, 0x30, 0x20, 0x22, 0x22, 0xde,
0x00,
};
size_t packetLen = sizeof(packet);
const uint8_t pattern[] = "STATUS: \"";
const size_t patternLen = sizeof(pattern)-1; // don't include NUL char
void setup()
{
Serial.begin( 9600 );
Serial.println( F("dummyload test") );
uint8_t *found = (uint8_t *) memmem( packet, packetLen, pattern, patternLen );
if (found) {
size_t patternStart = (found - packet);
size_t nameStart = patternStart + patternLen;
size_t remaining = packetLen - nameStart;
size_t NAME_SIZE = 32;
char name[ NAME_SIZE ];
size_t nameLen = 0;
// Don't look at more characters than we can save.
if (remaining > NAME_SIZE-1)
remaining = NAME_SIZE-1;
while (nameLen < remaining) {
char c = (char) packet[ nameStart + nameLen ];
if (c == '"')
break;
name[ nameLen++ ] = c;
}
name[ nameLen ] = '\0'; // NUL-terminate
Serial.print( F("Found STATUS field at position ") );
Serial.println( nameStart );
Serial.print( F("STATUS field value = \"") );
Serial.print( name );
Serial.println( '\"' );
} else {
Serial.println( F("STATUS field not found") );
}
}
void loop() {}