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