00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "config.hh"
00020
00021 #ifndef QOLYESTER_ENABLE_VIRTUAL
00022
00023 # include "sys/realinterfaceinfo.hh"
00024
00025 # ifndef QOLYESTER_DAEMON_SYS_SOCKET_HH
00026 # define QOLYESTER_DAEMON_SYS_SOCKET_HH 1
00027
00028 # include <sys/types.h>
00029 # include <string>
00030
00031 # include "config.hh"
00032
00033 # include "net/ipaddress.hh"
00034 # include "utl/data.hh"
00035 # include "sch/scheduler.hh"
00036
00037 namespace olsr {
00038
00039 namespace sys {
00040
00041
00042 class Socket {
00043 typedef Socket This;
00044 enum _dummy_values { _dummy_val };
00045 Socket(_dummy_values);
00046 public:
00047
00048 typedef address_t::sockaddr_t sockaddr_t;
00049 typedef address_t addr_t;
00050 typedef u_int16_t port_t;
00051
00052
00053
00054 Socket();
00055 Socket(unsigned mtu);
00056 Socket(unsigned mtu, const addr_t& addr, port_t port);
00057 Socket(unsigned mtu, const std::string& host, port_t port);
00058 Socket(unsigned mtu, const char* host, port_t port);
00059
00060 void close();
00061
00062 unsigned mtu() const { return _mtu; }
00063
00064 void set_mtu(unsigned mtu) { _mtu = mtu; }
00065
00066 void bind_to_device(const std::string& name);
00067
00068 void set_multicast(const RealInterfaceInfo& info);
00069
00070 void bind(const sockaddr_t& sin);
00071
00072 void bind_multicast(const RealInterfaceInfo& info,
00073 const address_t& a, port_t port);
00074
00075 # if QOLYESTER_FAMILY_INET == 6
00076 void bind(const addr_t& addr, port_t port, unsigned index = 0);
00077 # else // QOLYESTER_FAMILY_INET != 6
00078 void bind(const addr_t& addr, port_t port);
00079 # endif
00080
00081 void connect(const sockaddr_t& sin);
00082
00083 void connect(const addr_t& addr, port_t port);
00084
00085 utl::Data receive(address_t& sender) const;
00086
00087 void send(const utl::ConstData& d) const;
00088
00089 void set_baddr(const address_t& a) { _baddr = a; }
00090
00091 void sendto(const utl::ConstData& d,
00092 const address_t::sockaddr_t& s) const;
00093
00094 void sendto_bcast(const utl::ConstData& d) const;
00095
00096 sch::IOEvent::p_t read_p() const;
00097 sch::IOEvent::p_t write_p() const;
00098
00099 bool operator<(const This& rhs) const;
00100
00101 static const This& dummy() { return _dummy; }
00102
00103 private:
00104
00105
00106 void init();
00107
00108 int _fd;
00109 unsigned _mtu;
00110 address_t _baddr;
00111 unsigned _index;
00112
00113 static This _dummy;
00114 };
00115
00116 }
00117
00118 }
00119
00120 # include "socket.hxx"
00121
00122 # endif // ! QOLYESTER_DAEMON_SYS_SOCKET_HH
00123
00124 #endif // ! QOLYESTER_ENABLE_VIRTUAL