1 #include "Multicast_Manager.h"
2 #include "ace/Mem_Map.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/OS_NS_string.h"
5 #include "ace/OS_NS_arpa_inet.h"
6 #include "ace/OS_NS_netdb.h"
7 #include "ace/OS_Memory.h"
8 #include "ace/OS_NS_ctype.h"
10 // Initialize all the static member vars.
11 int Multicast_Manager::received_host_count
= 0;
12 Host_Elem
*Multicast_Manager::drwho_list
= 0;
13 Host_Elem
*Multicast_Manager::current_ptr
= 0;
15 // Names of hosts to query for friend info.
16 const char *Multicast_Manager::host_names
[] =
19 0 // The NULL entry...
23 Multicast_Manager::insert_default_hosts ()
25 // Enter the static list of hosts into the dynamic table!
27 for (const char **np
= host_names
;
30 Multicast_Manager::add_host (*np
);
33 // Inserts all the names in FILENAME into the list of hosts to
37 Multicast_Manager::insert_hosts_from_file (const char *filename
)
39 //FUZZ: disable check_for_lack_ACE_OS
40 ACE_Mem_Map
mmap (filename
);
41 //FUZZ: enable check_for_lack_ACE_OS
43 char *host_ptr
= (char *) mmap
.addr ();
49 for (char *end_ptr
= host_ptr
+ mmap
.size ();
53 Multicast_Manager::add_host (host_ptr
);
55 while (*host_ptr
!= '\n')
65 // Returns the IP host address for the next unexamined host in the
66 // list. If no more unexamined hosts remain a 0 is returned, else a
70 Multicast_Manager::get_next_host_addr (in_addr
&host_addr
)
72 for (Multicast_Manager::current_ptr
= Multicast_Manager::current_ptr
== 0 ? Multicast_Manager::drwho_list
: Multicast_Manager::current_ptr
->next
;
74 Multicast_Manager::current_ptr
!= 0;
75 Multicast_Manager::current_ptr
= Multicast_Manager::current_ptr
->next
)
77 const char *host_name
= Multicast_Manager::current_ptr
->host_name
;
78 hostent
*hp
= Multicast_Manager::get_host_entry (host_name
);
83 "%s: host unknown.\n",
88 Multicast_Manager::received_host_count
++;
89 ACE_OS::memcpy (&host_addr
,
92 ACE_OS::memcpy (&Multicast_Manager::current_ptr
->host_addr
,
101 // This function attempts to get the internet address for either a
102 // hostname or hostnumber. The function makes the simplifying
103 // assumption that hostnames begin with an alphabetic character!
106 Multicast_Manager::get_host_entry (const char *host
)
108 static hostent host_entry
;
111 if (ACE_OS::ace_isdigit (*host
)) // IP address.
113 u_long ia
= ACE_OS::inet_addr (host
);
115 if (ia
== (u_long
) -1)
118 hp
= ACE_OS::gethostbyaddr ((char *) &ia
,
124 hp
= ACE_OS::gethostbyname (host
);
127 return hp
== 0 ? 0 : (hostent
*) ACE_OS::memcpy (&host_entry
, hp
, sizeof *hp
);
130 // Adds an additional new host to the list of host machines.
133 Multicast_Manager::add_host (const char *host_name
)
135 ACE_NEW (Multicast_Manager::drwho_list
,
136 Host_Elem (host_name
,
137 Multicast_Manager::drwho_list
));
141 Multicast_Manager::checkoff_host (in_addr host_addr
)
143 for (Host_Elem
*tmp
= Multicast_Manager::drwho_list
;
146 if (ACE_OS::memcmp (&tmp
->host_addr
.s_addr
,
148 sizeof host_addr
.s_addr
) == 0)
150 tmp
->checked_off
= 1;
151 Multicast_Manager::received_host_count
--;
157 Multicast_Manager::get_next_non_responding_host (const char *&host_name
)
159 for (Multicast_Manager::current_ptr
= Multicast_Manager::current_ptr
== 0 ? Multicast_Manager::drwho_list
: Multicast_Manager::current_ptr
->next
;
160 Multicast_Manager::current_ptr
!= 0;
161 Multicast_Manager::current_ptr
= Multicast_Manager::current_ptr
->next
)
162 if (Multicast_Manager::current_ptr
->checked_off
== 0)
164 host_name
= Multicast_Manager::current_ptr
->host_name
;
171 Host_Elem::Host_Elem (const char *h_name
,
173 : host_name (h_name
),
180 Multicast_Manager::outstanding_hosts_remain ()
182 return Multicast_Manager::received_host_count
> 0;