Skip to content

Commit

Permalink
Added npcap_helpers passthrough to API (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianReimold authored Apr 5, 2024
1 parent f2e7c90 commit 5f511fb
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ecaludp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ set(sources
###############################################
if(ECALUDP_ENABLE_NPCAP)
list(APPEND includes
include_with_udpcap/ecaludp/npcap_helpers.h
include_with_udpcap/ecaludp/socket_npcap.h
)

list(APPEND sources
src/socket_npcap.cpp
src/async_udpcap_socket.cpp
src/async_udpcap_socket.h
src/npcap_helpers.cpp
src/socket_npcap.cpp
)
endif()

Expand Down
59 changes: 59 additions & 0 deletions ecaludp/include_with_udpcap/ecaludp/npcap_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/********************************************************************************
* Copyright (c) 2024 Continental Corporation
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#pragma once

#include <string>

// IWYU pragma: begin_exports
#include <ecaludp/ecaludp_export.h>
// IWYU pragma: end_exports

namespace ecaludp
{
namespace npcap
{
/**
* @brief Initializes Npcap, if not done already. Must be called before calling any native npcap methods.
*
* This method initialized Npcap and must be called at least once before
* calling any ncap functions.
* As it always returns true when npcap has been intialized successfully, it
* can also be used to check whether npcap is available and working properly.
*
* If this function returns true, npcap should work.
*
* @return True if npcap is working
*/
ECALUDP_EXPORT bool initialize();

/**
* @brief Checks whether npcap has been initialized successfully
* @return true if npcap has been initialized successfully
*/
ECALUDP_EXPORT bool is_initialized();

/**
* @brief Returns a human readible status message.
*
* This message is intended to be displayed in a graphical user interface.
* For terminal based applications it is not needed, as the messages are also
* printed to stderr.
*
* @return The Udpcap status as human-readible text (may be multi-line)
*/
ECALUDP_EXPORT std::string get_human_readable_error_text();
}
}
34 changes: 34 additions & 0 deletions ecaludp/src/npcap_helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/********************************************************************************
* Copyright (c) 2024 Continental Corporation
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#pragma once

#include <ecaludp/npcap_helpers.h>

#include <string>

#include <udpcap/npcap_helpers.h>

namespace ecaludp
{
namespace npcap
{
bool initialize() { return Udpcap::Initialize(); }

bool is_initialized() { return Udpcap::IsInitialized(); }

std::string get_human_readable_error_text() { return Udpcap::GetHumanReadibleErrorText(); }
}
}
4 changes: 4 additions & 0 deletions samples/integration_test_npcap/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@

#include <asio.hpp>
#include <ecaludp/socket_npcap.h>
#include <ecaludp/npcap_helpers.h>

#include <thread>

int main()
{
// Initialize npcap explicitely
ecaludp::npcap::initialize();

// Create a socket
ecaludp::SocketNpcap socket({'E', 'C', 'A', 'L'});

Expand Down

0 comments on commit 5f511fb

Please sign in to comment.