'
' Network
' version 0.1
' (c) 2011 Stefan Wurzinger
'

Declare Function netStart() As Integer
Declare Function netStop() As Integer
Declare Function resolveHost(ByRef hostname As String) As Integer




Function netStart() As Integer
	Dim wsaData As WSAData
	Return WSAStartup(MAKEWORD(1,1), @wsaData)  '"Error: WSAStartup failed"
End Function

Function netStop() As Integer
	Return WSACleanup()
End Function

Function resolveHost(ByRef hostname As String) As Integer
	Dim ia As in_addr
	Dim hostentry As hostent Ptr

	ia.S_addr = inet_addr(hostname)
	If (ia.S_addr = INADDR_NONE) Then
		hostentry = gethostbyname(hostname)
		If (hostentry = 0) Then Return 0
		Return *Cast(Integer Ptr, *hostentry->h_addr_list)
	End If
	
	Return ia.S_addr
End Function
