"Gisle Vanem" wrote in message news:<406aeec8$1@news.broadpark.no>...
> "Colin Pimlott" wrote:
>
> > I get the error code 10047 (Address Family is not supported) when
> > attempting a network broadcast.
> >
> > The relevant VB6 code is
> >
> > Winsock1.Protocol = sckUDPProtocol
> > Winsock1.LocalPort = 0
> > Winsock1.RemotePort = 1000
> > Winsock1.RemoteHost = "255.255.255.255"
> > Winsock1.Bind

>
> You must enable broadcast by
> BOOL on = TRUE;
> setsockopt (sock, SOL_SOCKET, SO_BROADCAST, (const char*)&on, sizeof(on));


Thanks,
I am using the MSWinsck.ocx control, and I have tried to do this with
the following..

Const SO_BROADCAST = &H20
Const SOL_SOCKET = &HFFFF

Public Type OptType
Opt As Long
End Type

Public Declare Function setsockopt Lib "wsock32.dll" (ByVal sock As
Long, _
ByVal level As Integer, ByVal optname As Integer, _
optval As OptType, ByVal optlen As Integer) As Integer


optval.Opt = 1
intErr = setsockopt(Winsock1.SocketHandle, SOL_SOCKET, SO_BROADCAST,
optval, Len(optval))

...but it always returns -1 (SOCKET_ERROR). I presume I should call
setsockopt after the Winsock1.Bind function call.

I don't know if the socket handle returned by the ocx is the same as
the one it passes to the winsock layer.

Regards
Colin.