diff options
| author | 祝振军 <[email protected]> | 2023-10-09 07:37:56 +0000 |
|---|---|---|
| committer | 祝振军 <[email protected]> | 2023-10-09 07:37:56 +0000 |
| commit | bb3c9ffd69eb54ac2b48e042328bcdbbe0a21048 (patch) | |
| tree | 5286c2fda94ba2de4ca64b6149ec084d4464b5ee /example/osfp_example.c | |
| parent | aa052317563d462fddfae59b392462a724b9feae (diff) | |
| parent | 1b8758ef1f41fd11315110bcb9950e551d3087db (diff) | |
Merge branch 'dev' into 'main'
Dev
See merge request zhuzhenjun/libosfp!4
Diffstat (limited to 'example/osfp_example.c')
| -rw-r--r-- | example/osfp_example.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/example/osfp_example.c b/example/osfp_example.c index e047a91..62d08df 100644 --- a/example/osfp_example.c +++ b/example/osfp_example.c @@ -442,21 +442,27 @@ void example_detect(struct osfp_db *osfp_db, Packet *p) int ret; char str_buf[1024]; //unsigned char *iph = (unsigned char *)(p->iph != NULL ? (void *)p->iph : (void *)p->ip6h); + struct iphdr *iph; + struct ipv6hdr *ip6h; struct tcphdr *tcph; unsigned int tcph_len; - struct osfp_result *result; - unsigned int os_class_flags = OSFP_OS_CLASS_FLAG_WINDOWS | OSFP_OS_CLASS_FLAG_LINUX | OSFP_OS_CLASS_FLAG_MAC_OS; + struct osfp_result *result = NULL; printf("Example ipv4 header detect: --------------------------\n"); - if (p->iph == NULL) { - goto exit; - } - + iph = (struct iphdr *)p->iph; + ip6h = (struct ipv6hdr *)p->ip6h; tcph = (struct tcphdr *)p->tcph; tcph_len = tcph->doff << 2; - result = osfp_ipv4_identify(osfp_db, p->iph, tcph, tcph_len); + if (iph) { + result = osfp_ipv4_identify(osfp_db, iph, tcph, tcph_len); + } else if (ip6h) { + result = osfp_ipv6_identify(osfp_db, ip6h, tcph, tcph_len); + } else { + goto exit; + } + if (result == NULL) { printf("osfp header match failed, erro: %s\n", "?"); goto exit; @@ -468,9 +474,10 @@ void example_detect(struct osfp_db *osfp_db, Packet *p) printf("Details:\n"); printf("%s\n", osfp_result_score_detail_export(result)); - osfp_result_free(result); - exit: + if (result) { + osfp_result_free(result); + } return; } |
