elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  API de WinSock para VB (Completa)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: API de WinSock para VB (Completa)  (Leído 20,116 veces)
Slasher-K


Desconectado Desconectado

Mensajes: 1.477


Ver Perfil
API de WinSock para VB (Completa)
« en: 21 Marzo 2005, 07:15 am »

Muchas veces es difícil encontrar las funciones de WinSock para VB, así que recopilé todas las funciones, estructuras, constantes, etc. que se usan para manipular sockets en Windows.

También puse algunas funciones básicas para ejemplificar el uso de las funciones.


Código:
'*************************************************************
'¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
'     Application Programming Inteface (API) for WinSock
'
'Este módulo contiene todas las declaraciones necesarias para
'utilizar los sockets de sistema. El funcionamiento y ejemplo
'de estas funciones se pueden encontrar en MSDN:
'
'http://msdn.microsoft.com
'
'Autor: Slasher Keeper :)
'Fuente: MSDN Library
'
'¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
'**************************************************************

Option Explicit

#Const WS_CURVERSION = 2


Public Const WS_VERSION_REQD = &H101
Public Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100 And &HFF&
Public Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF&
Public Const MIN_SOCKETS_REQD = 1
Public Const SOCKET_ERROR = -1
Public Const WSADescription_Len = 256
Public Const WSASYS_Status_Len = 128
Public Const FD_SETSIZE = 64

'Network Events.
'
Public Const FD_READ_BIT = 0
Public Const FD_READ = 1
Public Const FD_WRITE_BIT = 1
Public Const FD_WRITE = 2
Public Const FD_OOB_BIT = 2
Public Const FD_OOB = 4
Public Const FD_ACCEPT_BIT = 3
Public Const FD_ACCEPT = 8
Public Const FD_CONNECT_BIT = 4
Public Const FD_CONNECT = 16
Public Const FD_CLOSE_BIT = 5
Public Const FD_CLOSE = 32
Public Const FD_QOS_BIT = 6
Public Const FD_QOS = 64
Public Const FD_GROUP_QOS_BIT = 7
Public Const FD_GROUP_QOS = 128
Public Const FD_ROUTING_INTERFACE_CHANGE_BIT = 8
Public Const FD_ROUTING_INTERFACE_CHANGE = 256
Public Const FD_ADDRESS_LIST_CHANGE_BIT = 9
Public Const FD_ADDRESS_LIST_CHANGE = 512
Public Const FD_MAX_EVENTS = 10
Public Const FD_ALL_EVENTS = 1023

'Namespaces.
'
Public Const NS_ALL = 0

Public Const NS_SAP = 1
Public Const NS_NDS = 2
Public Const NS_PEER_BROWSE = 3

Public Const NS_TCPIP_LOCAL = 10
Public Const NS_TCPIP_HOSTS = 11
Public Const NS_DNS = 12
Public Const NS_NETBT = 13
Public Const NS_WINS = 14

Public Const NS_NBP = 20

Public Const NS_MS = 30
Public Const NS_STDA = 31
Public Const NS_NTDS = 32

Public Const NS_X500 = 40
Public Const NS_NIS = 41
Public Const NS_NISPLUS = 42

Public Const NS_WRQ = 50

Public Const SERVICE_REGISTER = 1
Public Const SERVICE_DEREGISTER = 2
Public Const SERVICE_FLUSH = 3
Public Const SERVICE_FLAG_HARD = &H2

Enum SearchControlFlags
  LUP_DEEP = &H1
  LUP_CONTAINERS = &H2
  LUP_NOCONTAINERS = &H4
  LUP_NEAREST = &H8
  LUP_RETURN_NAME = &H10
  LUP_RETURN_TYPE = &H20
  LUP_RETURN_VERSION = &H40
  LUP_RETURN_COMMENT = &H80
  LUP_RETURN_ADDR = &H100
  LUP_RETURN_BLOB = &H200
  LUP_RETURN_ALIASES = &H400
  LUP_RETURN_QUERY_STRING = &H800
  LUP_RETURN_ALL = &HFF0
  LUP_RES_SERVICE = &H8000
  LUP_FLUSHCACHE = &H1000
  LUP_FLUSHPREVIOUS = &H2000
End Type


'Protocolos
'
Enum SockProtocols
  IPPROTO_IP = 0                           'dummy for IP
  IPPROTO_ICMP = 1                         'control message protocol
  IPPROTO_IPIP = 4
  IPPROTO_GGP = 2                          ' gateway^2 (deprecated)
  IPPROTO_TCP = 6                          ' tcp
  IPPROTO_EGP = 8
  IPPROTO_PUP = 12                         ' pup
  IPPROTO_UDP = 17                         ' user datagram protocol
  IPPROTO_IDP = 22                         ' xns idp
  IPPROTO_ND = 77                          ' UNOFFICIAL net disk proto
  NSPROTO_IPX = 1000
  NSPROTO_SPX = 1256
  NSPROTO_SPXII = 1257
End Enum

