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 

reload_from_lease_file

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



Joined: 27 Sep 2009
Posts: 7

PostPosted: Sun Sep 27, 2009 8:14 am    Post subject: reload_from_lease_file Reply with quote

Function reload_from_lease_file() leads the line in the lease file to the form of "String \n\n" instead of "String \n". My solution is to bring reload_from_lease_file() to the form:
Code:
int reload_from_lease_file()
{
   FILE * fd;
   char * p = NULL;
   char * eport, iport;
   char * proto;
   char * iaddr;
   char * desc;
   char line[128];
   int r;

   if(!lease_file) return -1;
   fd = fopen( lease_file, "r");
   if (fd==NULL) {
      syslog(LOG_ERR, "could not open lease file: %s", lease_file);
      return -1;
   }
   if(unlink(lease_file) < 0) {
      syslog(LOG_WARNING, "could not unlink file %s : %m", lease_file);
   }

   while(fgets(line, sizeof(line), fd)) {
      syslog(LOG_DEBUG, "parsing lease file line '%s'", line);
      proto = strtok_r(line, ":\n", &p);
      eport = strtok_r(NULL, ":\n", &p);
      iaddr = strtok_r(NULL, ":\n", &p);
      iport = strtok_r(NULL, ":\n", &p);
      desc  = strtok_r(NULL, ":\n", &p);
      if (!proto) || (!eport) || (!iaddr) || (!iport) || (!desc) {
         syslog(LOG_ERR, "unrecognized data in lease file");
         continue;
      }

      r = upnp_redirect((unsigned short)atoi(*eport), iaddr, (unsigned short)atoi(*iport), proto, desc);
      if(r == -1) {
         syslog(LOG_ERR, "Failed to redirect %hu -> %s:%hu protocol %s",
                (unsigned short)atoi(*eport), iaddr, (unsigned short)atoi(*iport), proto);
      } else if(r == -2) {
         /* Add the redirection again to the lease file */
         lease_file_add((unsigned short)atoi(*eport), iaddr, (unsigned short)atoi(*iport), proto_atoi(proto), desc);
      }
   }
   fclose(fd);
   
   return 0;
}
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Sat Oct 10, 2009 7:29 pm    Post subject: Reply with quote

I made some changes :
see miniupnpd-20091010.tar.gz
_________________
Main miniUPnP author.
https://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 -> miniupnpd 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.