diff options
Diffstat (limited to 'src/nat/libnatpmp/natpmp.h')
-rw-r--r-- | src/nat/libnatpmp/natpmp.h | 202 |
1 files changed, 0 insertions, 202 deletions
diff --git a/src/nat/libnatpmp/natpmp.h b/src/nat/libnatpmp/natpmp.h deleted file mode 100644 index 976bad06f..000000000 --- a/src/nat/libnatpmp/natpmp.h +++ /dev/null | |||
@@ -1,202 +0,0 @@ | |||
1 | /* $Id: natpmp.h,v 1.11 2009/02/27 22:38:05 nanard Exp $ */ | ||
2 | /* libnatpmp | ||
3 | * Copyright (c) 2007-2008, Thomas BERNARD <miniupnp@free.fr> | ||
4 | * http://miniupnp.free.fr/libnatpmp.html | ||
5 | * | ||
6 | * Permission to use, copy, modify, and/or distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ | ||
17 | #ifndef __NATPMP_H__ | ||
18 | #define __NATPMP_H__ | ||
19 | |||
20 | /* NAT-PMP Port as defined by the NAT-PMP draft */ | ||
21 | #define NATPMP_PORT (5351) | ||
22 | |||
23 | #include <stdint.h> | ||
24 | #include <time.h> | ||
25 | #include <sys/time.h> | ||
26 | #ifdef WIN32 | ||
27 | #include <winsock2.h> | ||
28 | #include <stdint.h> | ||
29 | #define in_addr_t uint32_t | ||
30 | #include "declspec.h" | ||
31 | #else | ||
32 | #define LIBSPEC | ||
33 | #include <netinet/in.h> | ||
34 | #include <sys/socket.h> | ||
35 | #endif | ||
36 | |||
37 | typedef struct | ||
38 | { | ||
39 | int s; /* socket */ | ||
40 | struct sockaddr *addr; | ||
41 | socklen_t addrlen; | ||
42 | uint8_t gateway[16]; /* default gateway (IPv4 or IPv6) */ | ||
43 | int has_pending_request; | ||
44 | unsigned char pending_request[12]; | ||
45 | int pending_request_len; | ||
46 | int try_number; | ||
47 | struct timeval retry_time; | ||
48 | } natpmp_t; | ||
49 | |||
50 | typedef struct | ||
51 | { | ||
52 | uint16_t type; /* NATPMP_RESPTYPE_* */ | ||
53 | uint16_t resultcode; /* NAT-PMP response code */ | ||
54 | uint32_t epoch; /* Seconds since start of epoch */ | ||
55 | union | ||
56 | { | ||
57 | struct | ||
58 | { | ||
59 | int family; | ||
60 | struct in_addr addr; | ||
61 | struct in6_addr addr6; | ||
62 | } publicaddress; | ||
63 | struct | ||
64 | { | ||
65 | uint16_t privateport; | ||
66 | uint16_t mappedpublicport; | ||
67 | uint32_t lifetime; | ||
68 | } newportmapping; | ||
69 | } pnu; | ||
70 | } natpmpresp_t; | ||
71 | |||
72 | /* possible values for type field of natpmpresp_t */ | ||
73 | #define NATPMP_RESPTYPE_PUBLICADDRESS (0) | ||
74 | #define NATPMP_RESPTYPE_UDPPORTMAPPING (1) | ||
75 | #define NATPMP_RESPTYPE_TCPPORTMAPPING (2) | ||
76 | |||
77 | /* Values to pass to sendnewportmappingrequest() */ | ||
78 | #define NATPMP_PROTOCOL_UDP (1) | ||
79 | #define NATPMP_PROTOCOL_TCP (2) | ||
80 | |||
81 | /* return values */ | ||
82 | /* NATPMP_ERR_INVALIDARGS : invalid arguments passed to the function */ | ||
83 | #define NATPMP_ERR_INVALIDARGS (-1) | ||
84 | /* NATPMP_ERR_SOCKETERROR : socket() failed. check errno for details */ | ||
85 | #define NATPMP_ERR_SOCKETERROR (-2) | ||
86 | /* NATPMP_ERR_CANNOTGETGATEWAY : can't get default gateway IP */ | ||
87 | #define NATPMP_ERR_CANNOTGETGATEWAY (-3) | ||
88 | /* NATPMP_ERR_CLOSEERR : close() failed. check errno for details */ | ||
89 | #define NATPMP_ERR_CLOSEERR (-4) | ||
90 | /* NATPMP_ERR_RECVFROM : recvfrom() failed. check errno for details */ | ||
91 | #define NATPMP_ERR_RECVFROM (-5) | ||
92 | /* NATPMP_ERR_NOPENDINGREQ : readnatpmpresponseorretry() called while | ||
93 | * no NAT-PMP request was pending */ | ||
94 | #define NATPMP_ERR_NOPENDINGREQ (-6) | ||
95 | /* NATPMP_ERR_NOGATEWAYSUPPORT : the gateway does not support NAT-PMP */ | ||
96 | #define NATPMP_ERR_NOGATEWAYSUPPORT (-7) | ||
97 | /* NATPMP_ERR_CONNECTERR : connect() failed. check errno for details */ | ||
98 | #define NATPMP_ERR_CONNECTERR (-8) | ||
99 | /* NATPMP_ERR_WRONGPACKETSOURCE : packet not received from the network gateway */ | ||
100 | #define NATPMP_ERR_WRONGPACKETSOURCE (-9) | ||
101 | /* NATPMP_ERR_SENDERR : send() failed. check errno for details */ | ||
102 | #define NATPMP_ERR_SENDERR (-10) | ||
103 | /* NATPMP_ERR_FCNTLERROR : fcntl() failed. check errno for details */ | ||
104 | #define NATPMP_ERR_FCNTLERROR (-11) | ||
105 | /* NATPMP_ERR_GETTIMEOFDAYERR : gettimeofday() failed. check errno for details */ | ||
106 | #define NATPMP_ERR_GETTIMEOFDAYERR (-12) | ||
107 | /* NATPMP_ERR_BINDERROR : bind() failed. check errno for details */ | ||
108 | #define NATPMP_ERR_BINDERROR (-13) | ||
109 | /* NATPMP_ERR_ADDRERROR : gateway does not use the same inet protocol as the passed address */ | ||
110 | #define NATPMP_ERR_ADDRERROR (-14) | ||
111 | |||
112 | /* */ | ||
113 | #define NATPMP_ERR_UNSUPPORTEDVERSION (-15) | ||
114 | #define NATPMP_ERR_UNSUPPORTEDOPCODE (-16) | ||
115 | |||
116 | /* Errors from the server : */ | ||
117 | #define NATPMP_ERR_UNDEFINEDERROR (-49) | ||
118 | #define NATPMP_ERR_NOTAUTHORIZED (-51) | ||
119 | #define NATPMP_ERR_NETWORKFAILURE (-52) | ||
120 | #define NATPMP_ERR_OUTOFRESOURCES (-53) | ||
121 | |||
122 | /* NATPMP_TRYAGAIN : no data available for the moment. try again later */ | ||
123 | #define NATPMP_TRYAGAIN (-100) | ||
124 | |||
125 | /* initnatpmp() | ||
126 | * initialize a natpmp_t object | ||
127 | * Return values : | ||
128 | * 0 = OK | ||
129 | * NATPMP_ERR_INVALIDARGS | ||
130 | * NATPMP_ERR_SOCKETERROR | ||
131 | * NATPMP_ERR_FCNTLERROR | ||
132 | * NATPMP_ERR_CANNOTGETGATEWAY | ||
133 | * NATPMP_ERR_CONNECTERR */ | ||
134 | LIBSPEC int initnatpmp (natpmp_t * p); | ||
135 | |||
136 | /* closenatpmp() | ||
137 | * close resources associated with a natpmp_t object | ||
138 | * Return values : | ||
139 | * 0 = OK | ||
140 | * NATPMP_ERR_INVALIDARGS | ||
141 | * NATPMP_ERR_CLOSEERR */ | ||
142 | LIBSPEC int closenatpmp (natpmp_t * p); | ||
143 | |||
144 | /* sendpublicaddressrequest() | ||
145 | * send a public address NAT-PMP request to the network gateway | ||
146 | * Return values : | ||
147 | * 2 = OK (size of the request) | ||
148 | * NATPMP_ERR_INVALIDARGS | ||
149 | * NATPMP_ERR_SENDERR */ | ||
150 | LIBSPEC int sendpublicaddressrequest (natpmp_t * p); | ||
151 | |||
152 | /* sendnewportmappingrequest() | ||
153 | * send a new port mapping NAT-PMP request to the network gateway | ||
154 | * Arguments : | ||
155 | * protocol is either NATPMP_PROTOCOL_TCP or NATPMP_PROTOCOL_UDP, | ||
156 | * lifetime is in seconds. | ||
157 | * To remove a port mapping, set lifetime to zero. | ||
158 | * To remove all port mappings to the host, set lifetime and both ports | ||
159 | * to zero. | ||
160 | * Return values : | ||
161 | * 12 = OK (size of the request) | ||
162 | * NATPMP_ERR_INVALIDARGS | ||
163 | * NATPMP_ERR_SENDERR */ | ||
164 | LIBSPEC int sendnewportmappingrequest (natpmp_t * p, int protocol, | ||
165 | uint16_t privateport, | ||
166 | uint16_t publicport, | ||
167 | uint32_t lifetime); | ||
168 | |||
169 | /* getnatpmprequesttimeout() | ||
170 | * fills the timeval structure with the timeout duration of the | ||
171 | * currently pending NAT-PMP request. | ||
172 | * Return values : | ||
173 | * 0 = OK | ||
174 | * NATPMP_ERR_INVALIDARGS | ||
175 | * NATPMP_ERR_GETTIMEOFDAYERR | ||
176 | * NATPMP_ERR_NOPENDINGREQ */ | ||
177 | LIBSPEC int getnatpmprequesttimeout (natpmp_t * p, struct timeval *timeout); | ||
178 | |||
179 | /* readnatpmpresponseorretry() | ||
180 | * fills the natpmpresp_t structure if possible | ||
181 | * Return values : | ||
182 | * 0 = OK | ||
183 | * NATPMP_TRYAGAIN | ||
184 | * NATPMP_ERR_INVALIDARGS | ||
185 | * NATPMP_ERR_NOPENDINGREQ | ||
186 | * NATPMP_ERR_NOGATEWAYSUPPORT | ||
187 | * NATPMP_ERR_RECVFROM | ||
188 | * NATPMP_ERR_WRONGPACKETSOURCE | ||
189 | * NATPMP_ERR_UNSUPPORTEDVERSION | ||
190 | * NATPMP_ERR_UNSUPPORTEDOPCODE | ||
191 | * NATPMP_ERR_NOTAUTHORIZED | ||
192 | * NATPMP_ERR_NETWORKFAILURE | ||
193 | * NATPMP_ERR_OUTOFRESOURCES | ||
194 | * NATPMP_ERR_UNSUPPORTEDOPCODE | ||
195 | * NATPMP_ERR_UNDEFINEDERROR */ | ||
196 | LIBSPEC int readnatpmpresponseorretry (natpmp_t * p, natpmpresp_t * response); | ||
197 | |||
198 | #ifdef ENABLE_STRNATPMPERR | ||
199 | LIBSPEC const char *strnatpmperr (int t); | ||
200 | #endif | ||
201 | |||
202 | #endif | ||