Giter Site home page Giter Site logo

multicast-dns's Introduction

Multicast DNS

Build Status

multicust_dns - is essentially a Rust wrapper around Avahi that internally uses AvahiDaemon to manage host name and browse services on the local network.

Requires avahi-common, avahi-client and dbus-1 libs to compile sucessfully.

For non-linux platforms that don't have required avahi libs, fake implementation is used.

See Multicast DNS Utils command line app as an example.

Examples (see ./examples folder):

extern crate multicast_dns;
use multicast_dns::host::HostManager;

fn main() {
    let host_name = format!("custom-host");

    let host_manager = HostManager::new();

    if !host_manager.is_valid_name(&host_name).unwrap() {
        panic!("Host name `{}` is not a valid host name!", &host_name);
    }

    // The `new_host_name` can be different from the one we are trying to set,
    // due to possible collisions that may happen.
    let new_host_name = host_manager.set_name(&host_name).unwrap();

    println!("New host name is: {:?}", &new_host_name);
}

or

extern crate multicast_dns;
use multicast_dns::discovery::*;

fn main() {
    let service_type = format!("_device-info._tcp");
    
    let discovery_manager = DiscoveryManager::new();

    let on_service_resolved = |service: ServiceInfo| {
        println!("Service resolved: {:?}", service);
    };

    let on_service_discovered = |service: ServiceInfo| {
        println!("Service discovered: {:?}", service);

        let resolve_listeners = ResolveListeners {
            on_service_resolved: Some(&on_service_resolved),
        };

        discovery_manager.resolve_service(service, resolve_listeners);
    };

    let on_all_discovered = || {
        println!("All services has been discovered");
    };

    let discovery_listeners = DiscoveryListeners {
        on_service_discovered: Some(&on_service_discovered),
        on_all_discovered: Some(&on_all_discovered),
    };

    discovery_manager.discover_services(&service_type, discovery_listeners);
}

Look at RFC 6762 and RFC 6763 for the standard specifications.

Also one can take a look at Service Name and Transport Protocol Port Number Registry to see currently available and registered services.

multicast-dns's People

Contributors

alesharik avatar andir avatar azasypkin avatar cr avatar lrbalt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

multicast-dns's Issues

Please add a license

From the Google open source guidelines:

Copyright protection can subsist in original works of authorship fixed in any tangible medium of expression. When someone makes code publicly available in any form, including GitHub, that code may be protected by copyright.

Generally, you should use code under licenses which explicitly give you relevant permissions. Ambiguity about what you can do with code can cause unwanted confusion and make open source difficult to use.

Discovery example doesn't build

Trying to build the discovery example from README:

error[E0412]: cannot find type `ServiceInfo` in this scope
 --> examples/discovery.rs:9:41
  |
9 |     let on_service_resolved = |service: ServiceInfo| {
  |                                         ^^^^^^^^^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
  |
2 | use multicast_dns::discovery::discovery_manager::ServiceInfo;
  |

error[E0412]: cannot find type `ServiceInfo` in this scope
  --> examples/discovery.rs:13:43
   |
13 |     let on_service_discovered = |service: ServiceInfo| {
   |                                           ^^^^^^^^^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
   |
2  | use multicast_dns::discovery::discovery_manager::ServiceInfo;
   |

error[E0422]: cannot find struct, variant or union type `ResolveListeners` in this scope
  --> examples/discovery.rs:16:33
   |
16 |         let resolve_listeners = ResolveListeners {
   |                                 ^^^^^^^^^^^^^^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
   |
2  | use multicast_dns::discovery::discovery_manager::ResolveListeners;
   |

error[E0422]: cannot find struct, variant or union type `DiscoveryListeners` in this scope
  --> examples/discovery.rs:27:31
   |
27 |     let discovery_listeners = DiscoveryListeners {
   |                               ^^^^^^^^^^^^^^^^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
   |
2  | use multicast_dns::discovery::discovery_manager::DiscoveryListeners;
   |

Adding those structs to src/discovery/mod.rs solves it:

diff --git a/src/discovery/mod.rs b/src/discovery/mod.rs
index 19a6b42..8b0d602 100644
--- a/src/discovery/mod.rs
+++ b/src/discovery/mod.rs
@@ -1,3 +1,6 @@
 pub use self::discovery_manager::DiscoveryManager;
+pub use self::discovery_manager::ServiceInfo;
+pub use self::discovery_manager::ResolveListeners;
+pub use self::discovery_manager::DiscoveryListeners;
 
 pub mod discovery_manager;

Fake adapter build errors

$ DEP_OPENSSL_INCLUDE=/usr/local/opt/openssl/include/ OPENSSL_INCLUDE_DIR=/usr/local/Cellar/openssl/1.0.2f/include/ cargo build
    Updating git repository `https://github.com/fxbox/multicast-dns.git`
   Compiling foxbox v0.1.0 (file:///Users/cruetten/Documents/src/foxbox)
   Compiling multicast_dns v0.1.0 (https://github.com/fxbox/multicast-dns.git?rev=89bd32a#89bd32a2)
/Users/cruetten/.multirust/toolchains/nightly-2016-02-22/cargo/git/checkouts/multicast-dns-d51af2fa146824d6/89bd32a/src/adapters/fake/adapter.rs:18:27: 18:28 error: mismatched types:
 expected `discovery::discovery_manager::ServiceProtocol`,
    found `_`
(expected enum `discovery::discovery_manager::ServiceProtocol`,
    found integral variable) [E0308]
/Users/cruetten/.multirust/toolchains/nightly-2016-02-22/cargo/git/checkouts/multicast-dns-d51af2fa146824d6/89bd32a/src/adapters/fake/adapter.rs:18                 protocol: 3,
                                                                                                                                                                              ^
/Users/cruetten/.multirust/toolchains/nightly-2016-02-22/cargo/git/checkouts/multicast-dns-d51af2fa146824d6/89bd32a/src/adapters/fake/adapter.rs:18:27: 18:28 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error
Could not compile `multicast_dns`.

To learn more, run the command again with --verbose.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.