If you find that this library lacks some feature you need, or you have a suggestion for improving it, please don’t hesitate to get in touch with me!
This library implements NAT-PMP, the Apple/IETF protocol for opening TCP and UDP ports on home routers.
Using this library, you can discover the external IP address of your home router, and can manage port mappings from the public internet to internal TCP and UDP ports.
NAT-PMP is currently defined in an Internet-Draft.
All the functionality below can be accessed with a single require:
|(require (planet tonyg/nat-pmp:1:=1))|
NAT-PMP depends on being able to learn the IP address of the current default gateway. Currently, this library learns this information by running the system utility netstat and parsing its output.
Requests made to the gateway using NAT-PMP will eventually time out if the gateway does not support NAT-PMP. In this case, an exception is raised.
If you can’t or don’t want to use the persistent mapping support of this library, these routines let you explicitly manage mappings with the gateway.
(make-persistent-mapping protocol local-port requested-port [ #:refresh-interval refresh-interval #:on-mapping on-mapping]) → persistent-mapping? protocol : (or/c 'udp 'tcp) local-port : integer? requested-port : integer? refresh-interval : integer? = 7200 on-mapping : (-> mapping? any/c) = void
Every time the externally mapped port changes (including when the mapping is first established!) the #:on-mapping callback is called with the updated mapping information. Note that the callback is invoked directly from the mapping’s thread - if it raises an exception, it will kill the persistent mapping.
(struct persistent-mapping (thread) #:extra-constructor-name make-persistent-mapping #:prefab) thread : thread?