more tests in testnftpinhole.c

This commit is contained in:
Thomas Bernard 2023-11-16 22:06:40 +01:00
parent 80d628fa59
commit b3b5dd16d2
No known key found for this signature in database
GPG Key ID: DB511043A31ACAAF
1 changed files with 40 additions and 0 deletions

View File

@ -19,6 +19,32 @@
struct lan_addr_list lan_addrs; struct lan_addr_list lan_addrs;
time_t startup_time = 0; time_t startup_time = 0;
static void print_infos(unsigned short uid)
{
char rem_host[64];
unsigned short rem_port;
char int_client[64];
unsigned short int_port;
int proto;
char desc[256];
unsigned int timestamp;
u_int64_t packets, bytes;
int ret;
ret = get_pinhole_info(uid,
rem_host, sizeof(rem_host), &rem_port,
int_client, sizeof(int_client), &int_port,
&proto, desc, sizeof(desc), &timestamp,
&packets, &bytes);
if (ret < 0) {
syslog(LOG_WARNING, "get_pinhole_info(%d) returned %d", uid, ret);
} else {
syslog(LOG_INFO, "get_pinhole_info(%d) : %s:%hu => %s:%hu %s",
uid, rem_host, rem_port, int_client, int_port, proto==IPPROTO_TCP ? "tcp" : "udp");
syslog(LOG_INFO, " desc \"%s\" ts=%u packets=%llu %llu",
desc, timestamp, (long long unsigned)packets, (long long unsigned)bytes);
}
}
int main(int argc, char * * argv) int main(int argc, char * * argv)
{ {
int uid; int uid;
@ -35,10 +61,24 @@ int main(int argc, char * * argv)
uid = add_pinhole(ifname, rem_host, rem_port, int_client, int_port, IPPROTO_TCP, uid = add_pinhole(ifname, rem_host, rem_port, int_client, int_port, IPPROTO_TCP,
"dummy description", upnp_time() + 60 /* timestamp */); "dummy description", upnp_time() + 60 /* timestamp */);
syslog(LOG_INFO, "add_pinhole(): uid=%d", uid); syslog(LOG_INFO, "add_pinhole(): uid=%d", uid);
if (uid >= 0) print_infos(uid);
uid = find_pinhole(ifname, rem_host, rem_port, int_client, int_port, IPPROTO_TCP, uid = find_pinhole(ifname, rem_host, rem_port, int_client, int_port, IPPROTO_TCP,
desc, sizeof(desc), &timestamp); desc, sizeof(desc), &timestamp);
syslog(LOG_INFO, "find_pinhole(): uid=%d desc=\"%s\" timestamp=%u", uid, desc, timestamp); syslog(LOG_INFO, "find_pinhole(): uid=%d desc=\"%s\" timestamp=%u", uid, desc, timestamp);
if (uid >= 0) {
int r;
print_infos(uid);
r = update_pinhole(uid, upnp_time() + 3600);
syslog(LOG_INFO, "update_pinhole(%d, ...) returned %d", uid, r);
print_infos(uid);
r = delete_pinhole(uid);
syslog(LOG_INFO, "delete_pinhole(%d) returned %d", uid, r);
}
return 0; return 0;
} }