Skip to content

Commit

Permalink
change rule enclosing chars for netcap
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlf committed Dec 20, 2023
1 parent 613c833 commit 7964946
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions share/doc/man/gpac.1
Expand Up @@ -896,7 +896,7 @@ set packet capture and filtering rules formatted as [CFG][RULES]. Each -netcap a
.br
* nrt: disable real-time playback
.br
[RULES] is an optional list of {OPT,OPT2...} with OPT in:
[RULES] is an optional list of [OPT,OPT2...] with OPT in:
.br
* m=N: set rule mode - N can be r for reception only (default), w for send only or rw for both
.br
Expand Down Expand Up @@ -940,7 +940,7 @@ This will read packets from dump.gpc only for session1.sdp and let session2.sdp
.br
Example
.br
{p=1234,s=100,n=20}{r=200,s=500,o=10,v=FE}
-netcap=[p=1234,s=100,n=20][r=200,s=500,o=10,v=FE]
.br

.br
Expand Down
5 changes: 3 additions & 2 deletions src/utils/os_config_init.c
Expand Up @@ -1418,7 +1418,7 @@ GF_GPACArg GPAC_Args[] = {
"- dst=F: output packets to `F` (no pcap/pcapng support), cannot be set if src is set\n"
"- loop[=N]: loop capture file N times, or forever if N is not set or negative\n"
"- nrt: disable real-time playback\n"
"[RULES] is an optional list of `{OPT,OPT2...}` with OPT in:\n"
"[RULES] is an optional list of `[OPT,OPT2...]` with OPT in:\n"
"- m=N: set rule mode - `N` can be `r` for reception only (default), `w` for send only or `rw` for both\n"
"- s=N: set packet start range to `N`\n"
"- e=N: set packet end range to `N` (only used for `r` and `f` rules)\n"
Expand All @@ -1432,7 +1432,7 @@ GF_GPACArg GPAC_Args[] = {
"This will record packets to dump.gpc\n"
"\nEX -netcap=src=dump.gpc,id=NC1 -i session1.sdp:NCID=NC1 -i session2.sdp\n"
"This will read packets from dump.gpc only for session1.sdp and let session2.sdp use regular sockets\n"
"\nEX -netcap={p=1234,s=100,n=20}{r=200,s=500,o=10,v=FE}\n"
"\nEX -netcap=[p=1234,s=100,n=20][r=200,s=500,o=10,v=FE]\n"
"This will use regular network interface and drop packets 100 to 119 on port 1234 and patch one random packet every 200 starting from packet 500, setting byte 10 to FE", NULL, NULL, GF_ARG_STRING, GF_ARG_HINT_EXPERT|GF_ARG_SUBSYS_CORE),
#endif

Expand Down Expand Up @@ -2118,6 +2118,7 @@ void gf_sys_format_help(FILE *helpout, GF_SysPrintArgFlags flags, const char *fm
line_pos=0;
continue;
}
if (!line[0]) flags &= ~GF_PRINTARG_HIGHLIGHT_FIRST;

if ((line[0]=='#') && (line[1]==' ')) {
if (!gen_doc)
Expand Down
12 changes: 6 additions & 6 deletions src/utils/os_net.c
Expand Up @@ -1181,7 +1181,7 @@ GF_Err gf_netcap_setup(char *rules)
char *dst=NULL;
s32 cap_loop=0;
Bool cap_rt=GF_TRUE;
char *rsep = strchr(rules, '{');
char *rsep = strchr(rules, '[');
if (rsep) rsep[0] = 0;
//extract src or dst, nrt flag and loop flag
while (rules) {
Expand All @@ -1206,10 +1206,10 @@ GF_Err gf_netcap_setup(char *rules)
}
sep[0] = ',';
rules = sep+1;
if (rules[0]=='{') break;
if (rules[0]=='[') break;
}
if (rsep) {
rsep[0] = '{';
rsep[0] = '[';
rules = rsep;
}
if (!dst && !src && !rules) {
Expand Down Expand Up @@ -1271,9 +1271,9 @@ GF_Err gf_netcap_setup(char *rules)
s32 patch_val=-1;
u32 rand_every = 0;
char *rule_str;
char *sep = strchr(rules, '{');
char *sep = strchr(rules, '[');
if (!sep) break;
sep = strchr(sep+1, '}');
sep = strchr(sep+1, ']');
if (!sep) break;

sep[0] = 0;
Expand Down Expand Up @@ -1340,7 +1340,7 @@ GF_Err gf_netcap_setup(char *rules)
rule->nb_pck = num_pck;

gf_list_add(nf->rules, rule);
sep[0] = '}';
sep[0] = ']';
rules = sep+1;
}
nf->nb_rules = gf_list_count(nf->rules);
Expand Down

0 comments on commit 7964946

Please sign in to comment.