Announcement

Collapse
No announcement yet.

UPnP services...

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

  • UPnP services...

    Hi All,

    I had found some stuff about UPnP and NAT.
    Source code is available at:
    http://sourceforge.net/projects/libnat/

    My first aproach is this:

    Code:
    #compile exe
    
    type UpnpController
      control_url 	as string * 15
      service_type	as string * 512 
    end type
    
    Declare Function LNat_Upnp_Discover  cdecl Lib "libnat.dll" Alias "LNat_Upnp_Discover" ( upnp as UpnpController ) as long
    Declare Function LNat_Upnp_Get_Public_Ip cdecl Lib "libnat.dll" Alias "LNat_Upnp_Get_Public_Ip" ( upnp as UpnpController, IP as asciiz, ip_len as long ) as long
    Declare Function LNat_Upnp_Controller_Free  cdecl Lib "libnat.dll" Alias "LNat_Upnp_Controller_Free" ( upnp as UpnpController ) as long
    
    function pbmain()
    local ip as asciiz * 15, result as long, ip_len as long
    local upnp as UpnpController
    ip = "255.255.255.255"
    ip_len = Sizeof(ip)
    
    result = LNat_Upnp_Discover(upnp)
    if result <> 0 then msgbox "Failed at Router comunication" : exit function
    
    result = LNat_Upnp_Get_Public_Ip (upnp, ip, ip_len)
    if result <> 0 then msgbox "Router is not UPnP compatible" : exit function
    
    result = LNat_Upnp_Controller_Free(upnp)
    MsgBox ip
    
    end function
    But doesn't work.
    Any ideas ?

    Thanks in advance,
    David Marcovich

  • #2
    I haven't executed the code as I have UPnP turned off, but looking I see the following.

    Code:
    local ip as Asciiz * 15 should be local ip as ASciiz * 16 ' Need extra byte for ending chr$(0)
    I did not double check the declares. AsciiZ might need to be string.


    Most home routers have an option to have UPnP turned off and businesses definately do. At least anyone who is worried about security. You don't want someone (hacker) changing your router to allow complete access into your LAN.

    Comment


    • #3
      Thanks Brian,

      I think you are right.
      I need know the external IP of a routered PC in order to allow IP to IP chat.
      I don't know how MSN works, but I need some like this...

      Any ideas are welcomed.

      Thanks in advance,
      David de Argentina

      Comment


      • #4
        Are you writing your own chat program? If not, what chat program are you using?

        If your using one of the major chat programs, you can configure your router to allow specific ports through. There are many sites that list the port numbers. google "TCP PORTs appname"

        MSN Messenger info can be found here. support.microsoft.com/kb/240063

        You may also have to allow the application through any firewalls installed.

        Comment


        • #5
          The structure must be declared as

          Code:
          TYPE UpnpController
            control_url     AS ASCIIZ PTR
            service_type    AS ASCIIZ PTR
          END TYPE
          Original C declaration:

          Code:
          /* UpnpController structure definition */
          struct LIBNAT_API UpnpController
          {
            char * control_url;
            char * service_type;
          };
          and the ip_len parameter of the LNat_Upnp_Get_Public_Ip function must be BYVAL.
          Forum: http://www.jose.it-berater.org/smfforum/index.php

          Comment

          Working...
          X