Skip to content

IP_ADD_MEMBERSHIP constant not correctly defined for Windows #20381

Closed
@shepmaster

Description

@shepmaster

Running this code:

use std::io::net::udp::UdpSocket;
use std::io::net::ip::{Ipv4Addr, SocketAddr};

fn main() {
    let local_addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 3671 };
    let mut socket = match UdpSocket::bind(local_addr) {
        Ok(s) => s,
        Err(e) => panic!("couldn't bind socket: {}", e),
    };
    match socket.join_multicast(Ipv4Addr(224, 0, 23, 12)) {
        Err(why) => println!("! {}", why),
        Ok(_) => {},
    };
    drop(socket)
}

On Windows 7, 32-bit (rustc 0.13.0-nightly (5ba610265 2014-12-25 18:01:36 +0000)), and Windows 7, 64-bit (0.13.0-nightly (5ba610265 2014-12-25 18:01:36 +0000)) yields the error:

OS Error 10042: An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call

Doing some digging, I found a MS KB article that seems to directly mention this:

If the project is linked with Ws2_32.lib, setsockopt will fail with runtime error 10042 (WSAENOPROTOOPT). This is because in Winsock.h, IP_ADD_MEMBERSHIP is defined as "5". The corresponding Winsock runtime can not resolve option 5 at the IPPROTO_IP level, so the failure occurs with error code 10042.

As far as I can see, the current constant is set to 5, and the article says it should be 12

Metadata

Metadata

Assignees

No one assigned

    Labels

    O-windowsOperating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions