Mercurial > pidgin
annotate src/protocols/rendezvous/mdns.h @ 9125:668ffb8fec00
[gaim-migrate @ 9902]
(12:53:05) nosnilmot: LSchiere: not majorly important, but the pref changes
listed in the ChangeLog are out of sync
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Sun, 30 May 2004 16:54:40 +0000 |
| parents | 518455386538 |
| children | 913ec44675c3 |
| 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 | |
| 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 | |
| 8834 | 63 #define RENDEZVOUS_RRTYPE_AAAA 28 |
| 8594 | 64 #define RENDEZVOUS_RRTYPE_SRV 33 |
| 8636 | 65 #define RENDEZVOUS_RRTYPE_ALL 255 |
| 8487 | 66 |
| 67 /* | |
| 68 * Express for Men's | |
| 69 */ | |
| 70 typedef struct _Header { | |
| 71 unsigned short id; | |
| 72 unsigned short flags; | |
| 73 unsigned short numquestions; | |
| 74 unsigned short numanswers; | |
| 75 unsigned short numauthority; | |
| 76 unsigned short numadditional; | |
| 77 } Header; | |
| 78 | |
| 79 typedef struct _Question { | |
| 80 gchar *name; | |
| 81 unsigned short type; | |
| 82 unsigned short class; | |
| 83 } Question; | |
| 84 | |
| 8594 | 85 typedef struct _ResourceRecord { |
| 8487 | 86 gchar *name; |
| 87 unsigned short type; | |
| 88 unsigned short class; | |
| 89 int ttl; | |
| 90 unsigned short rdlength; | |
| 91 void *rdata; | |
| 92 } ResourceRecord; | |
| 93 | |
| 8834 | 94 typedef unsigned char ResourceRecordRDataA; |
| 95 | |
| 8631 | 96 typedef struct _ResourceRecordRDataTXTNode { |
| 8629 | 97 char *name; |
| 98 char *value; | |
| 8631 | 99 } ResourceRecordRDataTXTNode; |
| 100 | |
| 101 typedef GSList ResourceRecordRDataTXT; | |
| 8629 | 102 |
| 8834 | 103 typedef unsigned char ResourceRecordRDataAAAA; |
| 104 | |
| 8631 | 105 typedef struct _ResourceRecordRDataSRV { |
| 8594 | 106 unsigned int priority; |
| 107 unsigned int weight; | |
| 108 unsigned int port; | |
| 109 gchar *target; | |
| 8806 | 110 } ResourceRecordRDataSRV; |
| 8594 | 111 |
| 8487 | 112 typedef struct _DNSPacket { |
| 113 Header header; | |
| 8806 | 114 GSList *questions; |
| 115 GSList *answers; | |
| 116 GSList *authority; | |
| 117 GSList *additional; | |
| 8487 | 118 } DNSPacket; |
| 119 | |
| 120 /* | |
| 121 * Bring in 'Da Noise, Bring in 'Da Functions | |
| 122 */ | |
| 123 | |
| 124 /** | |
| 125 * Create a multicast socket that can be used for sending and | |
| 126 * receiving multicast DNS packets. The socket joins the | |
| 127 * link-local multicast group (224.0.0.251). | |
| 128 * | |
| 129 * @return The file descriptor of the new socket, or -1 if | |
| 130 * there was an error establishing the socket. | |
| 131 */ | |
| 8834 | 132 int mdns_socket_establish(); |
| 133 | |
| 134 | |
| 135 /** | |
| 136 * Close a multicast socket. This also clears the MDNS | |
| 137 * cache. | |
| 138 * | |
| 139 * @param The file descriptor of the multicast socket. | |
| 140 */ | |
| 141 void mdns_socket_close(int fd); | |
| 8487 | 142 |
| 8612 | 143 |
| 144 /** | |
| 145 * Sends a multicast DNS datagram. Generally this is called | |
| 146 * by other convenience functions such as mdns_query(), however | |
| 147 * a client CAN construct its own DNSPacket if it wishes. | |
| 148 * | |
| 149 * @param fd The file descriptor of a pre-established socket to | |
| 150 * be used for sending the outgoing mDNS datagram. | |
| 151 * @param dns The DNS datagram you wish to send. | |
| 152 * @return 0 on success, otherwise return the error number. | |
| 153 */ | |
| 154 int mdns_send_dns(int fd, const DNSPacket *dns); | |
| 155 | |
| 8487 | 156 /** |
| 157 * Send a multicast DNS query for the given domain across the given | |
| 158 * socket. | |
| 159 * | |
| 160 * @param fd The file descriptor of a pre-established socket to | |
| 8612 | 161 * be used for sending the outgoing mDNS datagram. |
| 8487 | 162 * @param domain This is the domain name you wish to query. It should |
| 163 * be of the format "_presence._tcp.local" for example. | |
|
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8636
diff
changeset
|
164 * @return 0 if successful. |
| 8487 | 165 */ |
| 8636 | 166 int mdns_query(int fd, const char *domain, unsigned short type); |
| 8487 | 167 |
| 8738 | 168 int mdns_send_rr(int fd, ResourceRecord *rr); |
| 8838 | 169 int mdns_advertise_a(int fd, const char *name, const unsigned char *ip); |
| 8636 | 170 int mdns_advertise_null(int fd, const char *name, const char *data, unsigned short rdlength); |
| 8612 | 171 int mdns_advertise_ptr(int fd, const char *name, const char *domain); |
| 8629 | 172 int mdns_advertise_txt(int fd, const char *name, const GSList *txt); |
| 8838 | 173 int mdns_advertise_aaaa(int fd, const char *name, const unsigned char *ip); |
| 8631 | 174 int mdns_advertise_srv(int fd, const char *name, unsigned short port, const char *target); |
| 8612 | 175 |
| 8487 | 176 /** |
| 8594 | 177 * Read a UDP packet from the given file descriptor and parse it |
| 178 * into a DNSPacket. | |
| 8487 | 179 * |
| 8594 | 180 * @param fd A UDP listening socket to read from. |
| 181 * @return A newly allocated DNSPacket. This should be freed with | |
| 182 * mdns_free() when no longer needed. | |
| 8487 | 183 */ |
| 184 DNSPacket *mdns_read(int fd); | |
| 185 | |
| 186 /** | |
| 187 * Free a DNSPacket structure. | |
| 188 * | |
| 189 * @param dns The DNSPacket that you want to free. | |
| 190 */ | |
| 191 void mdns_free(DNSPacket *dns); | |
| 8738 | 192 void mdns_free_rr(ResourceRecord *rr); |
| 8806 | 193 void mdns_free_rrs(GSList *rrs); |
| 194 | |
| 195 ResourceRecord *mdns_copy_rr(const ResourceRecord *rr); | |
| 196 | |
| 197 ResourceRecordRDataTXTNode *mdns_txt_find(const GSList *ret, const char *name); | |
| 198 GSList *mdns_txt_add(GSList *ret, const char *name, const char *value, gboolean replace); | |
| 199 | |
| 8487 | 200 |
| 201 #endif /* _MDNS_H_ */ |