'Socket types.
'
Enum SockTypes
  SOCK_STREAM = 1 'Envía datos como flujo de bytes.
  SOCK_DGRAM = 2  'Datagrama. Protocolo de conexión.
  SOCK_RAW = 3    '???
  SOCK_RDM = 4    'Reliably-Delivered Message (Mensaje confiablemente-entregado)
                  'Es un protocolo que conserva los límites del mensaje en los
                  'datos
  SOCK_SEQPACKET = 5  'Flujo de paquetes secuenciados. Es esencialmente igual
                      'que SOCK_RDM.
End Enum

Enum SockPorts
  '
  'Standard well-known ports
  '
  IPPORT_ECHO = 7
  IPPORT_DISCARD = 9
  IPPORT_SYSTAT = 11
  IPPORT_DAYTIME = 13
  IPPORT_NETSTAT = 15
  IPPORT_FTP = 21
  IPPORT_TELNET = 23
  IPPORT_SMTP = 25
  IPPORT_TIMESERVER = 37
  IPPORT_NAMESERVER = 42
  IPPORT_WHOIS = 43
  IPPORT_MTP = 57

  IPPORT_TFTP = 69
  IPPORT_RJE = 77
  IPPORT_FINGER = 79
  IPPORT_TTYLINK = 87
  IPPORT_SUPDUP = 95

  IPPORT_EXECSERVER = 512
  IPPORT_LOGINSERVER = 513
  IPPORT_CMDSERVER = 514
  IPPORT_EFSSERVER = 520

  'UDP ports.
  '
  IPPORT_BIFFUDP = 512
  IPPORT_WHOSERVER = 513
  IPPORT_ROUTESERVER = 520

  'Los puertos menores a este valor están reservados para
  'procesos con provilegios.
  '
  IPPORT_RESERVED = 1024

  'Los puertos mayores a este valor están reservados para
  'procesos sin privilegios.
  '
  IPPORT_USERRESERVED = 5000

End Enum

Enum SockErrors
  '
  'Windows Sockets definitions of regular Berkeley error constants
  '
 
   WSABASEERR = 10000
   WSAEWOULDBLOCK = (WSABASEERR + 35)
   WSAEINPROGRESS = (WSABASEERR + 36)
   WSAEALREADY = (WSABASEERR + 37)
   WSAENOTSOCK = (WSABASEERR + 38)
   WSAEDESTADDRREQ = (WSABASEERR + 39)
   WSAEMSGSIZE = (WSABASEERR + 40)
   WSAEPROTOTYPE = (WSABASEERR + 41)
   WSAENOPROTOOPT = (WSABASEERR + 42)
   WSAEPROTONOSUPPORT = (WSABASEERR + 43)
   WSAESOCKTNOSUPPORT = (WSABASEERR + 44)
   WSAEOPNOTSUPP = (WSABASEERR + 45)
   WSAEPFNOSUPPORT = (WSABASEERR + 46)
   WSAEAFNOSUPPORT = (WSABASEERR + 47)
   WSAEADDRINUSE = (WSABASEERR + 48)
   WSAEADDRNOTAVAIL = (WSABASEERR + 49)
   WSAENETDOWN = (WSABASEERR + 50)
   WSAENETUNREACH = (WSABASEERR + 51)
   WSAENETRESET = (WSABASEERR + 52)
   WSAECONNABORTED = (WSABASEERR + 53)
   WSAECONNRESET = (WSABASEERR + 54)
   WSAENOBUFS = (WSABASEERR + 55)
   WSAEISCONN = (WSABASEERR + 56)
   WSAENOTCONN = (WSABASEERR + 57)
   WSAESHUTDOWN = (WSABASEERR + 58)
   WSAETOOMANYREFS = (WSABASEERR + 59)
   WSAETIMEDOUT = (WSABASEERR + 60)
   WSAECONNREFUSED = (WSABASEERR + 61)
   WSAELOOP = (WSABASEERR + 62)
   WSAENAMETOOLONG = (WSABASEERR + 63)
   WSAEHOSTDOWN = (WSABASEERR + 64)
   WSAEHOSTUNREACH = (WSABASEERR + 65)
   WSAENOTEMPTY = (WSABASEERR + 66)
   WSAEPROCLIM = (WSABASEERR + 67)
   WSAEUSERS = (WSABASEERR + 68)
   WSAEDQUOT = (WSABASEERR + 69)
   WSAESTALE = (WSABASEERR + 70)
   WSAEREMOTE = (WSABASEERR + 71)
   WSAEDISCON = (WSABASEERR + 101)
End Enum

Enum SockAddressFamilies
   AF_UNSPEC = 0                    'unspecified
   AF_UNIX = 1                      'local to host (pipes, portals)
   AF_INET = 2                      'internetwork: UDP, TCP, etc.
   AF_IMPLINK = 3                   'arpanet imp addresses
   AF_PUP = 4                       'pup protocols: e.g. BSP
   AF_CHAOS = 5                     'mit CHAOS protocols
   AF_IPX = 6                       'IPX and SPX
   AF_NS = 6                        'XEROX NS protocols
   AF_ISO = 7                       'ISO protocols
   AF_OSI = AF_ISO                  'OSI is ISO
   AF_ECMA = 8                      'european computer manufacturers
   AF_DATAKIT = 9                   'datakit protocols
   AF_CCITT = 10                    'CCITT protocols, X.25 etc
   AF_SNA = 11                      'IBM SNA
   AF_DECnet = 12                   'DECnet
   AF_DLI = 13                      'Direct data link interface
   AF_LAT = 14                      'LAT
   AF_HYLINK = 15                   'NSC Hyperchannel
   AF_APPLETALK = 16                'AppleTalk
   AF_NETBIOS = 17                  'NetBios-style addresses
