• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

UDP Host Address detection

Started by Patrice Terrier, September 30, 2015, 11:10:27 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

This short piece of SDK coding style is a replacement for The PB/PBCC HOST ADDR statement,
to translate a host name into a corresponding IP address.

'// Patrice Terrier's core API replacement to the PB's HOST ADDR statement.
'// released on 09-27-2015
#COMPILE EXE "HOST_ADDR.exe"
#include "win32api.inc"

$zLim = "|"
declare function my_inet_ntoa lib "wsock32.dll" alias "inet_ntoa" (byval inn as dword) as dword
function HOST_ADDR() as string
    local host_name as asciiz * 256
    local hp as hostent ptr
    local ip_address as string
    local wsa as WSADATA
    if (WSAStartup(&H0202, wsa) = 0) then
        if (gethostname(host_name, sizeof(host_name)) = 0) then
            hp = gethostbyname(host_name)
            if (hp) then
                local ptrAddr as dword ptr
                local ptrAsciiz as asciiz ptr
                ptrAddr = @hp.h_addr_list
                do while @ptrAddr
                    ptrAsciiz = my_inet_ntoa(@@ptrAddr)
                    ip_address += @ptrAsciiz + $zLim
                    incr ptrAddr
                loop
                function = rtrim$(ip_address, $zLim)
            end if
        end if
        WSACleanup()
    end if
end function

function PBMAIN () AS LONG
    print "Your HOST ADDR is " + HOST_ADDR()
end function


...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com