Skip to content

Commit 94004ba

Browse files
committed
first commit
0 parents  commit 94004ba

File tree

6 files changed

+468
-0
lines changed

6 files changed

+468
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cmake-build-debug
2+
build
3+
.idea
4+
.vagrant

CMakeLists.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
project(tcp-client)
3+
set(EXE_NAME tcp-client)
4+
set(CMAKE_PREFIX_PATH ${PROJECT_SOURCE_DIR}/deps/cmake)
5+
set(CMAKE_C_STANDARD 99)
6+
aux_source_directory(./src SOURCE_FILES)
7+
#优先static
8+
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
9+
10+
#数学库
11+
list(APPEND DEPS_LIB m)
12+
13+
add_executable(${EXE_NAME} ${SOURCE_FILES})
14+
15+
#多线程支持
16+
find_package(Threads REQUIRED)
17+
if (THREADS_HAVE_PTHREAD_ARG)
18+
target_compile_options(PUBLIC ${EXE_NAME} "-pthread")
19+
endif ()
20+
if (CMAKE_THREAD_LIBS_INIT)
21+
list(APPEND DEPS_LIB ${CMAKE_THREAD_LIBS_INIT})
22+
endif ()
23+
24+
find_package(FindPCAP)
25+
if (PCAP_FOUND)
26+
include_directories(${PCAP_INCLUDE_DIR})
27+
list(APPEND DEPS_LIB ${PCAP_LIBRARY})
28+
else ()
29+
message(FATAL_ERROR "libpcap not found!")
30+
endif ()
31+
find_package(FindLibNet)
32+
if (LIBNET_FOUND)
33+
include_directories(${LIBNET_INCLUDE_DIR})
34+
list(APPEND DEPS_LIB ${LIBNET_LIBRARIES})
35+
else ()
36+
message(FATAL_ERROR "libnet not found!")
37+
endif ()
38+
target_link_libraries(${EXE_NAME} ${DEPS_LIB})
39+

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*百万级TCP测试工具
2+
3+
参考《模拟百万级TCP并发》

deps/cmake/FindLibNetConfig.cmake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# - Find libnet
2+
#
3+
# -*- cmake -*-
4+
#
5+
# Find the libnet module
6+
#
7+
# LIBNET_INCLUDE_DIR - where to find libnet.h, etc.
8+
# LIBNET_LIBRARIES - List of libraries when using LibNet.
9+
# LIBNET_FOUND - True if libnet found.
10+
11+
IF (LIBNET_INCLUDE_DIR)
12+
# Already in cache, be silent
13+
SET(LIBNET_FIND_QUIETLY TRUE)
14+
ENDIF (LIBNET_INCLUDE_DIR)
15+
16+
FIND_PATH(LIBNET_INCLUDE_DIR libnet.h
17+
/usr/include
18+
)
19+
20+
SET(LIBNET_NAMES net)
21+
FIND_LIBRARY(LIBNET_LIBRARY
22+
NAMES ${LIBNET_NAMES}
23+
PATHS /usr/lib /usr/local/lib
24+
PATH_SUFFIXES libnet
25+
)
26+
27+
ADD_DEFINITIONS(-DLIBNET_LIL_ENDIAN=1)
28+
29+
IF (LIBNET_INCLUDE_DIR AND LIBNET_LIBRARY)
30+
SET(LIBNET_FOUND TRUE)
31+
SET(LIBNET_LIBRARIES ${LIBNET_LIBRARY} )
32+
33+
ELSE (LIBNET_INCLUDE_DIR AND LIBNET_LIBRARY)
34+
SET(LIBNET_FOUND FALSE)
35+
SET(LIBNET_LIBRARIES )
36+
ENDIF (LIBNET_INCLUDE_DIR AND LIBNET_LIBRARY)
37+
38+
IF (LIBNET_FOUND)
39+
IF (NOT LIBNET_FIND_QUIETLY)
40+
MESSAGE(STATUS "Found LibNet: ${LIBNET_LIBRARY}")
41+
ENDIF (NOT LIBNET_FIND_QUIETLY)
42+
ELSE (LIBNET_FOUND)
43+
IF (LIBNET_FIND_REQUIRED)
44+
MESSAGE(STATUS "Looked for LibNet libraries named ${LIBNET_NAMES}.")
45+
MESSAGE(FATAL_ERROR "Could NOT find LibNet library")
46+
ENDIF (LIBNET_FIND_REQUIRED)
47+
ENDIF (LIBNET_FOUND)
48+
49+
MARK_AS_ADVANCED(
50+
LIBNET_LIBRARY
51+
LIBNET_INCLUDE_DIR
52+
)

deps/cmake/FindPCAPConfig.cmake

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# - Try to find libpcap include dirs and libraries
2+
#
3+
# Usage of this module as follows:
4+
#
5+
# find_package(PCAP)
6+
#
7+
# Variables used by this module, they can change the default behaviour and need
8+
# to be set before calling find_package:
9+
#
10+
# PCAP_ROOT_DIR Set this variable to the root installation of
11+
# libpcap if the module has problems finding the
12+
# proper installation path.
13+
#
14+
# Variables defined by this module:
15+
#
16+
# PCAP_FOUND System has libpcap, include and library dirs found
17+
# PCAP_INCLUDE_DIR The libpcap include directories.
18+
# PCAP_LIBRARY The libpcap library (possibly includes a thread
19+
# library e.g. required by pf_ring's libpcap)
20+
# HAVE_PF_RING If a found version of libpcap supports PF_RING
21+
22+
find_path(PCAP_ROOT_DIR
23+
NAMES include/pcap.h
24+
)
25+
26+
find_path(PCAP_INCLUDE_DIR
27+
NAMES pcap.h
28+
HINTS ${PCAP_ROOT_DIR}/include
29+
)
30+
31+
find_library(PCAP_LIBRARY
32+
NAMES pcap
33+
HINTS ${PCAP_ROOT_DIR}/lib
34+
)
35+
36+
include(FindPackageHandleStandardArgs)
37+
find_package_handle_standard_args(PCAP DEFAULT_MSG
38+
PCAP_LIBRARY
39+
PCAP_INCLUDE_DIR
40+
)
41+
42+
include(CheckCSourceCompiles)
43+
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
44+
check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO)
45+
set(CMAKE_REQUIRED_LIBRARIES)
46+
47+
# check if linking against libpcap also needs to link against a thread library
48+
if (NOT PCAP_LINKS_SOLO)
49+
find_package(Threads)
50+
if (THREADS_FOUND)
51+
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
52+
check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS)
53+
set(CMAKE_REQUIRED_LIBRARIES)
54+
endif ()
55+
if (THREADS_FOUND AND PCAP_NEEDS_THREADS)
56+
set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
57+
list(REMOVE_DUPLICATES _tmp)
58+
set(PCAP_LIBRARY ${_tmp}
59+
CACHE STRING "Libraries needed to link against libpcap" FORCE)
60+
else ()
61+
message(FATAL_ERROR "Couldn't determine how to link against libpcap")
62+
endif ()
63+
endif ()
64+
65+
include(CheckFunctionExists)
66+
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
67+
check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
68+
set(CMAKE_REQUIRED_LIBRARIES)
69+
70+
mark_as_advanced(
71+
PCAP_ROOT_DIR
72+
PCAP_INCLUDE_DIR
73+
PCAP_LIBRARY
74+
)

0 commit comments

Comments
 (0)