End Enum

Type SOCKADDR
  sa_family   As Integer
  sa_data     As String * 14
End Type

Type IN_ADDR
  s_b1 As Byte
  s_b2 As Byte
  s_b3 As Byte
  s_b4 As Byte
  s_w1 As Integer
  s_w2 As Integer
End Type

Type SOCKADDR_IN
  sin_family  As Integer
  sin_port    As Integer
  sin_addr    As IN_ADDR
  sin_zero    As String * 8
End Type

Type OVERLAPPED
  Internal      As Long
  InternalHigh  As Long
  Offset        As Long
  OffsetHigh    As Long
  hEvent        As Long
End Type

Type CSADDR_INFO
  LocalAddr     As Long
  RemoteAddr    As Long
  iSocketType   As Long
  iProtocol     As SockProtocols
End Type

Type HOSTENT
  h_name          As Long     'official name of host
  h_aliases       As Long     'alias list
  h_addrtype      As Integer  'host address type
  h_length        As Integer
  h_addr_list     As Long     'list of addresses
End Type


Type PROTOENT
  p_name        As String
  p_aliases(15) As String
  p_proto       As Integer
End Type

Type SERVENT
  s_name        As String
  s_aliases(15) As String
  s_port        As Integer
  s_proto       As String
End Type

Type SERVICE_ADDRESS
  dwAddressType     As Long
  dwAddressFlags    As Long
  dwAddressLength   As Long
  dwPrincipalLength As Long
  lpAddress         As Byte
  lpPrincipal       As Byte
End Type

Type SERVICE_ADDRESSES
  dwAddressCount  As Long
  Addresses(1)    As SERVICE_ADDRESS
End Type

Type BLOB
  cbSize      As Long
  pBlobData   As Byte
End Type

Type SERVICE_INFO
  lpServiceType       As Long
  lpServiceName       As String
  lpComment           As String
  lpLocale            As String
  dwDisplayHint       As Long
  dwVersion           As Long
  dwTime              As Long
  lpMachineName       As String
  lpServiceAddress As SERVICE_ADDRESSES
  ServiceSpecificInfo As BLOB
End Type

Type NS_SERVICE_INFO
  dwNameSpace As Long
  ServiceInfo As SERVICE_INFO
End Type

Type WSADATA
  wversion          As Integer
  wHighVersion      As Integer
  szDescription(0 To WSADescription_Len) As Byte
  szSystemStatus(0 To WSASYS_Status_Len) As Byte
  iMaxSockets       As Integer
  iMaxUdpDg         As Integer
  lpszVendorInfo    As Long
End Type

Type LARGE_INTEGER
  lowpart As Long
  highpart As Long
End Type

Type FD_SET
  fd_count              As Long
  fd_array(FD_SETSIZE)  As Long
End Type

Type TIMEVAL
  tv_sec  As Long
  tv_usec As Long
End Type

Type TRANSMIT_FILE_BUFFERS
  Head        As Long
  HeadLength  As Long
  Tail        As Long
  TailLength  As Long
End Type

Type FLOWSPEC
  TokenRate           As Long     'In Bytes/sec
  TokenBucketSize     As Long     'In Bytes
  PeakBandwidth       As Long     'In Bytes/sec
  Latency             As Long     'In microseconds
  DelayVariation      As Long     'In microseconds
  ServiceType         As Integer  'Guaranteed, Predictive,
                                  'Best Effort, etc.
  MaxSduSize          As Long     'In Bytes
  MinimumPolicedSize  As Long     'In Bytes
End Type

Type PROTOCOL_INFO
  dwServiceFlags  As Long
  iAddressFamily  As Long
  iMaxSockAddr    As Long
  iMinSockAddr    As Long
  iSocketType     As Long
  iProtocol       As Long
  dwMessageSize   As Long
  lpProtocol      As Long
End Type

Declare Function accept Lib "ws2_32" (ByVal sck As Long, addr As SOCKADDR, AddrLen As Integer) As Long

Declare Function AcceptEx Lib "ws2_32" (ByVal sListenSocket As Long, ByVal sAcceptSocket As Long, lpOutputBuffer As Any, ByVal dwReceiveDataLength As Long, ByVal dwLocalAddressLength As Long, ByVal dwRemoteAddressLength As Long, lpdwBytesReceived As Long, lpOverlapped As OVERLAPPED) As Long

Declare Function bind Lib "ws2_32" (ByVal sck As Long, name As SOCKADDR, ByVal namelen As Long) As Long
Declare Function closesocket Lib "ws2_32" (ByVal sck As Long) As Long

