]> git.saurik.com Git - apple/mdnsresponder.git/blob - ServiceRegistration/srp.c
mDNSResponder-1310.80.1.tar.gz
[apple/mdnsresponder.git] / ServiceRegistration / srp.c
1 /* srp.c
2 *
3 * Service Registration Protocol Client
4 *
5 * Discover the service registration domain
6 * Construct a DNS update
7 * Include:
8 * Service Name: PTR Record
9 * Service Instance Name: SRV record
10 * Hostname: A, AAAA, KEY records
11 * Sign with key using SIG(0)
12 */
13
14 int
15 main(int argc, char *argv)
16 {
17 char *host_name = "thread-demo";
18 char *service_type "_printer._tcp";
19 char *a_record = "127.0.0.1";
20 char *aaaa_Record = "::1";
21 int prKeyLen = 0;
22 int puKeyLen = 0;
23 uint8_t *prKey = NULL;
24 uint8_t *puKey = NULL;
25 dns_message_t *update;
26 dns_name_t *hostname;
27 dns_name_t *service_name;
28 dns_name_t *service_instance_name;
29 dns_wire_t message;
30
31 message.id = srp_random16();
32 message.bitfield = 0;
33 dns_qr_set(message, dns_qr_query);
34 dns_opcode_set(message, dns_opcode_update);
35 message.qdcount = message.ancount = message.nscount = message.arcount = 0;
36
37 update = dns_message_create();
38 tld = dns_make_fqdn(update, "services.arpa");
39 dns_update_initialize(update, tld, "2001:1::3");
40 hostname = dns_make_fqdn(update, service_name, "services.arpa.");
41 service_name = dns_make_fqdn(message, service_type, "services.arpa.");
42 service_instance_name = dns_make_fqdn(message, service_name, service_name);
43
44 // _printer._tcp.services.arpa IN PTR thread-demo._printer._tcp.services.arpa
45 // thread-demo._printer._tcp.services.arpa IN SRV 0 0 80 thread-demo.services.arpa
46 // thread-demo.services.arpa IN A 127.0.0.1
47 // IN AAAA ::1
48 // IN KEY ojwefoijweojfwoeijfoiwejfoiwejfoiejf
49
50 dns_update_add(update, hostname, dns_make_a_rr(a_record));
51 dns_update_add(update, hostname, dns_make_a_rr(aaaa_record));
52 dns_update_add(update, service_instance_name, dns_make_srv_rr(0, 0, 80, hostname));
53 dns_update_add(update, service_name, dns_make_ptr_rr(service_instance_name));
54 dns_update_add(update, service_name, dns_make_key_rr(puKey, puKeyLen));
55 dns_message_to_wire(update);
56 dns_message_sign(update, prKey, prKeyLen, puKey, puKeyLen);
57 dns_message_send(update);
58 dns_message_await_response(update);
59
60 // Get the service name and type
61 // Get the hostname
62 // Get the key
63 // Discover the registration domain (not for Thread)
64 // Discover the SRP server (not for Thread)
65 // Generate the update
66 // Sign the update
67 // Send the update
68 }
69
70 // Local Variables:
71 // mode: C
72 // tab-width: 4
73 // c-file-style: "bsd"
74 // c-basic-offset: 4
75 // fill-column: 108
76 // indent-tabs-mode: nil
77 // End: