Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / Service_Configurator / IPC-tests / client / broadcast_client_test.cpp
blob0575e55fa0f09c6596d9fa4aa9c9933dedc75eaa
1 // Tests out the broadcast service of the
2 // Internet domain IPC-SAP dgram abstraction.
4 #include "ace/OS_main.h"
5 #include "ace/OS_NS_stdio.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/OS_NS_stdlib.h"
8 #include "ace/INET_Addr.h"
9 #include "ace/SOCK_Dgram_Bcast.h"
10 #include "ace/Get_Opt.h"
11 #include "ace/Log_Msg.h"
13 /* Name of the program. */
14 static ACE_TCHAR *program_name;
16 /* Port number to use. */
17 static unsigned short broadcast_port_number = ACE_DEFAULT_BROADCAST_PORT;
19 static void
20 print_usage_and_die ()
22 ACE_OS::fprintf (stderr, "usage: %s [-p broadcast portnum]\n",
23 ACE_TEXT_ALWAYS_CHAR (program_name));
24 ACE_OS::exit (1);
27 void
28 parse_args (int argc, ACE_TCHAR *argv[])
30 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("p:"));
32 for (int c; (c = get_opt ()) != -1; )
33 switch (c)
35 case 'p':
36 broadcast_port_number = ACE_OS::atoi (get_opt.opt_arg ());
37 break;
38 default:
39 print_usage_and_die ();
40 break;
44 int
45 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
47 program_name = argv[0];
48 parse_args (argc, argv);
50 ACE_SOCK_Dgram_Bcast sd (ACE_Addr::sap_any);
52 static char buf[] = "testing socket broadcast service";
54 if (sd.send (buf, ACE_OS::strlen (buf), broadcast_port_number) == -1)
55 ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "can't send broadcast"), -1);
57 return 0;