Mercurial > pidgin
annotate src/protocols/rendezvous/mdns.h @ 11202:ff4884029708
[gaim-migrate @ 13330]
Some compile warning fixes. It's very possible the perl warnings
were caused by some of my changes to the core last week
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Mon, 08 Aug 2005 02:21:57 +0000 |
| parents | 913ec44675c3 |
| children |
| rev | line source |
|---|---|
| 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 | |
| 10596 | 26 /* |
| 27 * TODO: Need to document a lot of these. | |
| 28 */ | |
| 29 | |
| 8487 | 30 #ifndef _MDNS_H_ |
| 31 #define _MDNS_H_ | |
| 32 | |
| 8546 | 33 #include "internal.h" |
| 8487 | 34 #include "debug.h" |
| 35 | |
| 36 /* | |
| 37 * Some #define's stolen from libfaim. Used to put | |
| 38 * binary data (bytes, shorts and ints) into an array. | |
| 39 */ | |
| 40 #define util_put8(buf, data) ((*(buf) = (unsigned char)(data)&0xff),1) | |
| 41 #define util_put16(buf, data) ( \ | |
| 42 (*(buf) = (unsigned char)((data)>>8)&0xff), \ | |
| 43 (*((buf)+1) = (unsigned char)(data)&0xff), \ | |
| 44 2) | |
| 45 #define util_put32(buf, data) ( \ | |
| 46 (*((buf)) = (unsigned char)((data)>>24)&0xff), \ | |
| 47 (*((buf)+1) = (unsigned char)((data)>>16)&0xff), \ | |
| 48 (*((buf)+2) = (unsigned char)((data)>>8)&0xff), \ | |
| 49 (*((buf)+3) = (unsigned char)(data)&0xff), \ | |
| 50 4) | |
| 51 #define util_get8(buf) ((*(buf))&0xff) | |
| 52 #define util_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) & 0xff)) | |
| 53 #define util_get32(buf) ((((*(buf))<<24)&0xff000000) + \ | |
| 54 (((*((buf)+1))<<16)&0x00ff0000) + \ | |
| 55 (((*((buf)+2))<< 8)&0x0000ff00) + \ | |
| 56 (((*((buf)+3) )&0x000000ff))) | |
| 57 | |
| 58 /* | |
| 59 * Merriam-Webster's | |
| 60 */ | |
| 61 #define RENDEZVOUS_RRTYPE_A 1 | |
| 62 #define RENDEZVOUS_RRTYPE_NS 2 | |
| 63 #define RENDEZVOUS_RRTYPE_CNAME 5 | |
| 64 #define RENDEZVOUS_RRTYPE_NULL 10 | |
| 65 #define RENDEZVOUS_RRTYPE_PTR 12 | |
| 66 #define RENDEZVOUS_RRTYPE_TXT 16 | |
| 8834 | 67 #define RENDEZVOUS_RRTYPE_AAAA 28 |
| 8594 | 68 #define RENDEZVOUS_RRTYPE_SRV 33 |
| 8636 | 69 #define RENDEZVOUS_RRTYPE_ALL 255 |
| 8487 | 70 |
| 71 /* | |
| 72 * Express for Men's | |
| 73 */ | |
| 74 typedef struct _Header { | |
| 75 unsigned short id; | |
| 76 unsigned short flags; | |
| 77 unsigned short numquestions; | |
| 78 unsigned short numanswers; | |
| 79 unsigned short numauthority; | |
| 80 unsigned short numadditional; | |
| 81 } Header; | |
| 82 | |
| 83 typedef struct _Question { | |
| 84 gchar *name; | |
| 85 unsigned short type; | |
| 86 unsigned short class; | |
| 87 } Question; | |
| 88 | |
| 8594 | 89 typedef struct _ResourceRecord { |
| 8487 | 90 gchar *name; |
| 91 unsigned short type; | |
| 92 unsigned short class; | |
| 93 int ttl; | |
| 94 unsigned short rdlength; | |
| 95 void *rdata; | |
| 96 } ResourceRecord; | |
| 97 | |
| 8834 | 98 typedef unsigned char ResourceRecordRDataA; |
| 99 | |
| 8631 | 100 typedef struct _ResourceRecordRDataTXTNode { |
| 8629 | 101 char *name; |
| 102 char *value; | |
| 8631 | 103 } ResourceRecordRDataTXTNode; |
| 104 | |
| 105 typedef GSList ResourceRecordRDataTXT; | |
| 8629 | 106 |
| 8834 | 107 typedef unsigned char ResourceRecordRDataAAAA; |
| 108 | |
| 8631 | 109 typedef struct _ResourceRecordRDataSRV { |
| 8594 | 110 unsigned int priority; |
| 111 unsigned int weight; | |
| 112 unsigned int port; | |
| 113 gchar *target; | |
| 8806 | 114 } ResourceRecordRDataSRV; |
| 8594 | 115 |
| 8487 | 116 typedef struct _DNSPacket { |
| 117 Header header; | |
| 8806 | 118 GSList *questions; |
| 119 GSList *answers; | |
| 120 GSList *authority; | |
| 121 GSList *additional; | |
| 8487 | 122 } DNSPacket; |
| 123 | |
| 124 /* | |
| 125 * Bring in 'Da Noise, Bring in 'Da Functions | |
| 126 */ | |
| 127 | |
| 128 /** | |
| 129 * Create a multicast socket that can be used for sending and | |
| 130 * receiving multicast DNS packets. The socket joins the | |
| 131 * link-local multicast group (224.0.0.251). | |
| 132 * | |
| 133 * @return The file descriptor of the new socket, or -1 if | |
| 134 * there was an error establishing the socket. | |
| 135 */ | |
| 8834 | 136 int mdns_socket_establish(); |
| 137 | |
| 138 /** | |
| 139 * Close a multicast socket. This also clears the MDNS | |
| 140 * cache. | |
| 141 * | |
| 142 * @param The file descriptor of the multicast socket. | |
| 143 */ | |
| 144 void mdns_socket_close(int fd); | |
| 8487 | 145 |
| 8612 | 146 /** |
| 147 * Sends a multicast DNS datagram. Generally this is called | |
| 148 * by other convenience functions such as mdns_query(), however | |
| 149 * a client CAN construct its own DNSPacket if it wishes. | |
| 150 * | |
| 151 * @param fd The file descriptor of a pre-established socket to | |
| 152 * be used for sending the outgoing mDNS datagram. | |
| 153 * @param dns The DNS datagram you wish to send. | |
| 154 * @return 0 on success, otherwise return the error number. | |
| 155 */ | |
| 156 int mdns_send_dns(int fd, const DNSPacket *dns); | |
| 157 | |
| 8487 | 158 /** |
| 159 * Send a multicast DNS query for the given domain across the given | |
| 160 * socket. | |
| 161 * | |
| 162 * @param fd The file descriptor of a pre-established socket to | |
| 8612 | 163 * be used for sending the outgoing mDNS datagram. |
| 8487 | 164 * @param domain This is the domain name you wish to query. It should |
| 165 * be of the format "_presence._tcp.local" for example. | |
|
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8636
diff
changeset
|
166 * @return 0 if successful. |
| 8487 | 167 */ |
| 8636 | 168 int mdns_query(int fd, const char *domain, unsigned short type); |
| 8487 | 169 |
| 8738 | 170 int mdns_send_rr(int fd, ResourceRecord *rr); |
| 8838 | 171 int mdns_advertise_a(int fd, const char *name, const unsigned char *ip); |
| 8636 | 172 int mdns_advertise_null(int fd, const char *name, const char *data, unsigned short rdlength); |
| 8612 | 173 int mdns_advertise_ptr(int fd, const char *name, const char *domain); |
| 10596 | 174 int mdns_advertise_ptr_with_ttl(int fd, const char *name, const char *domain, int ttl); |
| 8629 | 175 int mdns_advertise_txt(int fd, const char *name, const GSList *txt); |
| 8838 | 176 int mdns_advertise_aaaa(int fd, const char *name, const unsigned char *ip); |
| 8631 | 177 int mdns_advertise_srv(int fd, const char *name, unsigned short port, const char *target); |
| 8612 | 178 |
| 8487 | 179 /** |
| 8594 | 180 * Read a UDP packet from the given file descriptor and parse it |
| 181 * into a DNSPacket. | |
| 8487 | 182 * |
| 8594 | 183 * @param fd A UDP listening socket to read from. |
| 184 * @return A newly allocated DNSPacket. This should be freed with | |
| 185 * mdns_free() when no longer needed. | |
| 8487 | 186 */ |
| 187 DNSPacket *mdns_read(int fd); | |
| 188 | |
| 189 /** | |
| 190 * Free a DNSPacket structure. | |
| 191 * | |
| 192 * @param dns The DNSPacket that you want to free. | |
| 193 */ | |
| 194 void mdns_free(DNSPacket *dns); | |
| 8738 | 195 void mdns_free_rr(ResourceRecord *rr); |
| 8806 | 196 void mdns_free_rrs(GSList *rrs); |
| 197 | |
| 198 ResourceRecord *mdns_copy_rr(const ResourceRecord *rr); | |
| 199 | |
| 200 ResourceRecordRDataTXTNode *mdns_txt_find(const GSList *ret, const char *name); | |
| 10596 | 201 |
| 8806 | 202 GSList *mdns_txt_add(GSList *ret, const char *name, const char *value, gboolean replace); |
| 203 | |
| 8487 | 204 |
| 205 #endif /* _MDNS_H_ */ |