Declare Function Connect Lib "ws2_32" (ByVal sck As Long, ByVal SckName As String, ByVal namelen As Long) As Long
Declare Function EnumProtocols Lib "ws2_32" Alias "EnumProtocolsA" (ByVal lpiProtocols As SockProtocols, ByVal lpProtocolBuffer As PROTOCOL_INFO, ByVal lpdwBufferLength As Long)

Declare Sub GetAcceptExSockaddrs Lib "ws2_32" (lpOutputBuffer As Any, ByVal dwReceiveDataLength As Long, ByVal dwLocalAddressLength As Long, ByVal dwRemoteAddressLength As Long, LocalSockaddr As Long, LocalSockaddrLength As Long, RemoteSockaddr As Long, RemoteSockaddrLength As Long)

Declare Function GetAddressByName Lib "ws2_32" Alias "GetAddressByNameA" (ByVal dwNameSpace As Long, ByVal lpServiceType As Long, ByVal lpServiceName As Long, ByVal lpiProtocols As SockProtocols, ByVal dwResolution As Long, ByVal lpServiceAsyncInfo As Long, lpCsaddrBuffer As CSADDR_INFO, ByVal lpdwBufferLength As Long, ByVal lpAliasBuffer As Long, ByVal lpdwAliasBufferLength As Long) As Long

Declare Function gethostbyaddr Lib "ws2_32" (ByVal addr As String, ByVal iaddrlen As Long, ByVal iaddrtype As Long) As HOSTENT

Declare Function gethostbyname Lib "ws2_32" (ByVal hostname As String) As Long

Declare Function gethostname Lib "ws2_32" (ByVal name As String, ByVal namelen As Long) As Long

Declare Function GetNameByType Lib "ws2_32" Alias "GetNameByTypeA" (ByVal lpServiceType As Long, ByVal lpServiceName As String, ByVal dwNameLength As Long) As Long

Declare Function getpeername Lib "ws2_32" (ByVal sck As Long, name As SOCKADDR, ByVal namelen As Long) As Long

Declare Function getprotobyname Lib "ws2_32" (ByVal name As String) As PROTOENT

Declare Function getprotobynumber Lib "ws2_32" (ByVal Number As Long) As PROTOENT

Declare Function getservbyname Lib "ws2_32" (ByVal name As String, ByVal proto As String) As SERVENT

Declare Function getservbyport Lib "ws2_32" (ByVal port As Integer, ByVal proto As String) As SERVENT


Declare Function GetService Lib "ws2_32" Alias "GetServiceA" (ByVal dwNameSpace As Long, ByVal lpGuid As Long, ByVal lpServiceName As String, ByVal dwProperties As Long, lpBuffer As NS_SERVICE_INFO, ByVal lpdwBufferSize As Long, ByVal lpServiceAsyncInfo As Long) As Long

Declare Function GetSockName Lib "ws2_32" Alias "GetSockNameA" (ByVal sck As Long, name As Long, ByVal namelen As Long) As Long

Declare Function getsockopt Lib "ws2_32" (ByVal sck As Long, ByVal level As Long, ByVal optname As Long, ByVal optval As Long, optlen As Long) As Long

Declare Function GetTypeByName Lib "ws2_32" Alias "GetTypeByNameA" ()

Declare Function htons Lib "ws2_32" (ByVal hostshort As Integer) As Integer

Declare Function htonl Lib "ws2_32" (ByVal hostlong As Long) As Long

Declare Function inet_addr Lib "ws2_32" (ByVal cp As String) As Long

Declare Function inet_ntoa Lib "ws2_32" (pin As IN_ADDR) As Long

Declare Function ioctlsocket Lib "ws2_32" (ByVal s As Long, ByVal cmd As Long, ByVal argp As Long) As Integer

Declare Function listen Lib "ws2_32" (ByVal s As Long, ByVal backlog As Integer) As Integer

Declare Function ntohl Lib "ws2_32" (ByVal netlong As Long) As Long

Declare Function ntohs Lib "ws2_32" (ByVal netshort As Integer) As Integer

Declare Function recv Lib "ws2_32" (ByVal s As Long, ByVal buf As String, ByVal BufLen As Integer, ByVal flags As Integer) As Integer

Declare Function recvfrom Lib "ws2_32" (ByVal s As Long, ByVal buf As String, ByVal BufLen As Integer, ByVal flags As Integer, from As SOCKADDR, fromlen As Integer) As Integer

Declare Function sockselect Lib "ws2_32" Alias "select" (ByVal nfds As Integer, readfds As FD_SET, writefds As FD_SET, exceptfds As FD_SET, timeout As TIMEVAL) As Integer

Declare Function send Lib "ws2_32" (ByVal s As Long, ByVal buf As Long, ByVal BufLen As Integer, ByVal flags As Integer) As Integer

Declare Function sendto Lib "ws2_32" (ByVal s As Long, ByVal buf As Long, ByVal BufLen As Integer, ByVal flags As Integer, sckto As SOCKADDR, ByVal tolen As Integer) As Integer

Declare Function SetService Lib "ws2_32" Alias "SetServiceA" (ByVal dwNameSpace As Long, ByVal dwOperation As Long, ByVal dwFlags As Long, lpServiceInfo As SERVICE_INFO, ByVal lpServiceAsyncInfo As Long, ByVal lpdwStatusFlags As Long) As Long

