]>
git.saurik.com Git - apple/mdnsresponder.git/blob - ServiceRegistration/srp.c
3 * Service Registration Protocol Client
5 * Discover the service registration domain
6 * Construct a DNS update
8 * Service Name: PTR Record
9 * Service Instance Name: SRV record
10 * Hostname: A, AAAA, KEY records
11 * Sign with key using SIG(0)
15 main(int argc
, char *argv
)
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";
23 uint8_t *prKey
= NULL
;
24 uint8_t *puKey
= NULL
;
25 dns_message_t
*update
;
27 dns_name_t
*service_name
;
28 dns_name_t
*service_instance_name
;
31 message
.id
= srp_random16();
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;
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
);
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
48 // IN KEY ojwefoijweojfwoeijfoiwejfoiwejfoiejf
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
);
60 // Get the service name and type
63 // Discover the registration domain (not for Thread)
64 // Discover the SRP server (not for Thread)
65 // Generate the update
73 // c-file-style: "bsd"
76 // indent-tabs-mode: nil