AlexeyS
Joined: 27 Sep 2009 Posts: 7
|
Posted: Sun Sep 27, 2009 8:14 am Post subject: reload_from_lease_file |
|
|
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;
}
|
|
|