Reputation: 15010
I have a lex pattern file (test.l) where I want to recognize a pattern for an IPv4 address and an IPv6 address.
Currently I use a binary pattern notation for example
src -ip of 192.168.156.203 is to be written as
1 src-ip {11000000 10101000 10011100 11001011}
where '1' is a tag that I use for classification.I want to extend this patter to include IPv4 address(dotted decimal) and IPv6 address (quad notation)
Currently my the relevant portion of my lexical analyser file (test.l) looks as below.
BINARY_PATTERN [ \t]*[ \t0-1\-\*]+[ \t]*
<S_src_ip>\{{BINARY_PATTERN}\} {
/*Some code here*/
}
I have slightly extended the code as below.
<S_dst_ip>\{{BINARY_PATTERN}\}|\{[0-255]\\.[0-255]\\.[0-255]\\.[0-255}\}
to support IPv4 addresses.Is there something wrong with the above code. Also how do I extend this to support IPV6 patterns.
I cannot compile the above code.It is showing
flex --header-file="test.h" test.l
test.l:50: bad character class
Can someone point out what is the error.
Upvotes: 0
Views: 1017
Reputation: 5018
I think I see a typo.
<S_dst_ip>\{{BINARY_PATTERN}\}|\{[0-255]\\.[0-255]\\.[0-255]\\.[0-255}\}
should be:
<S_dst_ip>\{{BINARY_PATTERN}\}|\{[0-255]\\.[0-255]\\.[0-255]\\.[0-255]\}
But to go beyond that, I don't think the character class [0-255]
will accomplish what you want. It will match a single digit, 0, 1, 2, or 5.
Upvotes: 1