Thu, 01 Apr 2004 17:42:12 +0000
[gaim-migrate @ 9288]
Might as well have this up to date with the small changes I'd made
| 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
59e40a3b08bf
[gaim-migrate @ 9288]
Mark Doliner <markdoliner@pidgin.im>
parents:
8487
diff
changeset
|
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 | |
| 63 | ||
| 64 | /* | |
| 65 | * Express for Men's | |
| 66 | */ | |
| 67 | typedef struct _Header { | |
| 68 | unsigned short id; | |
| 69 | unsigned short flags; | |
| 70 | unsigned short numquestions; | |
| 71 | unsigned short numanswers; | |
| 72 | unsigned short numauthority; | |
| 73 | unsigned short numadditional; | |
| 74 | } Header; | |
| 75 | ||
| 76 | typedef struct _Question { | |
| 77 | gchar *name; | |
| 78 | unsigned short type; | |
| 79 | unsigned short class; | |
| 80 | } Question; | |
| 81 | ||
| 82 | typedef struct ResourceRecord { | |
| 83 | gchar *name; | |
| 84 | unsigned short type; | |
| 85 | unsigned short class; | |
| 86 | int ttl; | |
| 87 | unsigned short rdlength; | |
| 88 | void *rdata; | |
| 89 | } ResourceRecord; | |
| 90 | ||
| 91 | typedef struct _DNSPacket { | |
| 92 | Header header; | |
| 93 | Question *questions; | |
| 94 | ResourceRecord *answers; | |
| 95 | ResourceRecord *authority; | |
| 96 | ResourceRecord *additional; | |
| 97 | } DNSPacket; | |
| 98 | ||
| 99 | /* | |
| 100 | * Bring in 'Da Noise, Bring in 'Da Functions | |
| 101 | */ | |
| 102 | ||
| 103 | /** | |
| 104 | * Create a multicast socket that can be used for sending and | |
| 105 | * receiving multicast DNS packets. The socket joins the | |
| 106 | * link-local multicast group (224.0.0.251). | |
| 107 | * | |
| 108 | * @return The file descriptor of the new socket, or -1 if | |
| 109 | * there was an error establishing the socket. | |
| 110 | */ | |
| 111 | int mdns_establish_socket(); | |
| 112 | ||
| 113 | /** | |
| 114 | * Send a multicast DNS query for the given domain across the given | |
| 115 | * socket. | |
| 116 | * | |
| 117 | * @param fd The file descriptor of a pre-established socket to | |
| 118 | * be used for sending the outgoing mDNS query. | |
| 119 | * @param domain This is the domain name you wish to query. It should | |
| 120 | * be of the format "_presence._tcp.local" for example. | |
| 121 | * @return 0 if sucessful. | |
| 122 | */ | |
| 123 | int mdns_query(int fd, const char *domain); | |
| 124 | ||
| 125 | /** | |
| 126 | * | |
| 127 | * | |
| 128 | */ | |
| 129 | DNSPacket *mdns_read(int fd); | |
| 130 | ||
| 131 | /** | |
| 132 | * Free a DNSPacket structure. | |
| 133 | * | |
| 134 | * @param dns The DNSPacket that you want to free. | |
| 135 | */ | |
| 136 | void mdns_free(DNSPacket *dns); | |
| 137 | ||
| 138 | #endif /* _MDNS_H_ */ |