#103827 - 2003-08-18 10:13 AM
Re: String Challenge
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
quote: woudl work, however if the length of the binary string is beign determined ahead of time
And that is of course the only way it will work.
Maybe we should avoid the word "string" to describe this, as it is confusing the issue.
What you need is an abitrary binary object. It is not a string. Handling and object as a string is simply taking a binary object an adding some rules to it - the simplest of which is that it is null terminated.
A "string" object is a very simple beast. It has a start (pointer to memory location) and content (the string data). The size of the string is determined by the data (and available memory). This means that a string is represented in coding terms by a simple pointer to memory and nothing else.
To contain arbitrary binary data, the object needs more information contained within the object itself. Specifically it requires an "end" or more likely a "length" attribute. This must be a property of the object, as it needs to be passed along with it.
This is going to make things very complicated, as something like KiXtart can deal with binary objects represented as COM automation objects, but something like Winsock will be expecting two simple values - a pointer and a length.
What you could try is constructing an automation object which creates a buffer for arbitrary binary data, and a length parameter. Assign values to it using an array or C-escaped type declarations, and then pass the individual parts on. You won't be able to manipulate them in KiXtart (unless you follow the string rules) but you may be able to pass them for handling by COM.
A final note about Winsock. When I was looking at using it some time ago I had problems. Either the library wasn't initialising, or wasn't dealing with I/O because it was expecting to be dealing with event driven code. That was why I ended up playing with the Catalyst product.
The best solution for this is to code a wrapper COM Automation object which calls the socket library directly. The wrapper object can include all the support routines you need for automatically converting to and from native KiXtart types.
As a spooky aside this is exactly what I was working on before real work intervened and I had to mothball it.
|
|
Top
|
|
|
|
#103828 - 2003-08-18 02:20 PM
Re: String Challenge
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Jens,
quote:
BTW, the COM-object where I need this is MSWinsock.Winsock(), which I tried to use to do a Wake-On-LAN. However, MAC addresses do contain CHR(0), thus currently a no-go for KiXtart-COM
Do you have any example code written in VBS or JS that uses this COM component, and that manages to pass a string with null chars ?
Richard,
Yeah, if one was to build a COM wrapper for this, would probably just suggest wrapping this in an array and pass binary data like this:
$Object.Address = 0,3,23,0,44,255,0 ...
-Shawn [ 18. August 2003, 14:23: Message edited by: Shawn ]
|
|
Top
|
|
|
|
#103829 - 2003-08-18 04:25 PM
Re: String Challenge
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
VB Code ( http://cwashington.netreach.net/depo/view.asp?Index=415&ScriptType=component ):
code:
<?xml version="1.0"?> <component>
<?component error="true" debug="true"?>
<registration description="MagicPacket" progid="MagicPacket.WSC" version="1.01" classid="{37bab79c-5e27-4cf2-b0e2-73979683a479}" > </registration>
<public> <property name="IPBroadcastAddress"> <put/> </property> <property name="MacAddress"> <get/> <put/> </property> <method name="Send"> </method> </public>
<script language="VBScript"> <![CDATA[ '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Component: MagicPacket.WSC ' Properties: IPBroadcastAddress: ' The IP Broadcast Address of the host you would like to wake up. This is typically ' something like 10.10.118.255 ' MacAddress: ' The Hardware address of the host you would like to wake up. This can either ' be in the form 11:22:33:44:55:66 (as it is in SMS) or 11-22-33-44-55-66 as is ' the output from getmac.exe ' Methods: Send ' Sends the packet, and hopefully wakes up the machine ' Requires: mswinsck.dll ' Comes with VisualStudio ' ' Example: dim o ' Set o = CreateObject("MagicPacket.WSC") ' o.IPBroadcastAddress = "10.10.224.255" ' o.macaddress = "00-08-C7-59-2D-17" ' o.send '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' dim IPBroadcastAddress dim MacAddress
function put_IPBroadcastAddress(newValue) IPBroadcastAddress = newValue end function
function get_MacAddress() get_MacAddress = MacAddress end function
function put_MacAddress(newValue) MacAddress = newValue end function
function Send() SendWakeUp MacAddress, IPBroadcastAddress end function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Function: parseMac ' Params: Hardare address of network adapter in either colon(:) or dash(-) delimited form ' Return: Array of byte size mac address elements for later processing '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Function parseMAC(strMacAddr) Dim arMacAddr
Select Case Len(strMacAddr) Case 17 arMacAddr = Split(strMacAddr, ":") If Ubound(arMacAddr) <> 5 Then arMacAddr = Split(strMacAddr, "-") If Ubound(arMacAddr) <> 5 Then parseMac = -1 'Error Else parseMac = arMacAddr End If Else parseMac = arMacAddr End If
Case Else parseMac = -1 'Error End Select End Function '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Function: CreatePacket ' Params: array of bytes representing Mac address of target ' Return: String of data representing Magic Packet data ' Notes: Magic Packet is six bytes of chr(&HFF) folowed by 16 copies of the target adapter's ' Mac address '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Function CreatePacket(arMacAddr) Dim Item Dim strTemp Dim strData
For Each Item in arMacAddr Item = "&H" & Item strTemp = strTemp & chr(Item) Next For i = 1 to 16 strData = strData & strTemp Next CreatePacket = String(6, &HFF) & strData End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Function: SendWakeUp ' Params: Mac Address of target machine, IP Broadcast address of target machine '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Function SendWakeUp(MacAddr, BCastAddr) Dim objSocket Set objSocket = CreateObject("MSWinsock.Winsock") objSocket.Protocol = 1 'UDP objSocket.RemoteHost = BCastAddr objSocket.SendData CreatePacket(ParseMac(MacAddr)) objSocket.Close End Function ]]> </script>
</component>
KiXtart Code (not functional):
code:
; to be run with KiXtart 4.21 or later
break on cls dim $iRC $iRC=SetOption("WrapAtEOL","On") $iRC=SetOption("Explicit","On") $iRC=SetOption("NoVarsInStrings","On")
dim $sMAC, $sBCast
$sMAC=@ADDRESS $sBCast='128.197.181.255' ? 'MAC Address = '+$sMAC ? 'Broadcast Address = '+$sBCast
$iRC=WakeOnLAN($sMAC, $sBCast) ? 'Error '+@ERROR+' - '+@SERROR ? 'WakeOnLAN = '+$iRC exit 0
function WakeOnLAN($sMAC, $sBCast, optional $bWait) dim $iIndex, $asMAC[5], $sMagicPacket, $sByte dim $objSocket ; format the MAC address select case len($sMAC)=12 for $iIndex=0 to 5 $asMAC[$iIndex]=substr($sMAC,$iIndex*2+1,2) next case len($sMAC)=17 select case instr($sMAC,':') $asMAC=split($sMAC,':') case instr($sMAC,'-') $asMAC=split($sMAC,'-') case 1 exit 87 endselect case 1 exit 87 endselect ; create the magic packet (six bytes of FF followed by 16 copies of the MAC address $sMAC='' for each $sByte in $asMAC ? 'Byte = '+$sByte+' = '+chr(val('&'+$sByte)) $sMAC=$sMAC+chr(val('&'+$sByte)) next ? 'MAC = ('+len($sMAC)+') = '+$sMAC redim $sMagicPacket[6], $WakeOnLAN[16] $sMagicPacket=join($sMagicPacket,chr(&FF)) $WakeOnLAN=join($WakeOnLAN,$sMAC) $sMagicPacket=$sMagicPacket+$WakeOnLAN ? 'Magic Packet = '+len($sMagicPacket) ; create the Winsock object and send the magic packet $objSocket=createobject('MSWinsock.Winsock') $objSocket.Protocol = 1 $objSocket.RemoteHost = $sBCast $objSocket.SendData = $sMagicPacket $objSocket.Close $objSocket = 0 $WakeOnLAN=@ERROR exit @ERROR endfunction
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#103830 - 2003-08-19 01:05 AM
Re: String Challenge
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Just started looking at this bit of code - think it holds the key. Since the SendData method takes a string, then this routine is somehow constructing a string containing nulls ?
Whats with the sixteen times mac address thingy ? Is that part of the trick or just something to do with WOL ?
code:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Function: CreatePacket ' Params: array of bytes representing Mac address of target ' Return: String of data representing Magic Packet data ' Notes: Magic Packet is six bytes of chr(&HFF) folowed by 16 copies of the target adapter's ' Mac address '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Function CreatePacket(arMacAddr) Dim Item Dim strTemp Dim strData
For Each Item in arMacAddr Item = "&H" & Item strTemp = strTemp & chr(Item) Next For i = 1 to 16 strData = strData & strTemp Next CreatePacket = String(6, &HFF) & strData End Function
[ 19. August 2003, 01:07: Message edited by: Shawn ]
|
|
Top
|
|
|
|
#103832 - 2003-08-19 01:40 AM
Re: String Challenge
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Found a WinSock wrapper COM object called ActiveSocket that allows you to produce code like this:
code:
' ***************************************************** ' Example4: Wake Up on LAN ' Note: Use an existing MAC address ' (c) Copyright 2001 by ActiveXperts Software ' http://www.activexperts.com ' *****************************************************
Set wObj = CreateObject("ActivXperts.WOL")
WScript.Echo "ActiveSocket " & wObj.Version & " demo." WScript.Echo "Expiration date: " & wObj.ExpirationDate & vbCrLf
wObj.WakeUp "00-10-4B-BA-7A-51" WScript.Echo "WakeUp: result = " & wObj.LastError
Costs money though, which kinda sucks.
-Shawn
|
|
Top
|
|
|
|
#103833 - 2003-08-19 01:44 AM
Re: String Challenge
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Would it be acceptable for me to provide this functionality in Win32Admin.DLL? I think I can do if the code posted above works except for the nulls.
I know I can process chr(0)in Perl. [ 19. August 2003, 01:46: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#103835 - 2003-08-19 01:48 AM
Re: String Challenge
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
That would be what I expected would happen...take mac return did it wake up or not.
But I need to understand what the nitty gritty is. I haven't been following the WOL stuff.
|
|
Top
|
|
|
|
#103837 - 2003-08-19 02:02 AM
Re: String Challenge
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
S-ingTFW...
I will see what turns up.
|
|
Top
|
|
|
|
#103839 - 2003-08-19 03:04 AM
Re: String Challenge
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Who can test the new DLL with Win32Admin.WakeUp($mac [,$ip] [,$port])
Default IP is broadcast "255.255.255.255" default port is 9991
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2375 anonymous users online.
|
|
|