miniupnp.tuxfamily.org Forum Index miniupnp.tuxfamily.org
The forum about miniupnp and libnatpmp
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

natpmp automatically selecting ports?

 
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> libnatpmp Bugs
View previous topic :: View next topic  
Author Message
dreadslicer



Joined: 23 Jan 2013
Posts: 1

PostPosted: Wed Jan 23, 2013 9:13 pm    Post subject: natpmp automatically selecting ports? Reply with quote

Code:
#include <iostream>
#include <natpmp.h>

using namespace std;


void redirect(uint16_t privateport, uint16_t publicport)
{
  int r;
  natpmp_t natpmp;
  natpmpresp_t response;
  initnatpmp(&natpmp,0,NATPMP_RESPTYPE_UDPPORTMAPPING);
  sendnewportmappingrequest(&natpmp, NATPMP_PROTOCOL_TCP, privateport, publicport, 3600);
  do {
    fd_set fds;
    struct timeval timeout;
    FD_ZERO(&fds);
    FD_SET(natpmp.s, &fds);
    getnatpmprequesttimeout(&natpmp, &timeout);
    select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
    r = readnatpmpresponseorretry(&natpmp, &response);
  } while(r==NATPMP_TRYAGAIN);
  cout << "mapped public port "<<response.pnu.newportmapping.mappedpublicport<<
           " to localport "<<response.pnu.newportmapping.privateport<<" liftime "<<
           response.pnu.newportmapping.lifetime<<"\n";
  closenatpmp(&natpmp);
}


int main (){
   redirect(32000,32000);
}


This code does work, however, it doesn't set the port to 32000:32000... it sets it:

Quote:
mapped public port 20701 to localport 22404 liftime 32539


I'm trying to make a game system and I need these ports open.... I'm going to assume that if it gets the port open, I would THEN start the port listener using a UDP server w/ these special ports?
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1500

PostPosted: Sun Jan 27, 2013 5:34 pm    Post subject: Reply with quote

with NAT-PMP the port mapped is not always the one requested.
So you may ask for 32000 / 32000 and get 20701 / 22404
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> libnatpmp Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP
© 2007 Thomas Bernard, author of MiniUPNP.