Announcement

Collapse
No announcement yet.

bound socket can only be connected to from the Internet not the LAN due to adapter??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • bound socket can only be connected to from the Internet not the LAN due to adapter??

    I'm trying to listen on a port, and be able to connect to that port from both a LAN-based workstation and an Internet-based workstation. At the moment I can only have one or the other...

    Im binding a socket using this statement:
    Code:
     TCP OPEN Server ADDR GetAdapter PORT 113 AS hServer TIMEOUT 5
    Where GetAdapter is this function (found somewhere in POFFS):
    Code:
    FUNCTION GetAdapter() AS LONG
        LOCAL sd AS DWORD
        LOCAL nBytesReturned AS DWORD
        LOCAL i  AS LONG
        LOCAL lerr AS LONG
        LOCAL lReturn AS LONG
        LOCAL nNumInterfaces AS INTEGER
        LOCAL sDisplay AS STRING
        LOCAL sBuff AS STRING * 760                   '' allow max 10 interfaces
        LOCAL pszHost AS ASCIIZ PTR
        sd    = WSASocket(%AF_INET, %SOCK_DGRAM, 0, BYVAL 0, 0, 0)
        IF sd = %SOCKET_ERROR THEN EXIT FUNCTION
        lReturn = WSAIoctl(BYVAL sd, %SIO_GET_INTERFACE_LIST, 0, 0, VARPTR( sBuff ), _
                           LEN(sBuff), nBytesReturned, BYVAL 0, BYVAL 0 )
        lerr    = WSAGetLastError()
        IF lreturn = %SOCKET_ERROR THEN
           'STDOUT "lReturn " + $TAB + STR$( lreturn ) + $CRLF + "lerr " + $TAB + STR$( lerr )
           EXIT FUNCTION
        END IF
        closesocket sd
        WSACleanup
        DIM zz AS LONG
        FUNCTION = CVL(MID$(sBuff, %ADAPTER * %INTERFACE_RECLEN + 9, %IP_Len))
    END FUNCTION
    The problem:
    When it binds to an adapter (eg. the same adapter that my modem/internet uses), only Internet-based sockets can connect to it... I can't telnet to the port from a different workstation in my LAN
    If I change it to bind to adapter 1 instead of 0, it's the opposite - I can connect from my LAN, but not from the Internet...
    I noticed that when I load a socket in Visual Basic, it seems to bind to _all_ adapters... so what do I have to do to create a socket that can be connected to from both the Internet _and_ my LAN?

    Any help is much appreciated!
    Thanks,
    Wayne


    ------------------
    -

  • #2
    Interesting...

    You have to open two ports on your machine, one for each IP address.

    I'm assuming one is dialed up and the other is lan but not I-net connected?


    I'm not sure how VB does it but I'm pretty sure you can only bind to one adapter at a time unless you open a port on each....


    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment


    • #3
      Here are the interfaces on my workstation (i go through the LAN out the server to get to the Internet)
      Code:
      #            ADDRESS         BROADCAST            NETMASK
      167772170    10.0.0.10       255.255.255.255      255.255.255.0
      16777343     127.0.0.1       255.255.255.255      255.0.0.0
      2 interfaces found.
      And here's what I get on my server, which has a modem on it etc:
      Code:
      #            IP              BCAST                NETMASK
      2102336203   203.22.1.122    255.255.255.255      255.255.255.0
      33554442     10.0.0.2        255.255.255.255      255.255.255.0
      16777343     127.0.0.1       255.255.255.255      255.0.0.0
      3 interfaces found.
      So, perhaps I need to enumerate through the adapters and bind to all the ones that aren't 127.0.0.1 ...
      I wonder how Visual Basic does it - VB sockets seem to (according to netstat) bind to all adapters, so im assuming to do that it has to load multiple sockets?



      [This message has been edited by Wayne Diamond (edited January 17, 2001).]
      -

      Comment


      • #4
        hi wayne

        to bind an address to all interfaces you need to use inaddr_any. for
        a discussion of this and an example look at:
        http://www.powerbasic.com/support/pb...ad.php?t=17653

        note that as far as i know the pb implementation does not support
        this so you *may* have to resort to using the api.

        ymmv

        florent




        [this message has been edited by florent heyworth (edited january 17, 2001).]

        Comment

        Working...
        X