libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] Starting 2 server on same port but different ip addr


From: Christian Grothoff
Subject: Re: [libmicrohttpd] Starting 2 server on same port but different ip address
Date: Wed, 25 Mar 2020 19:14:53 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0

Hi Shikha,

What you can/should do is call socket(), bind() and listen() yourself
first, and then call MHD_start_daemon() using MHD_OPTION_LISTEN_SOCKET
to pass the already bound listen socket.

That way, you can precisely bind to whatever IPs/ports you want to use.

happy hacking!

Christian

On 3/25/20 4:32 PM, Shikha Sharma wrote:
> Hi,
> 
> I was trying to test some scenarios to see what is allowed and what is
> not allowed by MHD in respect to starting 2 servers on same port but
> different IP address.
> 
> The information for passing on the address to MHD_start_daemon api is:
>      addr_hint.ai_family   = AF_UNSPEC;  /* IPv4 or IPv6 */
>     addr_hint.ai_flags    = AI_ADDRCONFIG;
>     addr_hint.ai_socktype = SOCK_STREAM;
> 
> For IPv6 addresses, Daemon is started by calling api 
> MHD_start_daemon(flags, port, MHD_OPTION_SOCK_ADDR, address..) where
> MHD_USE_IPv6 is set in flags.
> 
> For IPv4, is started same way but without MHD_USE_IPv6.
> 
> Below are some of the scenarios that I have tried:
> 
> Scenario 1:
> 
>   * Start S1 on : '0.0.0.0':6666
>   * Start S2 on:  :'fe80::5054:ff:feec:73d1':6666
> 
> The MHD_start_daemon api is okay for S1 but fails for S2.
> 
> Scenario2:
> 
>   * Start S1 on : '0.0.0.0':6666
>   * Start S2 on:  '::':6666
> 
> MHD_start_daemon call is successful on both.
> 
> Scenario3:
> 
>   * Start S1 on : '192.168.11.11':6666
>   * Start S2 on:  '::':6666
> 
> MHD_start_daemon call is successful on both.
> 
> Scenario4:
> 
>   * Start S1 on : '192.168.11.11':6666
>   * Start S2 on:  'fe80::5054:ff:feec:73d1':6666
> 
> MHD_start_daemon call fails on S2.
> 
> Both IP addressed are on same interface.Is this how they are supposed to
> work? Why is it that it fails in scenario 1 but is okay in scenario 3?
> 
> Trying to figure-out if its an issue at my end/expected behavior/issue
> in MHD?
> 
> Thanks & Regards,
> 
> Shikha
> 

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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