Declare Function setsockopt Lib "ws2_32" (ByVal s As Long, ByVal level As Integer, ByVal optname As Integer, ByVal optval As Long, ByVal optlen As Long) As Integer

Declare Function shutdown Lib "ws2_32" (ByVal s As Long, ByVal how As Integer) As Integer

Declare Function socket Lib "ws2_32" (ByVal iAddressFamily As Long, ByVal iType As Long, ByVal iProtocol As Long) As Long

Declare Function TransmitFile Lib "ws2_32" (ByVal hSocket As Long, ByVal hFile As Long, ByVal nNumberOfBytesToWrite As Long, ByVal nNumberOfBytesPerSend As Long, ByVal lpOverlapped As OVERLAPPED, ByVal lpTransmitBuffers As TRANSMIT_FILE_BUFFERS, ByVal dwFlags As Long) As Boolean


Const MAX_PROTOCOL_CHAIN = 7

Type WSAPROTOCOLCHAIN
  ChainLen As Integer   'the length of the chain,
                        'length = 0 means layered protocol,
                        'length = 1 means base protocol,
                        'length > 1 means protocol chain
  ChainEntries(MAX_PROTOCOL_CHAIN) As Long  'a list of dwCatalogEntryIds
End Type

Const WSAPROTOCOL_LEN = 255

Type WSAPROTOCOL_INFO
    dwServiceFlags1                 As Long
    dwServiceFlags2                 As Long
    dwServiceFlags3                 As Long
    dwServiceFlags4                 As Long
    dwProviderFlags                 As Long
    ProviderId                      As CLSID
    dwCatalogEntryId                As Long
    ProtocolChain                   As WSAPROTOCOLCHAIN
    iVersion                        As Integer
    iAddressFamily                  As Integer
    iMaxSockAddr                    As Integer
    iMinSockAddr                    As Integer
    iSocketType                     As Integer
    iProtocol                       As Integer
    iProtocolMaxOffset              As Integer
    iNetworkByteOrder               As Integer
    iSecurityScheme                 As Integer
    dwMessageSize                   As Integer
    dwProviderReserved              As Integer
    szProtocol(WSAPROTOCOL_LEN + 1) As Byte
End Type
 
Declare Function WSAAccept Lib "ws2_32" (ByVal hSocket As Long, pSockAddr As SOCKADDR, ByVal AddrLen As Integer, ByVal lpfnCondition As Long, ByVal dwCallbackData As Long) As Long

Declare Function WSAAddressToString Lib "ws2_32" Alias "WSAAddressToStringA" (lpsaAddress As SOCKADDR, ByVal dwAddressLength As Long, lpProtocolInfo As PROTOCOL_INFO, ByVal lpszAddressString As String, ByVal lpdwAddressStringLength As Long) As Long

Declare Function WSAAsyncGetHostByAddr Lib "ws2_32" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal lpNetAddr As Long, ByVal AddrLen As Long, ByVal AddrType As Long, ByVal lpBuf As Long, ByVal BufLen As Long) As Long

Declare Function WSAAsyncGetHostByName Lib "ws2_32" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal lpHostName As String, ByVal lpBuf As Long, ByVal BufLen As Long) As Long

Declare Function WSAAsyncGetProtoByName Lib "ws2_32" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal lpHostName As String, ByVal lpBuf As Long, ByVal BufLen As Long) As Long

Declare Function WSAAsyncGetProtoByNumber Lib "ws2_32" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal iNumer As Integer, ByVal lpBuf As Long, ByVal BufLen As Long) As Long

Declare Function WSAAsyncGetServByName Lib "ws2_32" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal lpServiceName As String, ByVal lpProtocolName As String, ByVal lpBuf As Long, ByVal BufLen As Long) As Long

Declare Function WSAAsyncGetServByPort Lib "ws2_32" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal iPort As Integer, ByVal lpProtocolName As String, ByVal lpBuf As Long, ByVal BufLen As Long) As Long

Declare Function WSAAsyncSelect Lib "ws2_32" (ByVal hSocket As Long, ByVal hWnd As Long, ByVal wMsg As Integer, ByVal lEvent As Long) As Integer

Declare Function WSACancelAsyncRequest Lib "ws2_32" (ByVal hAsyncTaskHandle As Long) As Integer

Declare Function WSACleanup Lib "ws2_32" () As Integer

Declare Function WSACloseEvent Lib "ws2_32" (ByVal hEvent As Long) As Boolean
Declare Function WSAConnect Lib "ws2_32" (ByVal hSocket As Long, lpSckName As SOCKADDR, ByVal iSckNameLen As Integer, ByVal lpCallerData As Long, lpCalleeData As Long, lpSQOS As FLOWSPEC, lpGQOS As FLOWSPEC) As Integer

Declare Function WSACreateEvent Lib "ws2_32" () As Long

Declare Function WSADuplicateSocket Lib "ws2_32" Alias "WSADuplicateSocketA" (ByVal hSocket As Long, ByVal dwProcessId As Long, lpProtocolInfo As WSAPROTOCOL_INFO)

