summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhuzhenjun <[email protected]>2023-10-12 15:05:58 +0800
committerzhuzhenjun <[email protected]>2023-10-12 15:36:31 +0800
commit8b8627b0d8e06cb2d1073b2e86741dad8c39d4f6 (patch)
treee41e8a5e70bc0d043f34b2a1651e026a15d54b4f
parent7e1849233b8640e6139143c99423bf71cca0b6b2 (diff)
symbol: set public symbols prefixv1.1.0rel-1.1
-rw-r--r--CMakeLists.txt16
-rw-r--r--README.md11
-rw-r--r--example/osfp_example.c16
-rw-r--r--example/sample.c14
-rw-r--r--src/MESA_osfp.c (renamed from src/osfp.c)20
-rw-r--r--src/MESA_osfp.h (renamed from src/osfp.h)16
-rw-r--r--src/osfp_common.c7
-rw-r--r--src/osfp_common.h8
-rw-r--r--src/osfp_fingerprint.c2
-rw-r--r--src/osfp_score_db.c2
-rw-r--r--src/osfp_score_db.h1
-rw-r--r--src/version.map2
-rw-r--r--test/test.c16
13 files changed, 64 insertions, 67 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a617d8d..a87bc55 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,11 +1,11 @@
cmake_minimum_required (VERSION 2.8)
-set(lib_name osfp)
+set(lib_name MESA_osfp)
project (${lib_name})
set(LIB_MAJOR_VERSION 1)
-set(LIB_MINOR_VERSION 0)
+set(LIB_MINOR_VERSION 1)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(Version)
@@ -55,17 +55,17 @@ set_target_properties(${lib_name}_static PROPERTIES OUTPUT_NAME ${lib_name})
set(CMAKE_INSTALL_PREFIX /opt/MESA)
-install(FILES src/osfp.h DESTINATION
+install(FILES src/MESA_osfp.h DESTINATION
${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT devel)
install(TARGETS ${lib_name}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARIES)
-install(FILES src/osfp.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT HEADER)
-install(FILES fp.json DESTINATION /var/lib/libosfp COMPONENT PROFILE)
+install(FILES src/MESA_osfp.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT HEADER)
+install(FILES fp.json DESTINATION /var/lib/MESA_osfp COMPONENT PROFILE)
add_executable(${lib_name}_sample example/sample.c)
target_link_libraries(${lib_name}_sample ${lib_name}_shared)
add_executable(${lib_name}_example example/osfp_example.c)
-target_link_libraries(${lib_name}_example ${lib_name}_shared)
+target_link_libraries(${lib_name}_example ${lib_name}_static)
target_link_libraries(${lib_name}_example pcap)
add_executable(${lib_name}_test test/test.c)
@@ -73,7 +73,7 @@ target_link_libraries(${lib_name}_test ${lib_name}_static)
enable_testing()
-add_test(NAME sample COMMAND osfp_sample)
-add_test(NAME test COMMAND osfp_test -f ../fp.json -t ../data.json)
+add_test(NAME sample COMMAND MESA_osfp_sample)
+add_test(NAME test COMMAND MESA_osfp_test -f ../fp.json -t ../data.json)
include(Package)
diff --git a/README.md b/README.md
index a44e37b..6936a78 100644
--- a/README.md
+++ b/README.md
@@ -7,20 +7,19 @@ Libosfp is a C library for OS fingerprinting.
```
# osfp_example depends on libpcap
yum install -y libpcap-devel
-# build and install
-./build.sh
-./package.sh
-yum install package/*.rpm
+BUILD_TYPE=Debug PACKAGE=1 ./ci/travis.sh
+yum install -y ./build/*.rpm
```
## library usage
```
-gcc -I./src example/sample.c -o sample -L./build -losfp; cat example/sample.c
+gcc -I./src example/sample.c -o sample -L./build -lMESA_osfp; cat example/sample.c
+LD_LIBRARY_PATH=${PWD}/build ./sample
```
## run example
```
# load the fingerprint file and capture on eth0, filter tcp port 8888
-osfp_example -f /var/lib/libosfp/fp.json -i eth0 "tcp port 8888"
+./build/MESA_osfp_example -f /var/lib/MESA_osfp/fp.json -i eth0 "tcp port 8888"
```
diff --git a/example/osfp_example.c b/example/osfp_example.c
index 2a53ac6..709ba4f 100644
--- a/example/osfp_example.c
+++ b/example/osfp_example.c
@@ -10,7 +10,7 @@
#include <pcap.h>
#include "osfp_common.h"
-#include "osfp.h"
+#include "MESA_osfp.h"
#include "osfp_log.h"
#include "osfp_fingerprint.h"
#include "osfp_score_db.h"
@@ -450,9 +450,9 @@ void example_detect(struct osfp_db *osfp_db, Packet *p)
osfp_profile_get_cycle(c1);
if (iph) {
- result = osfp_ipv4_identify(osfp_db, iph, tcph, tcph_len);
+ result = MESA_osfp_ipv4_identify(osfp_db, iph, tcph, tcph_len);
} else if (ip6h) {
- result = osfp_ipv6_identify(osfp_db, ip6h, tcph, tcph_len);
+ result = MESA_osfp_ipv6_identify(osfp_db, ip6h, tcph, tcph_len);
} else {
goto exit;
}
@@ -469,19 +469,19 @@ void example_detect(struct osfp_db *osfp_db, Packet *p)
result_os_count[result->likely_os_class]++;
- char *json = osfp_result_score_detail_export(result);
+ char *json = MESA_osfp_result_score_detail_export(result);
if (1) {
printf("Example ipv4 header detect: --------------------------\n");
printf("Connection info: %s:%d -> %s:%d\n", p->srcip, p->sp, p->dstip, p->dp);
- printf("Most likely os class: %s\n", osfp_result_os_name_get(result));
+ printf("Most likely os class: %s\n", MESA_osfp_result_os_name_get(result));
printf("Details:\n");
printf("%s\n", json);
}
exit:
if (result) {
- osfp_result_free(result);
+ MESA_osfp_result_free(result);
}
return;
}
@@ -670,7 +670,7 @@ int main(int argc, char *argv[])
osfp_profile_set(1);
- struct osfp_db *osfp_db = osfp_db_new(fp_file_path);
+ struct osfp_db *osfp_db = MESA_osfp_db_new(fp_file_path);
if (osfp_db == NULL) {
printf("could not create osfp context. fingerprints file: %s\n", fp_file_path);
exit(1);
@@ -686,7 +686,7 @@ int main(int argc, char *argv[])
}
// destroy osfp db
- osfp_db_free(osfp_db);
+ MESA_osfp_db_free(osfp_db);
return 0;
}
diff --git a/example/sample.c b/example/sample.c
index 6313c62..612ca2b 100644
--- a/example/sample.c
+++ b/example/sample.c
@@ -1,5 +1,5 @@
#include "stdio.h"
-#include "osfp.h"
+#include "MESA_osfp.h"
char iph[] = {
0x45, 0x00, 0x00, 0x34, 0x51, 0xc4, 0x40, 0x00,
@@ -22,14 +22,14 @@ int main(int argc, char **argv)
struct tcphdr *l4_hdr = (struct tcphdr *)tcph;
size_t l4_hdr_len = sizeof(tcph);
- struct osfp_db *db = osfp_db_new(json_file_path);
+ struct osfp_db *db = MESA_osfp_db_new(json_file_path);
if (db) {
- struct osfp_result *result = osfp_ipv4_identify(db, l3_hdr, l4_hdr, l4_hdr_len);
+ struct osfp_result *result = MESA_osfp_ipv4_identify(db, l3_hdr, l4_hdr, l4_hdr_len);
if (result) {
- printf("likely os: %s\n", osfp_result_os_name_get(result));
- printf("details: \n%s\n", osfp_result_score_detail_export(result));
- osfp_result_free(result);
+ printf("likely os: %s\n", MESA_osfp_result_os_name_get(result));
+ printf("details: \n%s\n", MESA_osfp_result_score_detail_export(result));
+ MESA_osfp_result_free(result);
}
- osfp_db_free(db);
+ MESA_osfp_db_free(db);
}
}
diff --git a/src/osfp.c b/src/MESA_osfp.c
index e822436..f88cff8 100644
--- a/src/osfp.c
+++ b/src/MESA_osfp.c
@@ -1,6 +1,6 @@
#include "osfp_common.h"
-#include "osfp.h"
+#include "MESA_osfp.h"
#include "osfp_fingerprint.h"
#include "osfp_score_db.h"
#include "osfp_log.h"
@@ -70,7 +70,7 @@ exit:
return NULL;
}
-const char *osfp_result_os_name_get(struct osfp_result *result)
+const char *MESA_osfp_result_os_name_get(struct osfp_result *result)
{
enum osfp_os_class_id os_class;
@@ -86,7 +86,7 @@ const char *osfp_result_os_name_get(struct osfp_result *result)
return osfp_os_class_id_to_name(os_class);
}
-char *osfp_result_score_detail_export(struct osfp_result *result)
+char *MESA_osfp_result_score_detail_export(struct osfp_result *result)
{
int i;
char *result_str = NULL;
@@ -150,7 +150,7 @@ exit:
return result_str;
}
-void osfp_result_free(struct osfp_result *result)
+void MESA_osfp_result_free(struct osfp_result *result)
{
if (result) {
if (result->json_str) {
@@ -160,7 +160,7 @@ void osfp_result_free(struct osfp_result *result)
}
}
-struct osfp_result *osfp_ipv4_identify(struct osfp_db *db, struct iphdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len)
+struct osfp_result *MESA_osfp_ipv4_identify(struct osfp_db *db, struct iphdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len)
{
int ret = OSFP_EINVAL;
struct osfp_fingerprint fp;
@@ -203,7 +203,7 @@ exit:
return NULL;
}
-struct osfp_result *osfp_ipv6_identify(struct osfp_db *db, struct ip6_hdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len)
+struct osfp_result *MESA_osfp_ipv6_identify(struct osfp_db *db, struct ip6_hdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len)
{
int ret = OSFP_EINVAL;
struct osfp_fingerprint fp;
@@ -234,7 +234,7 @@ exit:
return NULL;
}
-struct osfp_result *osfp_json_identify(struct osfp_db *db, const char *json_str)
+struct osfp_result *MESA_osfp_json_identify(struct osfp_db *db, const char *json_str)
{
int ret = OSFP_EINVAL;
struct osfp_fingerprint fp;
@@ -265,7 +265,7 @@ exit:
return NULL;
}
-struct osfp_db *osfp_db_new(const char *db_json_file)
+struct osfp_db *MESA_osfp_db_new(const char *db_json_file)
{
int ret;
struct osfp_db *db;
@@ -299,12 +299,12 @@ struct osfp_db *osfp_db_new(const char *db_json_file)
return db;
exit:
if (db) {
- osfp_db_free(db);
+ MESA_osfp_db_free(db);
}
return NULL;
}
-void osfp_db_free(struct osfp_db *db)
+void MESA_osfp_db_free(struct osfp_db *db)
{
if (db) {
if (db->db_json_path) {
diff --git a/src/osfp.h b/src/MESA_osfp.h
index bf01738..af62d8f 100644
--- a/src/osfp.h
+++ b/src/MESA_osfp.h
@@ -23,14 +23,14 @@ struct osfp_db;
* @param db_json_path 操作系统指纹库 JSON 文件的路径。
* @return 指向新创建的操作系统指纹库的指针。
*/
-struct osfp_db *osfp_db_new(const char *db_json_path);
+struct osfp_db *MESA_osfp_db_new(const char *db_json_path);
/**
* @brief 释放操作系统指纹库占用的内存。
*
* @param db 指向要释放的操作系统指纹库的指针。
*/
-void osfp_db_free(struct osfp_db *db);
+void MESA_osfp_db_free(struct osfp_db *db);
/**
* @brief 通过 IPv4 头部和 TCP 头部识别操作系统。
@@ -41,7 +41,7 @@ void osfp_db_free(struct osfp_db *db);
* @param l4_hdr_len TCP 头部的长度(注意:包含TCP选项部分)。
* @return 指向操作系统识别结果的指针。
*/
-struct osfp_result *osfp_ipv4_identify(struct osfp_db *db, struct iphdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len);
+struct osfp_result *MESA_osfp_ipv4_identify(struct osfp_db *db, struct iphdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len);
/**
* @brief 通过 IPv6 头部和 TCP 头部识别操作系统。
@@ -52,7 +52,7 @@ struct osfp_result *osfp_ipv4_identify(struct osfp_db *db, struct iphdr* l3_hdr,
* @param l4_hdr_len TCP 头部的长度(注意:包含TCP选项部分)。
* @return 指向操作系统识别结果的指针(注意:内存需要使用者释放)。
*/
-struct osfp_result *osfp_ipv6_identify(struct osfp_db *db, struct ip6_hdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len);
+struct osfp_result *MESA_osfp_ipv6_identify(struct osfp_db *db, struct ip6_hdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len);
/**
* @brief 通过 json 格式的指纹识别操作系统。
@@ -61,7 +61,7 @@ struct osfp_result *osfp_ipv6_identify(struct osfp_db *db, struct ip6_hdr* l3_hd
* @param json_str 指纹字符串。
* @return 指向操作系统识别结果的指针(注意:内存需要使用者释放)。
*/
-struct osfp_result *osfp_json_identify(struct osfp_db *db, const char *json_str);
+struct osfp_result *MESA_osfp_json_identify(struct osfp_db *db, const char *json_str);
/**
* @brief 获取操作系统识别结果的操作系统名称。
@@ -69,7 +69,7 @@ struct osfp_result *osfp_json_identify(struct osfp_db *db, const char *json_str)
* @param result 操作系统识别结果。
* @return 指向操作系统名称的常量字符指针(注意:这块内存将由osfp_result_free释放)。
*/
-const char *osfp_result_os_name_get(struct osfp_result *result);
+const char *MESA_osfp_result_os_name_get(struct osfp_result *result);
/**
* @brief 导出操作系统识别结果的得分详情。
@@ -77,14 +77,14 @@ const char *osfp_result_os_name_get(struct osfp_result *result);
* @param result 操作系统识别结果。
* @return 指向得分详情字符串的指针(注意:内存需要使用者释放)。
*/
-char *osfp_result_score_detail_export(struct osfp_result *result);
+char *MESA_osfp_result_score_detail_export(struct osfp_result *result);
/**
* @brief 释放操作系统识别结果占用的内存。
*
* @param result 操作系统识别结果。
*/
-void osfp_result_free(struct osfp_result *result);
+void MESA_osfp_result_free(struct osfp_result *result);
#ifdef __cplusplus
}
diff --git a/src/osfp_common.c b/src/osfp_common.c
index 53139fa..968b07d 100644
--- a/src/osfp_common.c
+++ b/src/osfp_common.c
@@ -1,6 +1,6 @@
#include "osfp_common.h"
-#include "osfp.h"
+#include "MESA_osfp.h"
unsigned int osfp_profile_enable;
@@ -19,6 +19,11 @@ struct osfp_profile_counter osfp_profile_score;
struct osfp_profile_counter osfp_profile_result_build;
struct osfp_profile_counter osfp_profile_result_export;
+const char *osfp_os_class_id_to_name(enum osfp_os_class_id os_class)
+{
+ return osfp_os_class_name[os_class];
+}
+
void osfp_profile_counter_print(struct osfp_profile_counter *profile, const char *name)
{
printf("profile %s: avg: %lu max: %lu min: %lu curr: %lu total: %lu count: %lu\n",
diff --git a/src/osfp_common.h b/src/osfp_common.h
index 4e75873..1cc686b 100644
--- a/src/osfp_common.h
+++ b/src/osfp_common.h
@@ -21,8 +21,6 @@
#include "cJSON.h"
-#include "osfp.h"
-
static inline unsigned long long osfp_rdtsc(void)
{
union {
@@ -197,10 +195,6 @@ struct osfp_db {
enum osfp_os_class_id osfp_os_class_name_to_id(char *name);
-extern const char *osfp_os_class_name[OSFP_OS_CLASS_MAX];
-static inline const char *osfp_os_class_id_to_name(enum osfp_os_class_id os_class)
-{
- return osfp_os_class_name[os_class];
-}
+const char *osfp_os_class_id_to_name(enum osfp_os_class_id os_class);
#endif
diff --git a/src/osfp_fingerprint.c b/src/osfp_fingerprint.c
index cc8a64b..52b180b 100644
--- a/src/osfp_fingerprint.c
+++ b/src/osfp_fingerprint.c
@@ -1,6 +1,6 @@
#include "osfp_common.h"
-#include "osfp.h"
+#include "MESA_osfp.h"
#include "osfp_fingerprint.h"
#include "osfp_log.h"
diff --git a/src/osfp_score_db.c b/src/osfp_score_db.c
index 5e88e21..bf6cd87 100644
--- a/src/osfp_score_db.c
+++ b/src/osfp_score_db.c
@@ -1,6 +1,6 @@
#include "osfp_common.h"
-#include "osfp.h"
+#include "MESA_osfp.h"
#include "osfp_fingerprint.h"
#include "osfp_score_db.h"
#include "osfp_log.h"
diff --git a/src/osfp_score_db.h b/src/osfp_score_db.h
index 3ee9a84..4e38cc9 100644
--- a/src/osfp_score_db.h
+++ b/src/osfp_score_db.h
@@ -1,7 +1,6 @@
#ifndef __OSFP_SCORE_DB_H__
#define __OSFP_SCORE_DB_H__
-#include "osfp.h"
#include "osfp_fingerprint.h"
#include "osfp_common.h"
diff --git a/src/version.map b/src/version.map
index 317c75d..50bf794 100644
--- a/src/version.map
+++ b/src/version.map
@@ -1,4 +1,4 @@
{
- global: osfp*;GIT_VERSION_*;
+ global: MESA_osfp*;GIT_VERSION_*;
local: *;
};
diff --git a/test/test.c b/test/test.c
index f4e4846..34b0793 100644
--- a/test/test.c
+++ b/test/test.c
@@ -6,7 +6,7 @@
#include "cJSON.h"
-#include "osfp.h"
+#include "MESA_osfp.h"
#include "osfp_fingerprint.h"
#include "osfp_score_db.h"
#include "osfp_log.h"
@@ -105,7 +105,7 @@ void test_miss_rate()
osfp_log_level_set(OSFP_LOG_LEVEL_DEBUG);
}
- struct osfp_db *osfp_db = osfp_db_new(db_file_path);
+ struct osfp_db *osfp_db = MESA_osfp_db_new(db_file_path);
if (osfp_db == NULL) {
printf("could not create osfp context. fingerprints file: %s\n", db_file_path);
exit(1);
@@ -123,7 +123,7 @@ void test_miss_rate()
const char *fp_str = cJSON_PrintUnformatted(entry);
- struct osfp_result *result = osfp_json_identify(osfp_db, fp_str);
+ struct osfp_result *result = MESA_osfp_json_identify(osfp_db, fp_str);
if (result == NULL) {
identify_failed_count++;
continue;
@@ -131,7 +131,7 @@ void test_miss_rate()
if (os_class == result->likely_os_class) {
verified_count++;
- osfp_result_free(result);
+ MESA_osfp_result_free(result);
continue;
}
@@ -145,16 +145,16 @@ void test_miss_rate()
unknown_count++;
}
- fprintf(log_file_ptr, "expect: %s, result: %s\n", os_class_json->valuestring, osfp_result_os_name_get(result));
+ fprintf(log_file_ptr, "expect: %s, result: %s\n", os_class_json->valuestring, MESA_osfp_result_os_name_get(result));
- char *result_json = osfp_result_score_detail_export(result);
+ char *result_json = MESA_osfp_result_score_detail_export(result);
if (result_json) {
fprintf(log_file_ptr, "%s\n", result_json);
} else {
fprintf(log_file_ptr, "result detail error:%p\n", result);
}
fflush(log_file_ptr);
- osfp_result_free(result);
+ MESA_osfp_result_free(result);
}
}
@@ -165,7 +165,7 @@ void test_miss_rate()
printf("details in: %s\n", LOG_FILE_PATH);
- osfp_db_free(osfp_db);
+ MESA_osfp_db_free(osfp_db);
}
int main(int argc, char **argv)