diff options
| author | 童宗振 <[email protected]> | 2024-05-17 12:14:14 +0000 |
|---|---|---|
| committer | 童宗振 <[email protected]> | 2024-05-17 12:14:14 +0000 |
| commit | 0f00aa537cd251ae2c7e45c88871d489ae9ffcf5 (patch) | |
| tree | f6eae280eaef7b4d71ecb1e69f7b7a70ce6bee69 /include/common.h | |
| parent | 7796d0bb8b7d4ea204869e004f6a12c49d0f3d6d (diff) | |
(TSG-21096)Special characters for bpf
Diffstat (limited to 'include/common.h')
| -rw-r--r-- | include/common.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/include/common.h b/include/common.h index 613d337..e108dda 100644 --- a/include/common.h +++ b/include/common.h @@ -94,17 +94,31 @@ static inline char * paths_combine(const char * restrict prog_absolute_path, con return resolve_path; } -static inline void backspace_remove(const char * input, char * output) +// Special character conversion adapted to geedge CM. +// unescape only for bpf. +// Full string escaping is confusing and difficult to read. +// pcap-filter support backslash (\). but no '\b' in bpf. +static inline void bpf_str_unescape_for_cm(const char * input, char * output) { int i, j; for (i = 0, j = 0; i < strlen(input) - 1; i++) { - if (input[i] == '\\' && input[i + 1] == 'b') + if (input[i] == '\\' && input[i + 1] == '\\') + { + i += 1; + output[j++] = '\\'; + } + else if (input[i] == '\\' && input[i + 1] == 'b') { i += 1; output[j++] = ' '; } + else if (input[i] == '\\' && input[i + 1] == '&') + { + i += 1; + output[j++] = '&'; + } else { output[j++] = input[i]; |
