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
;
20 print_usage_and_die ()
22 ACE_OS::fprintf (stderr
, "usage: %s [-p broadcast portnum]\n",
23 ACE_TEXT_ALWAYS_CHAR (program_name
));
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; )
36 broadcast_port_number
= ACE_OS::atoi (get_opt
.opt_arg ());
39 print_usage_and_die ();
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);