BIND
Association d'un socket
à un port particulier
Declare Function bind Lib "wsock32" _
(ByVal sock As Long, _
addr As SOCK_ADDR,
ByVal namelen As Long) As Long
Paramètres :
sock : identifie le socket à attacher
addr : l'adresse à utiliser (port et numéro IP)
Type IN_ADDR
S_addr As Long
End Type
Type SOCK_ADDR
sin_family As Integer
sin_port As Integer
sin_addr As IN_ADDR
sin_zero(0 To 7) As Byte
End Type
namelen : taille en octets de addr
retour : SOCKET_ERROR en cas d'erreur, 0 sinon.
Public Const SOCKET_ERROR = -1
Remarques :
- pour associer le socket à tous les numéros IP de la machine, il faut utiliser le numéro fictif INADDR_ANY :
Public Const INADDR_ANY = &H0
- pour associer le socket à un port quelconque (libre mais quelconque), utiliser le numéro de port 0.
Exemple :
Dim CR as long
Dim LocalServer as SOCK_ADDR
LocalServer.sin_family = AF_INET
LocalServer.sin_port = 0
LocalServer.sin_addr.S_addr = INADDR_ANY
CR = bind(sock, LocalServer, Len(LocalServer))
If CR = SOCKET_ERROR Then
MsgBox "Erreur sur bind : " & WSAGetLastError()
End If
|