Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
ilor committed Oct 24, 2012
1 parent 77f26b2 commit 49d6ed2
Show file tree
Hide file tree
Showing 9 changed files with 856 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
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
Expand Down
22 changes: 22 additions & 0 deletions CMakeLists.txt
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)
40 changes: 40 additions & 0 deletions addrinfo.cpp
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;
}
12 changes: 12 additions & 0 deletions addrinfo.hpp
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
18 changes: 18 additions & 0 deletions exception.hpp
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
Loading

0 comments on commit 49d6ed2

Please sign in to comment.