Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

vb 6's winsock control/sending magic packets

115 views
Skip to first unread message

Dan

unread,
Jul 19, 2002, 4:34:44 AM7/19/02
to
Hi

I'm trying to convert some vb6 code which sends magic packets into delphi 5
or 6. the code uses vb's winsock control. what's the best equivalent in
d5/d6? or does anyone know how to send a magic packet?

Thanks
Dan

Steve

unread,
Jul 19, 2002, 4:46:10 AM7/19/02
to
"Dan" <ds...@york.ac.uk> wrote in message news:3d37cf24$1_1@dnews...

Which magic packets are you talking about ?

Wake on lan ?


André Koch

unread,
Jul 19, 2002, 6:46:23 AM7/19/02
to
Hey thats interresting for me too.
That is what i have but my PC with an WakeonLan compatible Networkadapter
and right BIOS configuration does not wake.

function CheckWinSockResult(ResultCode: Integer; const FuncName: string):
Integer;
begin
if ResultCode <> 0 then
Result := WSAGetLastError
else
Result := 0;
end;

procedure Wake_on_Lan(SAddr: string);
const LEN_PHYSADDR = 6;
var WSAData : TWSAData;
MSocket : TSocket;
SockAddrIn : TSockAddrIn;
RetVal : integer;
OptVal : integer;
i : Integer;
MacAddr : array[0..5] of Byte;
MagicData : array[0..101] of Byte;
Position : Longint;
begin
try
if (Length(SAddr) = 17) and
(SAddr[3] = '-') and
(SAddr[6] = '-') and
(SAddr[9] = '-') and
(SAddr[12] = '-') and
(SAddr[15] = '-') then
begin
for i := 0 to High(MacAddr) do
begin
if Pos('-', SAddr) > 0 then
MacAddr[i] := StrToInt(HexDisplayPrefix + Copy(SAddr, 1, Pos('-',
SAddr) - 1))
else
MacAddr[i] := StrToInt(HexDisplayPrefix + SAddr);
Delete(SAddr, 1, Pos('-', SAddr));
end;

CheckWinSockResult(WSAStartup($0101, WSAData), 'WSAStartup');
MSocket := socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if MSocket = INVALID_SOCKET then
CheckWinSockResult(MSocket, 'socket');
OptVal := 1;
CheckWinSockResult(setsockopt(MSocket, SOL_SOCKET, SO_BROADCAST,
PChar(@OptVal), SizeOf(OptVal)), 'setsockopt');
FillChar(MagicData, SizeOf(MagicData), $FF);
Position := LEN_PHYSADDR;
while Position < SizeOf(MagicData) do
begin
Move(MacAddr, Pointer(Longint(@MagicData) + Position)^,
LEN_PHYSADDR);
Inc(Position, LEN_PHYSADDR);
end;
SockAddrIn.sin_family := AF_INET;
SockAddrIn.sin_addr.S_addr := Longint(INADDR_BROADCAST);
RetVal := sendto(MSocket, MagicData, SizeOf(MagicData), 0, SockAddrIn,
SizeOf(SockAddrIn));
if RetVal = SOCKET_ERROR then
CheckWinSockResult(RetVal, 'sendto');
CheckWinSockResult(closesocket(MSocket), 'closesocket');
CheckWinSockResult(WSACleanup, 'WSACleanup');
end;
except
end;
end;

When you got an result please let me know.

André


Dan

unread,
Jul 19, 2002, 6:58:22 AM7/19/02
to
yup, wake on lan.

"Steve" <st...@steve.com> wrote in message news:3d37d1d2_2@dnews...

Wayne Sherman

unread,
Jul 19, 2002, 3:07:30 PM7/19/02
to

http://sourceforge.net/projects/ezytools/

In the files section look for WakeOnLan.

Regards,

Wayne Sherman
Las Vegas


0 new messages