caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* UDP broadcast from Windows
@ 2007-10-10  1:31 Reed Wilson
  2007-10-10  8:55 ` [Caml-list] " Xavier Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: Reed Wilson @ 2007-10-10  1:31 UTC (permalink / raw)
  To: caml-list

Hi guys!

I'm in the middle of writing a program which does a UDP broadcast, but I 
noticed it doesn't work on Windows. Here's the source:

try (
   let sock = Unix.socket Unix.PF_INET Unix.SOCK_DGRAM 0 in
   Unix.setsockopt sock Unix.SO_BROADCAST true;
   let sent = Unix.sendto sock "ping" 0 4 [] (Unix.ADDR_INET 
((Unix.inet_addr_of_string "255.255.255.255"), 12345)) in
   Printf.printf "Sent %d\n" sent;
) with
   | Unix.Unix_error (x,y,z) -> Printf.printf "%S - %s,%s\n" 
(Unix.error_message x) y z
;;


I noticed that when I force the address by replacing:
Unix.inet_addr_of_string "255.255.255.255"

with:
Obj.magic "\255\255\255\255"

it _seems_ to work fine. I looked around in the OCaml source, and it 
looks like the broadcast address is specifically disallowed unless 
HAS_INET_ATON is defined? Why is this? And am I breaking anything by 
using magic?

Thanks
Reed


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-10-10  8:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-10  1:31 UDP broadcast from Windows Reed Wilson
2007-10-10  8:55 ` [Caml-list] " Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).