Smallers steps to keep plugin running
[oweals/gnunet.git] / src / include / gnunet_nat_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2007, 2008, 2009, 2010 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file include/gnunet_nat_lib.h
23  * @brief Library handling UPnP and NAT-PMP port forwarding and
24  *     external IP address retrieval
25  *
26  * @author Milan Bouchet-Valat
27  */
28
29 #ifndef GNUNET_NAT_LIB_H
30 #define GNUNET_NAT_LIB_H
31
32 #include "gnunet_util_lib.h"
33
34 /**
35  * Signature of the callback passed to GNUNET_NAT_register.
36  *
37  * @param cls closure
38  * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean
39  *     the previous (now invalid) one
40  * @param addr either the previous or the new public IP address
41  * @param addrlen actual lenght of the address
42  */
43 typedef void (*GNUNET_NAT_AddressCallback) (void *cls, 
44                                             int add_remove,
45                                             const struct sockaddr * addr,
46                                             socklen_t addrlen);
47
48
49 /**
50  * Handle for active NAT registrations.
51  */
52 struct GNUNET_NAT_Handle;
53
54 /**
55  * Attempt to enable port redirection and detect public IP address contacting
56  * UPnP or NAT-PMP routers on the local network. Use addr to specify to which
57  * of the local host's addresses should the external port be mapped. The port
58  * is taken from the corresponding sockaddr_in[6] field.
59  *
60  * @param sched the sheduler used in the program
61  * @param addr the local address packets should be redirected to
62  * @param addrlen actual lenght of the address
63  * @param callback function to call everytime the public IP address changes
64  * @param callback_cls closure for callback
65  * @return NULL on error, otherwise handle that can be used to unregister 
66  */
67 struct GNUNET_NAT_Handle *
68 GNUNET_NAT_register (struct GNUNET_SCHEDULER_Handle *sched,
69                      const struct sockaddr *addr,
70                      socklen_t addrlen,
71                      GNUNET_NAT_AddressCallback callback, 
72                      void *callback_cls);
73
74
75 /**
76  * Stop port redirection and public IP address detection for the given handle.
77  * This frees the handle, after having sent the needed commands to close open ports.
78  *
79  * @param h the handle to stop
80  */
81 void GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h);
82
83 #endif 
84
85 /* end of gnunet_nat_lib.h */