8487
|
1 /**
|
|
2 * @file mdns.h Multicast DNS connection code used by rendezvous.
|
|
3 *
|
|
4 * gaim
|
|
5 *
|
|
6 * Gaim is the legal property of its developers, whose names are too numerous
|
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
8 * source distribution.
|
|
9 *
|
|
10 * This program is free software; you can redistribute it and/or modify
|
|
11 * it under the terms of the GNU General Public License as published by
|
|
12 * the Free Software Foundation; either version 2 of the License, or
|
|
13 * (at your option) any later version.
|
|
14 *
|
|
15 * This program is distributed in the hope that it will be useful,
|
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 * GNU General Public License for more details.
|
|
19 *
|
|
20 * You should have received a copy of the GNU General Public License
|
|
21 * along with this program; if not, write to the Free Software
|
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
23 *
|
|
24 */
|
|
25
|
|
26 #ifndef _MDNS_H_
|
|
27 #define _MDNS_H_
|
|
28
|
8546
|
29 #include "internal.h"
|
8487
|
30 #include "debug.h"
|
|
31
|
|
32 /*
|
|
33 * Some #define's stolen from libfaim. Used to put
|
|
34 * binary data (bytes, shorts and ints) into an array.
|
|
35 */
|
|
36 #define util_put8(buf, data) ((*(buf) = (unsigned char)(data)&0xff),1)
|
|
37 #define util_put16(buf, data) ( \
|
|
38 (*(buf) = (unsigned char)((data)>>8)&0xff), \
|
|
39 (*((buf)+1) = (unsigned char)(data)&0xff), \
|
|
40 2)
|
|
41 #define util_put32(buf, data) ( \
|
|
42 (*((buf)) = (unsigned char)((data)>>24)&0xff), \
|
|
43 (*((buf)+1) = (unsigned char)((data)>>16)&0xff), \
|
|
44 (*((buf)+2) = (unsigned char)((data)>>8)&0xff), \
|
|
45 (*((buf)+3) = (unsigned char)(data)&0xff), \
|
|
46 4)
|
|
47 #define util_get8(buf) ((*(buf))&0xff)
|
|
48 #define util_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) & 0xff))
|
|
49 #define util_get32(buf) ((((*(buf))<<24)&0xff000000) + \
|
|
50 (((*((buf)+1))<<16)&0x00ff0000) + \
|
|
51 (((*((buf)+2))<< 8)&0x0000ff00) + \
|
|
52 (((*((buf)+3) )&0x000000ff)))
|
|
53
|
|
54 /*
|
|
55 * Merriam-Webster's
|
|
56 */
|
|
57 #define RENDEZVOUS_RRTYPE_A 1
|
|
58 #define RENDEZVOUS_RRTYPE_NS 2
|
|
59 #define RENDEZVOUS_RRTYPE_CNAME 5
|
|
60 #define RENDEZVOUS_RRTYPE_NULL 10
|
|
61 #define RENDEZVOUS_RRTYPE_PTR 12
|
|
62 #define RENDEZVOUS_RRTYPE_TXT 16
|
8594
|
63 #define RENDEZVOUS_RRTYPE_SRV 33
|
8487
|
64
|
|
65 /*
|
|
66 * Express for Men's
|
|
67 */
|
|
68 typedef struct _Header {
|
|
69 unsigned short id;
|
|
70 unsigned short flags;
|
|
71 unsigned short numquestions;
|
|
72 unsigned short numanswers;
|
|
73 unsigned short numauthority;
|
|
74 unsigned short numadditional;
|
|
75 } Header;
|
|
76
|
|
77 typedef struct _Question {
|
|
78 gchar *name;
|
|
79 unsigned short type;
|
|
80 unsigned short class;
|
|
81 } Question;
|
|
82
|
8594
|
83 typedef struct _ResourceRecord {
|
8487
|
84 gchar *name;
|
|
85 unsigned short type;
|
|
86 unsigned short class;
|
|
87 int ttl;
|
|
88 unsigned short rdlength;
|
|
89 void *rdata;
|
|
90 } ResourceRecord;
|
|
91
|
8594
|
92 typedef GHashTable ResourceRecordTXT;
|
|
93
|
|
94 typedef struct _ResourceRecordSRV {
|
|
95 unsigned int priority;
|
|
96 unsigned int weight;
|
|
97 unsigned int port;
|
|
98 gchar *target;
|
|
99 } ResourceRecordSRV;
|
|
100
|
8487
|
101 typedef struct _DNSPacket {
|
|
102 Header header;
|
|
103 Question *questions;
|
|
104 ResourceRecord *answers;
|
|
105 ResourceRecord *authority;
|
|
106 ResourceRecord *additional;
|
|
107 } DNSPacket;
|
|
108
|
|
109 /*
|
|
110 * Bring in 'Da Noise, Bring in 'Da Functions
|
|
111 */
|
|
112
|
|
113 /**
|
|
114 * Create a multicast socket that can be used for sending and
|
|
115 * receiving multicast DNS packets. The socket joins the
|
|
116 * link-local multicast group (224.0.0.251).
|
|
117 *
|
|
118 * @return The file descriptor of the new socket, or -1 if
|
|
119 * there was an error establishing the socket.
|
|
120 */
|
|
121 int mdns_establish_socket();
|
|
122
|
|
123 /**
|
|
124 * Send a multicast DNS query for the given domain across the given
|
|
125 * socket.
|
|
126 *
|
|
127 * @param fd The file descriptor of a pre-established socket to
|
|
128 * be used for sending the outgoing mDNS query.
|
|
129 * @param domain This is the domain name you wish to query. It should
|
|
130 * be of the format "_presence._tcp.local" for example.
|
|
131 * @return 0 if sucessful.
|
|
132 */
|
|
133 int mdns_query(int fd, const char *domain);
|
|
134
|
|
135 /**
|
8594
|
136 * Read a UDP packet from the given file descriptor and parse it
|
|
137 * into a DNSPacket.
|
8487
|
138 *
|
8594
|
139 * @param fd A UDP listening socket to read from.
|
|
140 * @return A newly allocated DNSPacket. This should be freed with
|
|
141 * mdns_free() when no longer needed.
|
8487
|
142 */
|
|
143 DNSPacket *mdns_read(int fd);
|
|
144
|
|
145 /**
|
|
146 * Free a DNSPacket structure.
|
|
147 *
|
|
148 * @param dns The DNSPacket that you want to free.
|
|
149 */
|
|
150 void mdns_free(DNSPacket *dns);
|
|
151
|
|
152 #endif /* _MDNS_H_ */
|