1

I'm trying to build a Unix-domain socket using the socket2 crate and the most basic code fails to compile:

extern crate socket2;
use socket2::*;

fn main() {
    let socket = Socket::new(Domain::unix(), Type::dgram(), None).unwrap();
}

This is the error:

5 | let socket = Socket::new(Domain::unix(), Type::dgram(), None).unwrap();
  |                          ^^^^^^^^^^^^ function or associated item not found in 
                                               `socket2::Domain`

The documentation indicates, that unix function is "only available on Unix when the unix feature is activated". I'm running this code on a Ubuntu machine. Do I need to activate anything else in my cargo file for this function to be enabled? The crate lacks examples that I can rely on.

4
  • This is not a MCVE. Please try to create one Commented Aug 24, 2018 at 10:48
  • Code has been edited. Commented Aug 24, 2018 at 10:51
  • Why don't you just use a regular UDP socket? Commented Aug 24, 2018 at 10:54
  • The use I have is for IPC between processes that require to communicate using socket files for various other reasons. Commented Aug 24, 2018 at 10:57

1 Answer 1

3

This function is only available on Unix when the unix feature is activated.

And How to activate a feature

In your case just add this to your cargo manifest:

[dependencies.socket2]
version = "0.3.7"
features = ["unix"]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.