int main(int argc, char * * argv) { int uid; openlog("testiptpinhole", LOG_PERROR|LOG_CONS, LOG_LOCAL0); uid = add_pinhole("eth0", NULL, 0, "ff::123", 54321, IPPROTO_TCP); return 0; }
/* upnp_add_inboundpinhole() * returns: 1 on success * -1 Pinhole space exhausted * -4 invalid arguments * -42 not implemented * TODO : return uid on success (positive) or error value (negative) */ int upnp_add_inboundpinhole(const char * raddr, unsigned short rport, const char * iaddr, unsigned short iport, int proto, char * desc, unsigned int leasetime, int * uid) { int r; time_t current; unsigned int timestamp; struct in6_addr address; r = inet_pton(AF_INET6, iaddr, &address); if(r <= 0) { syslog(LOG_ERR, "inet_pton(%d, %s, %p) FAILED", AF_INET6, iaddr, &address); return -4; } current = time(NULL); timestamp = current + leasetime; r = 0; *uid = upnp_find_inboundpinhole(raddr, rport, iaddr, iport, proto, NULL, 0, NULL); if(*uid >= 0) { syslog(LOG_INFO, "Pinhole for inbound traffic from [%s]:%hu to [%s]:%hu with proto %d found uid=%d. Updating it.", raddr, rport, iaddr, iport, proto, *uid); r = upnp_update_inboundpinhole(*uid, timestamp); return (r >= 0) ? 1 : r; } #if defined(USE_PF) || defined(USE_NETFILTER) *uid = add_pinhole (0/*ext_if_name*/, raddr, rport, iaddr, iport, proto, desc, timestamp); return *uid >= 0 ? 1 : -1; #else return -42; /* not implemented */ #endif }