| 427 |
430 |
| 428 return ret; |
431 return ret; |
| 429 } |
432 } |
| 430 |
433 |
| 431 int |
434 int |
| 432 mdns_advertise_null(int fd, const char *name, const char *rdata, unsigned short rdlength) |
435 mdns_send_rr(int fd, ResourceRecord *rr) |
| 433 { |
436 { |
| 434 int ret; |
437 int ret; |
| 435 DNSPacket *dns; |
438 DNSPacket *dns; |
| 436 |
|
| 437 if ((strlen(name) > 255)) { |
|
| 438 return -EINVAL; |
|
| 439 } |
|
| 440 |
439 |
| 441 dns = (DNSPacket *)g_malloc(sizeof(DNSPacket)); |
440 dns = (DNSPacket *)g_malloc(sizeof(DNSPacket)); |
| 442 dns->header.id = 0x0000; |
441 dns->header.id = 0x0000; |
| 443 dns->header.flags = 0x8400; |
442 dns->header.flags = 0x8400; |
| 444 dns->header.numquestions = 0x0000; |
443 dns->header.numquestions = 0x0000; |
| 445 dns->header.numanswers = 0x0001; |
444 dns->header.numanswers = 0x0001; |
| 446 dns->header.numauthority = 0x0000; |
445 dns->header.numauthority = 0x0000; |
| 447 dns->header.numadditional = 0x0000; |
446 dns->header.numadditional = 0x0000; |
| 448 dns->questions = NULL; |
447 dns->questions = NULL; |
| 449 |
448 dns->answers = rr; |
| 450 dns->answers = (ResourceRecord *)g_malloc(1 * sizeof(ResourceRecord)); |
|
| 451 dns->answers[0].name = g_strdup(name); |
|
| 452 dns->answers[0].type = RENDEZVOUS_RRTYPE_NULL; |
|
| 453 dns->answers[0].class = 0x0001; |
|
| 454 dns->answers[0].ttl = 0x00001c20; |
|
| 455 dns->answers[0].rdlength = rdlength; |
|
| 456 dns->answers[0].rdata = (void *)rdata; |
|
| 457 |
|
| 458 dns->authority = NULL; |
449 dns->authority = NULL; |
| 459 dns->additional = NULL; |
450 dns->additional = NULL; |
| 460 |
451 |
| 461 mdns_send_dns(fd, dns); |
452 mdns_send_dns(fd, dns); |
| 462 |
453 |
| |
454 /* The rr should be freed by the caller of this function */ |
| |
455 dns->header.numanswers = 0x0000; |
| |
456 dns->answers = NULL; |
| |
457 |
| |
458 mdns_free(dns); |
| |
459 |
| |
460 return ret; |
| |
461 } |
| |
462 |
| |
463 int |
| |
464 mdns_advertise_null(int fd, const char *name, const char *rdata, unsigned short rdlength) |
| |
465 { |
| |
466 int ret; |
| |
467 ResourceRecord *rr; |
| |
468 |
| |
469 if ((strlen(name) > 255)) { |
| |
470 return -EINVAL; |
| |
471 } |
| |
472 |
| |
473 rr = (ResourceRecord *)g_malloc(sizeof(ResourceRecord)); |
| |
474 rr->name = g_strdup(name); |
| |
475 rr->type = RENDEZVOUS_RRTYPE_NULL; |
| |
476 rr->class = 0x0001; |
| |
477 rr->ttl = 0x00001c20; |
| |
478 rr->rdlength = rdlength; |
| |
479 rr->rdata = (void *)rdata; |
| |
480 |
| |
481 mdns_send_rr(fd, rr); |
| |
482 |
| 463 /* The rdata should be freed by the caller of this function */ |
483 /* The rdata should be freed by the caller of this function */ |
| 464 dns->answers[0].rdata = NULL; |
484 rr->rdata = NULL; |
| 465 |
485 |
| 466 mdns_free(dns); |
486 mdns_free_rr(rr); |
| 467 |
487 |
| 468 return ret; |
488 return ret; |
| 469 } |
489 } |
| 470 |
490 |
| 471 int |
491 int |
| 472 mdns_advertise_ptr(int fd, const char *name, const char *domain) |
492 mdns_advertise_ptr(int fd, const char *name, const char *domain) |
| 473 { |
493 { |
| 474 int ret; |
494 int ret; |
| 475 DNSPacket *dns; |
495 ResourceRecord *rr; |
| 476 |
496 |
| 477 if ((strlen(name) > 255) || (strlen(domain) > 255)) { |
497 if ((strlen(name) > 255) || (strlen(domain) > 255)) { |
| 478 return -EINVAL; |
498 return -EINVAL; |
| 479 } |
499 } |
| 480 |
500 |
| 481 dns = (DNSPacket *)g_malloc(sizeof(DNSPacket)); |
501 rr = (ResourceRecord *)g_malloc(sizeof(ResourceRecord)); |
| 482 dns->header.id = 0x0000; |
502 rr->name = g_strdup(name); |
| 483 dns->header.flags = 0x8400; |
503 rr->type = RENDEZVOUS_RRTYPE_PTR; |
| 484 dns->header.numquestions = 0x0000; |
504 rr->class = 0x8001; |
| 485 dns->header.numanswers = 0x0001; |
505 rr->ttl = 0x00001c20; |
| 486 dns->header.numauthority = 0x0000; |
506 rr->rdata = (void *)g_strdup(domain); |
| 487 dns->header.numadditional = 0x0000; |
507 rr->rdlength = mdns_getlength_RR_rdata(rr->type, rr->rdata); |
| 488 dns->questions = NULL; |
508 |
| 489 |
509 mdns_send_rr(fd, rr); |
| 490 dns->answers = (ResourceRecord *)g_malloc(1 * sizeof(ResourceRecord)); |
510 |
| 491 dns->answers[0].name = g_strdup(name); |
511 mdns_free_rr(rr); |
| 492 dns->answers[0].type = RENDEZVOUS_RRTYPE_PTR; |
|
| 493 dns->answers[0].class = 0x8001; |
|
| 494 dns->answers[0].ttl = 0x00001c20; |
|
| 495 dns->answers[0].rdata = (void *)g_strdup(domain); |
|
| 496 dns->answers[0].rdlength = mdns_getlength_RR_rdata(dns->answers[0].type, dns->answers[0].rdata); |
|
| 497 |
|
| 498 dns->authority = NULL; |
|
| 499 dns->additional = NULL; |
|
| 500 |
|
| 501 mdns_send_dns(fd, dns); |
|
| 502 |
|
| 503 mdns_free(dns); |
|
| 504 |
512 |
| 505 return ret; |
513 return ret; |
| 506 } |
514 } |
| 507 |
515 |
| 508 int |
516 int |
| 509 mdns_advertise_txt(int fd, const char *name, const GSList *rdata) |
517 mdns_advertise_txt(int fd, const char *name, const GSList *rdata) |
| 510 { |
518 { |
| 511 int ret; |
519 int ret; |
| 512 DNSPacket *dns; |
520 ResourceRecord *rr; |
| 513 |
521 |
| 514 if ((strlen(name) > 255)) { |
522 if ((strlen(name) > 255)) { |
| 515 return -EINVAL; |
523 return -EINVAL; |
| 516 } |
524 } |
| 517 |
525 |
| 518 dns = (DNSPacket *)g_malloc(sizeof(DNSPacket)); |
526 rr = (ResourceRecord *)g_malloc(sizeof(ResourceRecord)); |
| 519 dns->header.id = 0x0000; |
527 rr->name = g_strdup(name); |
| 520 dns->header.flags = 0x8400; |
528 rr->type = RENDEZVOUS_RRTYPE_TXT; |
| 521 dns->header.numquestions = 0x0000; |
529 rr->class = 0x8001; |
| 522 dns->header.numanswers = 0x0001; |
530 rr->ttl = 0x00001c20; |
| 523 dns->header.numauthority = 0x0000; |
531 rr->rdata = (void *)rdata; |
| 524 dns->header.numadditional = 0x0000; |
532 rr->rdlength = mdns_getlength_RR_rdata(rr->type, rr->rdata); |
| 525 dns->questions = NULL; |
533 |
| 526 |
534 mdns_send_rr(fd, rr); |
| 527 dns->answers = (ResourceRecord *)g_malloc(1 * sizeof(ResourceRecord)); |
|
| 528 dns->answers[0].name = g_strdup(name); |
|
| 529 dns->answers[0].type = RENDEZVOUS_RRTYPE_TXT; |
|
| 530 dns->answers[0].class = 0x8001; |
|
| 531 dns->answers[0].ttl = 0x00001c20; |
|
| 532 dns->answers[0].rdata = (void *)rdata; |
|
| 533 dns->answers[0].rdlength = mdns_getlength_RR_rdata(dns->answers[0].type, dns->answers[0].rdata); |
|
| 534 |
|
| 535 dns->authority = NULL; |
|
| 536 dns->additional = NULL; |
|
| 537 |
|
| 538 mdns_send_dns(fd, dns); |
|
| 539 |
535 |
| 540 /* The rdata should be freed by the caller of this function */ |
536 /* The rdata should be freed by the caller of this function */ |
| 541 dns->answers[0].rdata = NULL; |
537 rr->rdata = NULL; |
| 542 |
538 |
| 543 mdns_free(dns); |
539 mdns_free_rr(rr); |
| 544 |
540 |
| 545 return ret; |
541 return ret; |
| 546 } |
542 } |
| 547 |
543 |
| 548 int |
544 int |
| 549 mdns_advertise_srv(int fd, const char *name, unsigned short port, const char *target) |
545 mdns_advertise_srv(int fd, const char *name, unsigned short port, const char *target) |
| 550 { |
546 { |
| 551 int ret; |
547 int ret; |
| 552 DNSPacket *dns; |
548 ResourceRecord *rr; |
| 553 ResourceRecordRDataSRV *rdata; |
549 ResourceRecordRDataSRV *rdata; |
| 554 |
550 |
| 555 if ((strlen(target) > 255)) { |
551 if ((strlen(target) > 255)) { |
| 556 return -EINVAL; |
552 return -EINVAL; |
| 557 } |
553 } |
| 558 |
554 |
| 559 rdata = g_malloc(sizeof(ResourceRecordRDataSRV)); |
555 rdata = g_malloc(sizeof(ResourceRecordRDataSRV)); |
| 560 rdata->port = port; |
556 rdata->port = port; |
| 561 rdata->target = g_strdup(target); |
557 rdata->target = g_strdup(target); |
| 562 |
558 |
| 563 dns = (DNSPacket *)g_malloc(sizeof(DNSPacket)); |
559 rr = (ResourceRecord *)g_malloc(sizeof(ResourceRecord)); |
| 564 dns->header.id = 0x0000; |
560 rr->name = g_strdup(name); |
| 565 dns->header.flags = 0x8400; |
561 rr->type = RENDEZVOUS_RRTYPE_SRV; |
| 566 dns->header.numquestions = 0x0000; |
562 rr->class = 0x8001; |
| 567 dns->header.numanswers = 0x0000; |
563 rr->ttl = 0x00001c20; |
| 568 dns->header.numauthority = 0x0001; |
564 rr->rdata = rdata; |
| 569 dns->header.numadditional = 0x0000; |
565 rr->rdlength = mdns_getlength_RR_rdata(rr->type, rr->rdata); |
| 570 dns->questions = NULL; |
566 |
| 571 dns->answers = NULL; |
567 mdns_send_rr(fd, rr); |
| 572 |
568 |
| 573 dns->authority = (ResourceRecord *)g_malloc(1 * sizeof(ResourceRecord)); |
569 mdns_free_rr(rr); |
| 574 dns->authority[0].name = g_strdup(name); |
|
| 575 dns->authority[0].type = RENDEZVOUS_RRTYPE_SRV; |
|
| 576 dns->authority[0].class = 0x8001; |
|
| 577 dns->authority[0].ttl = 0x00001c20; |
|
| 578 dns->authority[0].rdata = rdata; |
|
| 579 dns->authority[0].rdlength = mdns_getlength_RR_rdata(dns->authority[0].type, dns->authority[0].rdata); |
|
| 580 |
|
| 581 dns->additional = NULL; |
|
| 582 |
|
| 583 mdns_send_dns(fd, dns); |
|
| 584 |
|
| 585 mdns_free(dns); |
|
| 586 |
570 |
| 587 return ret; |
571 return ret; |
| 588 } |
572 } |
| 589 |
573 |
| 590 /***************************************/ |
574 /***************************************/ |