summaryrefslogtreecommitdiff
path: root/example/sample.c
blob: f5867592df534652518ec6ff8e2ae7250c6c03ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
#include "osfp.h" 
 
char iph[] = { 
  0x45, 0x00, 0x00, 0x34, 0x51, 0xc4, 0x40, 0x00, 
  0x80, 0x06, 0xe7, 0x27, 0xc0, 0xa8, 0x73, 0x08, 
  0x6a, 0xb9, 0x23, 0x6e 
}; 
 
char tcph[] = { 
  0xc1, 0xbd, 0x00, 0x50, 0x3d, 0x58, 0x51, 0x60, 
  0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x20, 0x00, 
  0x3d, 0x3a, 0x00, 0x00, 0x02, 0x04, 0x04, 0xec, 
  0x01, 0x03, 0x03, 0x08, 0x01, 0x01, 0x04, 0x02 
};  
 
int main(int argc, char **argv) 
{ 
    const char *json_file_path = "./fp.json";
    char *detail_json;
 
    struct iphdr *l3_hdr = (struct iphdr *)iph; 
    struct tcphdr *l4_hdr = (struct tcphdr *)tcph; 
    size_t l4_hdr_len = sizeof(tcph); 
 
    struct osfp_db *db = osfp_db_new(json_file_path); 
    if (db) {
        struct osfp_result *result = osfp_ipv4_identify(db, l3_hdr, l4_hdr, l4_hdr_len); 
        if (result) { 
            printf("likely os: %s\n", osfp_result_os_name_get(result)); 
            detail_json = osfp_result_score_detail_export(result);
            printf("details: \n%s\n", detail_json); 
            free(detail_json);
            osfp_result_free(result);
        } 
        osfp_db_free(db); 
    }
}