|
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
|
|
8631
|
92 typedef struct _ResourceRecordRDataTXTNode {
|
|
8629
|
93 char *name;
|
|
|
94 char *value;
|
|
8631
|
95 } ResourceRecordRDataTXTNode;
|
|
|
96
|
|
|
97 typedef GSList ResourceRecordRDataTXT;
|
|
8629
|
98
|
|
8631
|
99 typedef struct _ResourceRecordRDataSRV {
|
|
|
100 unsigned short port;
|
|
8634
|
101 char *target;
|
|
8631
|
102 } ResourceRecordRDataSRV;
|
|
8594
|
103
|
|
|
104 typedef struct _ResourceRecordSRV {
|
|
|
105 unsigned int priority;
|
|
|
106 unsigned int weight;
|
|
|
107 unsigned int port;
|
|
|
108 gchar *target;
|
|
|
109 } ResourceRecordSRV;
|
|
|
110
|
|
8487
|
111 typedef struct _DNSPacket {
|
|
|
112 Header header;
|
|
|
113 Question *questions;
|
|
|
114 ResourceRecord *answers;
|
|
|
115 ResourceRecord *authority;
|
|
|
116 ResourceRecord *additional;
|
|
|
117 } DNSPacket;
|
|
|
118
|
|
|
119 /*
|
|
|
120 * Bring in 'Da Noise, Bring in 'Da Functions
|
|
|
121 */
|
|
|
122
|
|
|
123 /**
|
|
|
124 * Create a multicast socket that can be used for sending and
|
|
|
125 * receiving multicast DNS packets. The socket joins the
|
|
|
126 * link-local multicast group (224.0.0.251).
|
|
|
127 *
|
|
|
128 * @return The file descriptor of the new socket, or -1 if
|
|
|
129 * there was an error establishing the socket.
|
|
|
130 */
|
|
|
131 int mdns_establish_socket();
|
|
|
132
|
|
8612
|
133
|
|
|
134 /**
|
|
|
135 * Sends a multicast DNS datagram. Generally this is called
|
|
|
136 * by other convenience functions such as mdns_query(), however
|
|
|
137 * a client CAN construct its own DNSPacket if it wishes.
|
|
|
138 *
|
|
|
139 * @param fd The file descriptor of a pre-established socket to
|
|
|
140 * be used for sending the outgoing mDNS datagram.
|
|
|
141 * @param dns The DNS datagram you wish to send.
|
|
|
142 * @return 0 on success, otherwise return the error number.
|
|
|
143 */
|
|
|
144 int mdns_send_dns(int fd, const DNSPacket *dns);
|
|
|
145
|
|
8487
|
146 /**
|
|
|
147 * Send a multicast DNS query for the given domain across the given
|
|
|
148 * socket.
|
|
|
149 *
|
|
|
150 * @param fd The file descriptor of a pre-established socket to
|
|
8612
|
151 * be used for sending the outgoing mDNS datagram.
|
|
8487
|
152 * @param domain This is the domain name you wish to query. It should
|
|
|
153 * be of the format "_presence._tcp.local" for example.
|
|
|
154 * @return 0 if sucessful.
|
|
|
155 */
|
|
|
156 int mdns_query(int fd, const char *domain);
|
|
|
157
|
|
8612
|
158 int mdns_advertise_ptr(int fd, const char *name, const char *domain);
|
|
8629
|
159 int mdns_advertise_txt(int fd, const char *name, const GSList *txt);
|
|
8631
|
160 int mdns_advertise_srv(int fd, const char *name, unsigned short port, const char *target);
|
|
8612
|
161
|
|
8487
|
162 /**
|
|
8594
|
163 * Read a UDP packet from the given file descriptor and parse it
|
|
|
164 * into a DNSPacket.
|
|
8487
|
165 *
|
|
8594
|
166 * @param fd A UDP listening socket to read from.
|
|
|
167 * @return A newly allocated DNSPacket. This should be freed with
|
|
|
168 * mdns_free() when no longer needed.
|
|
8487
|
169 */
|
|
|
170 DNSPacket *mdns_read(int fd);
|
|
|
171
|
|
|
172 /**
|
|
|
173 * Free a DNSPacket structure.
|
|
|
174 *
|
|
|
175 * @param dns The DNSPacket that you want to free.
|
|
|
176 */
|
|
|
177 void mdns_free(DNSPacket *dns);
|
|
|
178
|
|
|
179 #endif /* _MDNS_H_ */
|