The best solution seems to be the Boyer–Moore string search algorithm. It's also used in the ngrep commandline tool.

http://en.wikipedia.org/wiki/Boyer%E...arch_algorithm