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
LVL 3
GordonpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.