00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MCSOCKET_H_
00024 #define MCSOCKET_H_
00025
00026 #include "include/utils/addr_storage.hpp"
00027 #include <time.h>
00028 #include <string>
00029 using namespace std;
00030
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #define IPV4_ALL_HOST_ADDR "224.0.0.1" //The All Hosts multicast group that contains all systems on the same network segment
00043 #define IPV4_ALL_IGMP_ROUTERS_ADDR "224.0.0.2" //The All Routers multicast group that contains all routers on the same network segment
00044 #define IPV4_ALL_SPF_ROUTER_ADDR "224.0.0.5" //The Open Shortest Path First (OSPF) AllSPFRouters address. Used to send Hello packets to all OSPF routers on a network segment
00045 #define IPV4_ALL_D_Routers_ADDR "224.0.0.6" //The OSPF AllDRouters address. Used to send OSPF routing information to OSPF designated routers on a network segment
00046 #define IPV4_RIPV2_ADDR "224.0.0.9" //The RIP version 2 group address. Used to send routing information using the RIP protocol to all RIP v2-aware routers on a network segment
00047 #define IPV4_EIGRP_ADDR "224.0.0.10" //EIGRP group address. Used to send EIGRP routing information to all EIGRP routers on a network segment
00048 #define IPV4_PIMv2_ADDR "224.0.0.13" //PIM Version 2 (Protocol Independent Multicast)
00049 #define IPV4_VRR_ADDR "224.0.0.18" //Virtual Router Redundancy Protocol
00050 #define IPV4_IS_IS_OVER_IP_19_ADDR "224.0.0.19" //IS-IS over IP
00051 #define IPV4_IS_IS_OVER_IP_20_ADDR "224.0.0.20" //IS-IS over IP
00052 #define IPV4_IS_IS_OVER_IP_21_ADDR "224.0.0.21" //IS-IS over IP
00053 #define IPV4_IGMPV3_ADDR "224.0.0.22" //IGMP Version 3 (Internet Group Management Protocol)
00054 #define IPV4_HOT_STANDBY_ROUTERV2_ADDR "224.0.0.102" //Hot Standby Router Protocol Version 2
00055 #define IPV4_MCAST_DNS_ADDR "224.0.0.251" //Multicast DNS address
00056 #define IPV4_LINK_LOCAL_MCAST_NAME_RES_ADDR "224.0.0.252" //Link-local Multicast Name Resolution address
00057 #define IPV4_NTP_ADDR "224.0.1.1" //Network Time Protocol address
00058 #define IPV4_CISCO_AUTO_RP_ANNOUNCE_ADDR "224.0.1.39" //Cisco Auto-RP-Announce address
00059 #define IPV4_CISCO_AUTO_RP_DISCOVERY_ADDR "224.0.1.40" //Cisco Auto-RP-Discovery address
00060 #define IPV4_H_323_GETEKEEPER_DISC_ADDR "224.0.1.41" //H.323 Gatekeeper discovery address
00061
00062
00063 #define IPV6_ALL_NODES_ADDR "ff02::1" //All nodes on the local network segment (equivalent to the IPv4 link-local broadcast address, 169.254.255.255)
00064 #define IPV6_ALL_LINK_LOCAL_ROUTER "ff02::2" //All routers on the link local network segment
00065 #define IPV6_ALL_SITE_LOCAL_ROUTER "ff05::2" //All routers on the site local network segment [RFC4291]
00066 #define IPV6_ALL_MLDv2_CAPABLE_ROUTERS "ff02::16" //All MLDv2-capable routers [RFC3810]
00067 #define IPV6_ALL_PIM_ROUTERS "ff02::d" //All PIM Routers
00068
00069
00070 #define MC_SCOKET_IF_CHOOSE_INIT -1
00071
00072 string ipAddrResolver(string ipAddr);
00073
00074
00075
00079 class mc_socket {
00080 protected:
00084 int m_sock;
00085
00089 int m_addrFamily;
00090
00094 int m_ifIndex;
00095
00099 bool m_own_socket;
00100
00101
00105 mc_socket(const mc_socket ©);
00106 public:
00110 mc_socket();
00111
00115 virtual ~mc_socket();
00116
00120 virtual bool create_udp_ipv4_socket();
00121
00125 virtual bool create_udp_ipv6_socket();
00126
00133 bool set_own_socket(int socket, int addr_family);
00134
00138 int get_addr_family();
00139
00144 bool bind_udp_socket(int port);
00145
00150 bool set_loop_back(bool enable);
00151
00153
00154
00155
00156
00164 bool send_packet(const char* addr, int port, string data);
00165
00174 bool send_packet(const char* addr, int port, const unsigned char* data, unsigned int data_size);
00175
00183 bool receive_packet(unsigned char* buf, int sizeOfBuf, int &sizeOfInfo);
00184
00191 bool receive_msg(struct msghdr* msg, int &sizeOfInfo);
00197 bool set_receive_timeout(long msec);
00198
00206 bool choose_if(const char* interface);
00207
00216 bool join_group(const char* addr, const char* interface);
00217
00226 bool leave_group(const char* addr, const char* interface);
00227
00231 bool is_udp_valid() {
00232 return m_sock > 0;
00233 }
00234
00238 static void test_join_leave_send();
00239
00240 };
00241
00242 #endif