lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Issue with SO_BINDTODEVICE


From: Oliver Hitz
Subject: [lwip-users] Issue with SO_BINDTODEVICE
Date: Mon, 26 Oct 2020 16:57:26 +0100
User-agent: NeoMutt/20170113 (1.7.2)

Hi all,

I have a device with two network interfaces, en0 and en1. I would like
lwip to consider them as separate network interfaces.

As a test, I have installed two DHCP servers in two networks and I'm
assigning each interface an IP address in the same IP range. This works
perfectly. Each IP address is only visible on the interface to which it
was assigned. No ARP or other traffic mentioning the IP address is
"leaked" to the wrong interface. So far so good.

Next I have tried to set up a TCP server which is bound to only "en0"
using SO_BINDTOSOCKET, but without success. It seems as if that call
doesn't have any effect at all. I can connect to the socket from en1
though I would expect to get a "Connection refused". On the contrary,
connecting from en0 causes a SYN-ACK packet to be send out on en1.

My code is as follows:

    int sock;
    int error;

    if ((sock = lwip_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
        ...
    }

    struct ifreq dev = { .ifr_name = "en0" };
    error = lwip_setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, (const void *) 
&dev, sizeof(dev));
    if (error) {
        ...
    }

    struct sockaddr_in address = {
        .sin_family = AF_INET,
        .sin_port = htons(1234),
        .sin_addr.s_addr = INADDR_ANY
    };

    error = lwip_bind(sock, (struct sockaddr *) &address, sizeof(address));
    if (error) {
        ....
    }

    lwip_listen(sock, 0);

    while (1) {
        struct sockaddr remote;
        socklen_t size;

        int new_sd = lwip_accept(sock, &remote, &size);
        if (new_sd > 0) {
            lwip_send(new_sd, "Hello", sizeof("Hello"), 0);
            lwip_close(new_sd);
        }
    }

Implementing the same sequence of commands on Linux works.

Any ideas what I could be missing?

Best regards

Oliver

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]