Type WSANAMESPACE_INFO
  NSProviderId    As CLSID
  dwNameSpace     As Long
  fActive         As Boolean
  dwVersion       As Long
  lpszIdentifier  As Long
End Type

Declare Function WSAEnumNameSpaceProviders Lib "ws2_32" Alias "WSAEnumNameSpaceProvidersA" (lpdwBufferLength As Long, lpnspBuffer As Long) As Integer

Type WSANETWORKEVENTS
  lNetworkEvents            As Long
  iErrorCode(FD_MAX_EVENTS) As Integer
End Type

Declare Function WSAEnumNetworkEvents Lib "ws2_32" (ByVal hSocket As Long, ByVal hEventObject As Long, lpNetworkEvents As WSANETWORKEVENTS)

Declare Function WSAEnumProtocols Lib "ws2_32" Alias "WSAEnumProtocolsA" (ByVal lpiProtocols As Long, lpProtocolBuffer As Long, ByVal lpdwBufferLength As Long) As Integer


Declare Function WSAEventSelect Lib "ws2_32" (ByVal hSocket As Long, ByVal hEventObject As Long, ByVal lNetworkEvents As Long)

Declare Function WSAGetLastError Lib "ws2_32" () As Integer

Type WSAOVERLAPPED
  Internal      As Long
  InternalHigh  As Long
  Offset        As Long
  OffsetHigh    As Long
  hEvent        As Long
End Type

Declare Function WSAGetOverlappedResult Lib "ws2_32" (ByVal hSocket As Long, lpOverlapped As WSAOVERLAPPED, lpcbTransfer As Long, ByVal fWait As Boolean, ByVal lpdwFlags As Long) As Boolean

Type WSABUF
  dwBufferLen As Long
  lpBuffer    As Long
End Type

Type QUALITYOFSERVICE
  SendingFlowspec   As FLOWSPEC
  ReceivingFlowspec As FLOWSPEC
  ProviderSpecific  As WSABUF
End Type

Declare Function WSAGetQOSByName Lib "ws2_32" (ByVal hSocket As Long, lpQOSName As Long, lpQOS As QUALITYOFSERVICE)

Declare Function WSAGetServiceClassInfo Lib "ws2_32" Alias "WSAGetServiceClassInfoA" (lpProviderId As CLSID, lpServiceClassId As CLSID, ByVal lpdwBufferLength As Long, ByVal lpServiceClassInfo As Long) As Integer

Declare Function WSAGetServiceClassNameByClassId Lib "ws2_32" Alias "WSAGetServiceClassNameByClassIdA" (lpServiceClassId As CLSID, ByVal lpszServiceClassName As String, ByVal lpdwBufferLength As Integer) As Integer

Declare Function WSAHtonl Lib "ws2_32" (ByVal hSocket As Long, ByVal dwHostLong As Long, dwNetLong As Long) As Integer

Declare Function WSAHtons Lib "ws2_32" (ByVal hSocket As Long, ByVal iHostShort As Integer, lpNetShort As Integer) As Integer

Type WSAServiceClassInfo
  lpServiceClassId      As CLSID
  lpszServiceClassName  As String
  dwCount               As Long
  lpClassInfos          As Long
End Type

Declare Function WSAInstallServiceClass Lib "ws2_32" Alias "WSAInstallServiceClassA" (lpServiceClassInfo As WSAServiceClassInfo)

Declare Function WSAIoctl Lib "ws2_32" (ByVal hSocket As Long, ByVal dwIoControlCode As Long, ByVal lpvInBuffer As Long, ByVal cbInBuffer As Long, ByVal lpvOUTBuffer As Long, ByVal bOUTBuffer As Long, lpcbBytesReturned As Long, lpOverlapped As WSAOVERLAPPED, ByVal lpCompletionROUTINE As Long)

Declare Function WSAJoinLeaf Lib "ws2_32" (ByVal hSocket As Long, lpSckName As SOCKADDR, ByVal iSckNameLen As Integer, lpCallerData As WSABUF, lpCalleeData As WSABUF, lpSQOS As FLOWSPEC, lpGQOS As FLOWSPEC, ByVal dwFlags As Long) As Long

Enum WSAEcomparator
  COMP_EQUAL = 0
  COMP_NOTLESS = 1
End Enum

Type WSAVersion
  dwVersion As Long
  ecHow     As WSAEcomparator
End Type

Type AFPROTOCOLS
  iAddressFamily  As Integer
  iProtocol       As Integer
End Type

Type SOCKET_ADDRESS
  lpSockaddr      As Long
  iSockaddrLength As Long
End Type

Type WSAQuerySet
  dwSize                  As Long
  lpszServiceInstanceName As String
  lpServiceClassId        As CLSID
  lpVersion               As WSAVersion
  lpszComment             As String
  dwNameSpace             As Long
  lpNSProviderId          As CLSID
  lpszContext             As String
  dwNumberOfProtocols     As Long
  lpafpProtocols          As Long
  lpszQueryString         As String
  dwNumberOfCsAddrs       As Long
  lpcsaBuffer             As CSADDR_INFO
  dwOutputFlags           As Long
  lpBlob                  As BLOB
