• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

2 Network Cards and VB ( More points available)

On an Upcoming project, I'm going to have an application running on a PC with two network cards, and using Winsock controls on both networks.

Is there any special considerations for this, or is it just the same as using one network.

If neccesary I'll up the points for a coded solution ( if one is required ).

Gordon
0
Gordonp
Asked:
Gordonp
  • 3
  • 2
1 Solution
 
GogmanCommented:
The major consideration you must deal with is proper binding of the IP addresses to the Winsock control. Multiple Winsock controls will bind to the same IP address and NIC unless told to do otherwise. Check out the MS Winsock documentation on the Bind method for details on the method.

Now, you'll need to know what IP addresses you have on the system. Well, you may already know all the IPs, but if you are going to spread this program around, there should be some sort of configuration screen. It's very easy to list all the given IP addresses on a system. Here's some code that you can flop into a form that will do just that:

----- BOF -----

Option Base 0
Option Explicit
Option Compare Binary

Private Type MIBIPADDRROW

  dwAddr As Long            ' IP address
  dwIndex As Long           ' interface index
  dwMask As Long            ' subnet mask
  dwBCastAddr As Long       ' broadcast address
  dwReasmSize As Long       ' rassembly size
  unused As Long            ' not currently used

End Type

Private Type MIBIPADDRTABLE

  dwNumEntries As Long      ' number of entries in the table
  table() As MIBIPADDRROW   ' array of IP address entries

End Type

Private Declare Function GetIpAddrTable Lib "IPHLPAPI.DLL" _
  (PMIB_IPADDRTABLE As Byte, PUSIZE As Long, _
  ByVal bOrder As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
  (dst As Any, src As Any, ByVal bcount As Long)
 
Private Sub Form_Load()

    Dim n As Long
    Dim x As Long
    Dim lRow As Long

    Dim bytbuff() As Byte

    Dim uRow As MIBIPADDRROW
    Dim uTable As MIBIPADDRTABLE

    ReDim uTable.table(1 To 1)
    ReDim bytbuff(1 To 1)

    uTable.dwNumEntries = 0

    n = 0

    x = GetIpAddrTable(bytbuff(1), n, False)

    If n > 0 Then

        ReDim bytbuff(1 To n)

        x = GetIpAddrTable(bytbuff(1), n, False)

        Call CopyMemory(uTable, bytbuff(1), 4)

        If uTable.dwNumEntries > 0 Then

            ReDim uTable.table(1 To uTable.dwNumEntries)

            lRow = LenB(uRow)

            For x = 1 To uTable.dwNumEntries

                Call CopyMemory(uTable.table(x), bytbuff((x - 1) * lRow + 5), lRow)

                Me.Print "IP " & CStr(x) & ": " & BytesFrom(uTable.table(x).dwAddr) & _
                " Mask: " & BytesFrom(uTable.table(x).dwMask)

            Next x

        End If

    End If

End Sub

Private Function BytesFrom(ByVal addr As Long) As String

    Dim sOut As String
    Dim b(1 To 4) As Byte

    Call CopyMemory(b(1), addr, 4)

    sOut = CStr(b(1)) & "." & CStr(b(2)) & "." & CStr(b(3)) & "." & CStr(b(4))

    BytesFrom = sOut

End Function

----- EOF -----

You can use this code (with slight modification) to populate a list box so you can select the IP addresses you wish to use.

Hope this helps.

gogman
0
 
GordonpAuthor Commented:
SO basically other than using .Bind to set it to use the correct Network Adapter, theres nothing else I need to do.

Gordon

0
 
GogmanCommented:
That is correct. Once you have your WinSock control bind to a given IP, it will work just fine.
0
 
GordonpAuthor Commented:
Thanks for the info, you pretty much confirmed what I'd made out from the VB Docs.

Gordon
0
 
GogmanCommented:
No problem. Good luck!

gogman
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now