comparison libpurple/nat-pmp.h @ 15646:552be3958d6a

Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
author Evan Schoenberg <evan.s@dreskin.net>
date Sun, 18 Feb 2007 18:26:55 +0000
parents
children 32c366eeeb99
comparison
equal deleted inserted replaced
15645:61b42cf81aa4 15646:552be3958d6a
1 /**
2 * @file nat-pmp.h NAT-PMP Implementation
3 * @ingroup core
4 *
5 * gaim
6 *
7 * Gaim is the legal property of its developers, whose names are too numerous
8 * to list here. Please refer to the COPYRIGHT file distributed with this
9 * source distribution.
10 *
11 * Most code in nat-pmp.h copyright (C) 2007, R. Tyler Ballance, bleep, LLC.
12 * This file is distributed under the 3-clause (modified) BSD license:
13 * Redistribution and use in source and binary forms, with or without modification, are permitted
14 * provided that the following conditions are met:
15 *
16 * Redistributions of source code must retain the above copyright notice, this list of conditions and
17 * the following disclaimer.
18 * Neither the name of the bleep. LLC nor the names of its contributors may be used to endorse or promote
19 * products derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28 * OF SUCH DAMAGE.
29 */
30
31 #ifndef _PMPMAPPER_H
32 #define _PMPMAPPER_H
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <errno.h>
37 #include <assert.h>
38 #include <sys/socket.h>
39 #include <sys/sysctl.h>
40 #include <sys/types.h>
41 #include <net/if.h>
42 #include <net/route.h>
43
44 #define PMP_VERSION 0
45 #define PMP_PORT 5351
46 #define PMP_TIMEOUT 250000 // 250000 useconds
47 #define PMP_LIFETIME 3600 // 3600 seconds
48
49 #define PMP_MAP_UDP 1
50 #define PMP_MAP_TCP 2
51
52 /*
53 * uint8_t: version, opcodes
54 * uint16_t: resultcode
55 * unint32_t: epoch (seconds since mappings reset)
56 */
57
58 typedef struct {
59 uint8_t version;
60 uint8_t opcode;
61 } pmp_ip_request_t;
62
63 typedef struct {
64 uint8_t version;
65 uint8_t opcode; // 128 + n
66 uint16_t resultcode;
67 uint32_t epoch;
68 uint32_t address;
69 } pmp_ip_response_t;
70
71 typedef struct {
72 uint8_t version;
73 uint8_t opcode;
74 char reserved[2];
75 uint16_t privateport;
76 uint16_t publicport;
77 uint32_t lifetime;
78 } pmp_map_request_t;
79
80 typedef struct {
81 uint8_t version;
82 uint8_t opcode;
83 uint16_t resultcode;
84 uint32_t epoch;
85 uint16_t privateport;
86 uint16_t publicport;
87 uint32_t lifetime;
88 } pmp_map_response_t;
89
90 char *gaim_pmp_get_public_ip();
91 pmp_map_response_t *gaim_pmp_create_map(uint8_t type, uint16_t privateport, uint16_t publicport, uint32_t lifetime);
92 pmp_map_response_t *gaim_pmp_destroy_map(uint8_t type, uint16_t privateport);
93
94 #endif