End Type

Declare Function WSALookupServiceBegin Lib "ws2_32" Alias "WSALookupServiceBeginA" (ByVal lpqsRestrictions As WSAQuerySet, ByVal dwControlFlags As SearchControlFlags, lphLookup As Long) As Integer

Declare Function WSALookupServiceEnd Lib "ws2_32" (ByVal hLookup As Long) As Integer

Declare Function WSALookupServiceNext Lib "ws2_32" Alias "WSALookupServiceNextA" (ByVal hLookup As Long, ByVal dwControlFlags As SearchControlFlags, lpdwBufferLength As Long, lpqsResults As WSAQuerySet) As Integer

Declare Function WSANtohl Lib "ws2_32" (ByVal hSocket As Long, ByVal lpNetLong As Long, lpHostLong As Long) As Integer

Declare Function WSANtohs Lib "ws2_32" (ByVal hSocket As Long, ByVal lpNetShort As Integer, lpHostShort As Integer) As Integer

Declare Function WSAProviderConfigChange Lib "ws2_32" (ByVal lpNotificationHandle As Long, lpOverlapped As WSAOVERLAPPED, ByVal lpCompletionROUTINE As Long) As Integer

Declare Function WSARecvEx Lib "ws2_32" (ByVal hSocket As Long, ByVal lpBuffers As Long, ByVal dwBufferCount As Long, lpNumberOfBytesRecvd As Long, lpFlags As Long, lpOverlapped As WSAOVERLAPPED, ByVal lpCompletionROUTINE As Long) As Integer

Declare Function WSARecvDisconnect Lib "ws2_32" (ByVal hSocket As Long, lpInboundDisconnectData As WSABUF) As Integer

Declare Function WSARecvFrom Lib "ws2_32" (ByVal hSocket As Long, ByVal lpBuffers As Long, ByVal dwBufferCount As Long, lpNumberOfBytesRecvd As Long, lpFlags As Long, lpFrom As SOCKADDR, lpFromlen As Integer, lpOverlapped As WSAOVERLAPPED, ByVal lpCompletionROUTINE As Long) As Integer

Declare Function WSARemoveServiceClass Lib "ws2_32" (lpServiceClassId As CLSID) As Integer

Declare Function WSAResetEvent Lib "ws2_32" (ByVal hEvent As Long) As Boolean

Declare Function WSASend Lib "ws2_32" (ByVal hSocket As Long, ByVal lpBuffers As Long, ByVal dwBufferCount As Long, lpNumberOfBytesSent As Long, ByVal dwFlags As Long, lpOverlapped As WSAOVERLAPPED, ByVal lpCompletionROUTINE As Long) As Integer

Declare Function WSASendDisconnect Lib "ws2_32" (ByVal hSocket As Long, boundDisconnectData As WSABUF) As Integer

Declare Function WSASendTo Lib "ws2_32" (ByVal hSocket As Long, ByVal lpBuffers As Long, ByVal dwBufferCount As Long, lpNumberOfBytesSent As Long, ByVal dwFlags As Long, lpTo As SOCKADDR, ByVal iToLen As Integer, lpOverlapped As WSAOVERLAPPED, ByVal lpCompletionROUTINE As Long) As Integer

Declare Function WSASetEvent Lib "ws2_32" (ByVal hEvent As Long) As Boolean
Declare Sub WSASetLastError Lib "ws2_32" (ByVal iError As Integer)

Enum WSAESETSERVICEOP
  RNRSERVICE_REGISTER = 0
  RNRSERVICE_DEREGISTER = 1
  RNRSERVICE_DELETE = 2
End Enum

Declare Function WSASetService Lib "ws2_32" Alias "WSASetServiceA" (lpqsRegInfo As WSAQuerySet, essOperation As WSAESETSERVICEOP, ByVal dwControlFlags As Long) As Integer

Declare Function WSASocket Lib "ws2_32" Alias "WSASocketA" (ByVal iAddressFamily As Integer, ByVal iType As Integer, ByVal iProtocol As Integer, lpProtocolInfo As WSAPROTOCOL_INFO, ByVal lpGroup As Long, ByVal dwFlags As Long) As Long

Declare Function WSAStartup Lib "ws2_32" (ByVal wVersionRequired As Long, lpWSAData As WSADATA) As Long

Declare Function WSAStringToAddress Lib "ws2_32" (ByVal AddressString As String, ByVal AddressFamily As Integer, lpProtocolInfo As WSAPROTOCOL_INFO, lpAddress As SOCKADDR, lpAddressLength As Integer) As Integer

Public SockLastError As Long

Function sckhibyte(ByVal wParam As Integer)
  sckhibyte = (wParam \ &H100) And &HFF&
End Function

Function scklobyte(ByVal wParam As Integer)
  scklobyte = wParam And &HFF&
End Function

Property Get LocalHostName() As String
     
      Dim sStr As String * 256, lStr&
      Dim r&
     
  r = gethostname(sStr, 256)
  SockLastError = WSAGetLastError()
 
  LocalHostName = Trim(Replace(sStr, vbNullChar, vbNullString))
End Property

