rfc1918_parser.rl 912 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "rfc1918_parser.h"
  2. /** Ragel machine **/
  3. %%{
  4. machine rfc1918_parser;
  5. action is_rfc1918 {
  6. is_ip_rfc1918 = 1;
  7. }
  8. DIGIT = "0".."9";
  9. dec_octet = DIGIT | ( 0x31..0x39 DIGIT ) | ( "1" DIGIT{2} ) |
  10. ( "2" 0x30..0x34 DIGIT ) | ( "25" 0x30..0x35 );
  11. RFC1918_address = ( "10." dec_octet "." dec_octet "." dec_octet ) |
  12. ( "172." ( ( "1" "6".."9" ) | ( "2" DIGIT ) | ( "3" "0".."1" ) ) "." dec_octet "." dec_octet ) |
  13. ( "192.168." dec_octet "." dec_octet );
  14. main := RFC1918_address @is_rfc1918;
  15. }%%
  16. /** Data **/
  17. %% write data;
  18. /** exec **/
  19. unsigned int rfc1918_parser_execute(const char *str, size_t len)
  20. {
  21. int cs = 0;
  22. const char *p, *pe;
  23. unsigned int is_ip_rfc1918 = 0;
  24. p = str;
  25. pe = str+len;
  26. %% write init;
  27. %% write exec;
  28. return is_ip_rfc1918;
  29. }