Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Need Help/Example to use getnameinfo function (WSAAPI)

$
0
0

Hello,

 

I'm trying to use getnameinfo instead of gethostbyaddr to get the netbios name of computers in a LAN.

 

gethostbyaddr (used in _TCPIpToName() function) works but is very slow to respond. It seems getnameinfo works faster.

 

I'm a newbie with DllCall so don't be too harsh with me ^^'.

 

Here is what i've tried :

AutoIt         
;~ struct sockaddr_in { ;~         short   sin_family; ;~         u_short sin_port; ;~         struct  in_addr sin_addr; ;~         char    sin_zero[8]; ;~ }; ;~ int WSAAPI getnameinfo( ;~   _In_   const struct sockaddr FAR *sa, ;~   _In_   socklen_t salen, ;~   _Out_  char FAR *host, ;~   _In_   DWORD hostlen, ;~   _Out_  char FAR *serv, ;~   _In_   DWORD servlen, ;~   _In_   int flags ;~ ); Local $host, $service TCPStartup() Local $ip = "192.168.0.1" Local $port = 139 Local $hDll_Ws2_32 = "ws2_32.dll" $ret_inetaddr = DllCall($hDll_Ws2_32, "ulong", "inet_addr", "str", $ip) $ret_hton = DllCall($hDll_Ws2_32, "USHORT", "htons", "USHORT", $port) $sockaddr = DllStructCreate("short sin_family ; USHORT port ; ptr in_adrr ; char sin_zero[8]") DllStructSetData($sockaddr, "sin_family", 2) ; AF_INET DllStructSetData($sockaddr, "port", $ret_hton[0]) DllStructSetData($sockaddr, "in_adrr", DllStructGetPtr($ret_inetaddr)) $ret = DllCall($hDll_Ws2_32, "int", "getnameinfo" _         , "ptr", DllStructGetPtr($sockaddr) _         , "int", DllStructGetSize($sockaddr) _         , "str*", $host _         , "dword", 1025 _         , "str*", $service _         , "dword", 0 _         , "int", 0) ConsoleWrite("error=" & @error & "   $ret[0]=" & $ret[0] & "   host=" & $host & @CR) TCPShutdown()

Thank you for your time and sorry for my english.


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>