Property Get LocalHostIP() As String

   Dim sHostName$, pHostent&
   Dim pHost As HOSTENT
   Dim hIPAddress&, sIPAddress$
   Dim abIPAddress() As Byte
   Dim i%


  sHostName = LocalHostName
  pHostent = gethostbyname(sHostName)
  SockLastError = WSAGetLastError()

  If pHostent = 0 Then Exit Property
 
  CopyMemory ByVal pHost, ByVal pHostent, ByVal LenB(pHost)
  CopyMemory hIPAddress, ByVal pHost.h_addr_list, ByVal 4&

  ReDim abIPAddress(1 To pHost.h_length)
  CopyMemory abIPAddress(1), ByVal hIPAddress, ByVal pHost.h_length

  For i = 1 To pHost.h_length
    sIPAddress = sIPAddress & abIPAddress(i) & "."
  Next
 
  LocalHostIP = Left$(sIPAddress, Len(sIPAddress) - 1)
 
End Property

Sub SocketsInitialize()
      Dim WSAD As WSADATA
      Dim iReturn As Integer
      Dim sLowByte As String, sHighByte As String, sMsg As String

    iReturn = WSAStartup(WS_VERSION_REQD, WSAD)
    SockLastError = WSAGetLastError()

    If iReturn <> 0 Then
      Exit Sub
    End If

    If LoByte(WSAD.wversion) < WS_VERSION_MAJOR Or _
      (LoByte(WSAD.wversion) = WS_VERSION_MAJOR And _
        HiByte(WSAD.wversion) < WS_VERSION_MINOR) Then
       
        Exit Sub
    End If

    If WSAD.iMaxSockets < MIN_SOCKETS_REQD Then
      Exit Sub
    End If

End Sub

Function SocketsCleanup() As Long
  SocketsCleanup = WSACleanup()
End Function

Function CreateSocket(ByVal SockType As SockTypes, Optional ByVal Protocol As SockProtocols = IPPROTO_TCP) As Long
  CreateSocket = socket(AF_NETBIOS, SockType, Protocol)
  SockLastError = WSAGetLastError
End Function

Function DestroySocket(hSocket As Long) As Boolean
  DestroySocket = (closesocket(hSocket) = 0)
  SockLastError = WSAGetLastError
End Function

Function GetSckName(hSocket As Long) As String
      Dim sName$
      Dim pSckAdd As SOCKADDR, lpAdd&
      Dim r&
 
  r = GetSockNameA(hSocket, lpAdd, LenB(pSckAdd))
  SockLastError = WSAGetLastError
 
  CopyMemory ByVal pSckAdd, ByVal lpAdd, ByVal LenB(pSckAdd)
 
  GetSckName = Trim(Replace(pSckAdd.sa_data, vbNullChar, vbNullString))
 
End Function

Saludos.


« Última modificación: 22 Marzo 2005, 08:25 am por Slasher Keeper » En línea



A la reina de las profundidades que cuida los pasos de una sombra en la noche :*
c0rrupt_gamer


Desconectado Desconectado

Mensajes: 764



Ver Perfil
Re: API de WinSock para VB (Completa)
« Respuesta #1 en: 21 Marzo 2005, 22:32 pm »

Muchisimas gracias, esto si k es unpost con utilidad! ;D

Ahora mismo me pongo a mirar lo k necesito.

Saludos


En línea

c0rrupt_gamer


Desconectado Desconectado

Mensajes: 764



Ver Perfil
Re: API de WinSock para VB (Completa)
« Respuesta #2 en: 21 Marzo 2005, 22:53 pm »

Perdon pero es k al ponerlo en un modulo bas, la parte k dice:

Código:
Type CSADDR_INFO
  LocalAddr As SOCKET_ADDRESS
  RemoteAddr As SOCKET_ADDRESS
  iSocketType As Integer
  iProtocol As Integer
End Type

me da un error, solo habiendolo copiado, aun no he hecho ninguna modificacion, me dice k CSADDR_INFO es un nombre ambiguo o algo asi...
A k se refiere el VB?
En línea

byebye


Desconectado Desconectado

Mensajes: 5.093



Ver Perfil
Re: API de WinSock para VB (Completa)
« Respuesta #3 en: 22 Marzo 2005, 01:29 am »

que esta repetido. revisa el codigo.
En línea

c0rrupt_gamer


Desconectado Desconectado

Mensajes: 764



Ver Perfil
Re: API de WinSock para VB (Completa)
« Respuesta #4 en: 22 Marzo 2005, 01:51 am »

gracias, ahora mismo lo hago
En línea

Slasher-K


Desconectado Desconectado

Mensajes: 1.477


Ver Perfil
Re: API de WinSock para VB (Completa)
« Respuesta #5 en: 22 Marzo 2005, 08:27 am »

Ya lo arreglé, disculpen el error pero lo que pasa es que son muchas declaraciones :P
En línea



A la reina de las profundidades que cuida los pasos de una sombra en la noche :*
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
HTC cierra HTC Sense para someterla a una remodelación completa
Noticias
wolfbcn 0 1,318 Último mensaje 27 Marzo 2012, 14:41 pm
por wolfbcn
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines