MCPcopy Create free account
hub / github.com/amule-project/amule / ScanIP

Function ScanIP

src/IPFilterScanner.cpp:865–887  ·  view source on GitHub ↗

When we get here the IP has been lexed nicely, so we can blaze through without any checks. The total lexing time is more than twice as fast with this than when using sscanf.

Source from the content-addressed store, hash-verified

863// The total lexing time is more than twice as fast
864// with this than when using sscanf.
865static bool ScanIP(const char * buf, uint32 & ip)
866{
867 while (*buf < '0') {
868 buf++; // skip whitespace
869 }
870 ip = 0;
871 int a = 0;
872 for (int i = 0; i < 4; buf++) {
873 if (*buf < '0' || *buf > '9') {
874 // finished a number, check it and add to the ip
875 if (a > 255) {
876 return false;
877 }
878 ip = (ip << 8) | a;
879 a = 0;
880 i++;
881 } else {
882 // build number
883 a = a * 10 + *buf - '0';
884 }
885 }
886 return true;
887}
888
889static bool ScanInt(const char * buf, uint32 & a)
890{

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected