-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
856 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# Common cmake buil directories | ||
/bin/ | ||
/bin-*/ | ||
/build/ | ||
/build-*/ | ||
|
||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
cmake_minimum_required (VERSION 2.6) | ||
project (SctpCat) | ||
set (SctpCat_VERSION_MAJOR 1) | ||
set (SctpCat_VERSION_MINOR 1) | ||
|
||
configure_file ( | ||
"${PROJECT_SOURCE_DIR}/sctpcat_config.h.in" | ||
"${PROJECT_BINARY_DIR}/sctpcat_config.h" | ||
) | ||
include_directories ("${PROJECT_BINARY_DIR}") | ||
add_definitions("-DHAVE_SCTPCAT_CONFIG_H") | ||
|
||
set (SctpCat_SOURCES | ||
addrinfo.cpp | ||
sctpcat.cpp | ||
util.cpp | ||
) | ||
|
||
add_executable (sctpcat ${SctpCat_SOURCES}) | ||
|
||
target_link_libraries(sctpcat boost_program_options boost_thread) | ||
target_link_libraries(sctpcat sctp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "addrinfo.hpp" | ||
#include "exception.hpp" | ||
#include <iostream> | ||
|
||
namespace | ||
{ | ||
void addrinfoDeleter(addrinfo* ptr) | ||
{ | ||
if (ptr) | ||
{ | ||
freeaddrinfo(ptr); | ||
} | ||
} | ||
} | ||
|
||
boost::shared_ptr<addrinfo> getAi(int aiFamily, const std::string &port, const std::string& host, bool doListen) | ||
{ | ||
addrinfo* res = NULL; | ||
addrinfo hint; | ||
memset(&hint, 0, sizeof(hint)); | ||
hint.ai_family = aiFamily; | ||
if (doListen) | ||
{ | ||
hint.ai_flags = AI_PASSIVE; | ||
} | ||
std::cout << "getaddrinfo " << host << " : " << port << "\n"; | ||
if (getaddrinfo(host.empty() ? NULL : host.c_str(), | ||
port.empty() ? NULL : port.c_str(), &hint, &res) == -1) | ||
{ | ||
SCTPCAT_THROW(SctpCatError()) << clib_failure("getaddrinfo", errno); | ||
} | ||
if (!res) | ||
{ | ||
SCTPCAT_THROW(SctpCatError()) << clib_failure("getaddrinfo", errno); | ||
} | ||
std::cerr << "family " << res->ai_family << "\n"; | ||
std::cerr << "next is " << (void*) res->ai_next << "\n"; | ||
boost::shared_ptr<addrinfo> ai(res, addrinfoDeleter); | ||
return ai; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef ADDRINFO_HPP | ||
#define ADDRINFO_HPP | ||
|
||
#include <netdb.h> | ||
#include <string> | ||
#include <boost/shared_ptr.hpp> | ||
|
||
boost::shared_ptr<addrinfo> getAi(int ai_family, const std::string &port, const std::string& host, bool doListen); | ||
|
||
boost::shared_ptr<addrinfo> getAnyAddr(int ai_family); | ||
|
||
#endif // ADDRINFO_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef SCTPCAT_EXCEPTION_HPP | ||
#define SCTPCAT_EXCEPTION_HPP | ||
|
||
#include <boost/exception/all.hpp> | ||
|
||
typedef boost::tuple<boost::errinfo_api_function,boost::errinfo_errno> clib_failure; | ||
typedef boost::error_info<struct tag_sa_family, sa_family_t> sa_family_info; | ||
typedef boost::error_info<struct tag_recv_error_info, const char*> recv_error_info; | ||
|
||
struct SctpCatError : virtual boost::exception, virtual std::exception {}; | ||
struct SctpReceiveError : virtual SctpCatError {}; | ||
|
||
#define SCTPCAT_THROW(e) \ | ||
throw (e) << ::boost::throw_function(BOOST_CURRENT_FUNCTION) <<\ | ||
::boost::throw_file(__FILE__) <<\ | ||
::boost::throw_line((int)__LINE__) | ||
|
||
#endif // SCTPCAT_EXCEPTION_HPP |
Oops, something went wrong.