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
|
|
29 #include <errno.h>
|
|
30 #include <string.h>
|
|
31 #include <arpa/inet.h>
|
|
32 #include <netinet/in.h>
|
|
33 #include <sys/socket.h>
|
|
34 #include <sys/types.h>
|
|
35
|
|
36 #include "debug.h"
|
|
37
|
|
38 /*
|
|
39 * Some #define's stolen from libfaim. Used to put
|
|
40 * binary data (bytes, shorts and ints) into an array.
|
|
41 */
|
|
42 #define util_put8(buf, data) ((*(buf) = (unsigned char)(data)&0xff),1)
|
|
43 #define util_put16(buf, data) ( \
|
|
44 (*(buf) = (unsigned char)((data)>>8)&0xff), \
|
|
45 (*((buf)+1) = (unsigned char)(data)&0xff), \
|
|
46 2)
|
|
47 #define util_put32(buf, data) ( \
|
|
48 (*((buf)) = (unsigned char)((data)>>24)&0xff), \
|
|
49 (*((buf)+1) = (unsigned char)((data)>>16)&0xff), \
|
|
50 (*((buf)+2) = (unsigned char)((data)>>8)&0xff), \
|
|
51 (*((buf)+3) = (unsigned char)(data)&0xff), \
|
|
52 4)
|
|
53 #define util_get8(buf) ((*(buf))&0xff)
|
|
54 #define util_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) & 0xff))
|
|
55 #define util_get32(buf) ((((*(buf))<<24)&0xff000000) + \
|
|
56 (((*((buf)+1))<<16)&0x00ff0000) + \
|
|
57 (((*((buf)+2))<< 8)&0x0000ff00) + \
|
|
58 (((*((buf)+3) )&0x000000ff)))
|
|
59
|
|
60 /*
|
|
61 * Merriam-Webster's
|
|
62 */
|
|
63 #define RENDEZVOUS_RRTYPE_A 1
|
|
64 #define RENDEZVOUS_RRTYPE_NS 2
|
|
65 #define RENDEZVOUS_RRTYPE_CNAME 5
|
|
66 #define RENDEZVOUS_RRTYPE_NULL 10
|
|
67 #define RENDEZVOUS_RRTYPE_PTR 12
|
|
68 #define RENDEZVOUS_RRTYPE_TXT 16
|
|
69
|
|
70 /*
|
|
71 * Express for Men's
|
|
72 */
|
|
73 typedef struct _Header {
|
|
74 unsigned short id;
|
|
75 unsigned short flags;
|
|
76 unsigned short numquestions;
|
|
77 unsigned short numanswers;
|
|
78 unsigned short numauthority;
|
|
79 unsigned short numadditional;
|
|
80 } Header;
|
|
81
|
|
82 typedef struct _Question {
|
|
83 gchar *name;
|
|
84 unsigned short type;
|
|
85 unsigned short class;
|
|
86 } Question;
|
|
87
|
|
88 typedef struct ResourceRecord {
|
|
89 gchar *name;
|
|
90 unsigned short type;
|
|
91 unsigned short class;
|
|
92 int ttl;
|
|
93 unsigned short rdlength;
|
|
94 void *rdata;
|
|
95 } ResourceRecord;
|
|
96
|
|
97 typedef struct _DNSPacket {
|
|
98 Header header;
|
|
99 Question *questions;
|
|
100 ResourceRecord *answers;
|
|
101 ResourceRecord *authority;
|
|
102 ResourceRecord *additional;
|
|
103 } DNSPacket;
|
|
104
|
|
105 /*
|
|
106 * Bring in 'Da Noise, Bring in 'Da Functions
|
|
107 */
|
|
108
|
|
109 /**
|
|
110 * Create a multicast socket that can be used for sending and
|
|
111 * receiving multicast DNS packets. The socket joins the
|
|
112 * link-local multicast group (224.0.0.251).
|
|
113 *
|
|
114 * @return The file descriptor of the new socket, or -1 if
|
|
115 * there was an error establishing the socket.
|
|
116 */
|
|
117 int mdns_establish_socket();
|
|
118
|
|
119 /**
|
|
120 * Send a multicast DNS query for the given domain across the given
|
|
121 * socket.
|
|
122 *
|
|
123 * @param fd The file descriptor of a pre-established socket to
|
|
124 * be used for sending the outgoing mDNS query.
|
|
125 * @param domain This is the domain name you wish to query. It should
|
|
126 * be of the format "_presence._tcp.local" for example.
|
|
127 * @return 0 if sucessful.
|
|
128 */
|
|
129 int mdns_query(int fd, const char *domain);
|
|
130
|
|
131 /**
|
|
132 *
|
|
133 *
|
|
134 */
|
|
135 DNSPacket *mdns_read(int fd);
|
|
136
|
|
137 /**
|
|
138 * Free a DNSPacket structure.
|
|
139 *
|
|
140 * @param dns The DNSPacket that you want to free.
|
|
141 */
|
|
142 void mdns_free(DNSPacket *dns);
|
|
143
|
|
144 #endif /* _MDNS_H_ */
|