setting "address.sin_addr.s_addr" + "bind" is kind of a way you can use to
receive requests only from an interface that has a specific IP address.
This is useful if your system has multiple network interfaces and you want
to provide some kind of isolation.
"address.sin_addr.s_addr = INADDR_ANY;" + "bind" is a way that you say "I
want to receive requests from any interface".

So this does not have any relation to the interface you configure via
menuconfig. Obviously if you will set "address.sin_addr.s_addr" to address
configured via menuconfig it will work.

чт, 21 вер. 2023 р. о 15:44 Gustavo Soares <gustavo.felipesoa...@hotmail.com>
пише:

> So setting a value for the IP address in Kconfig and assigning it to
> address.sin_addr.s_addr should solve the problem?
> ________________________________
> De: Petro Karashchenko <petro.karashche...@gmail.com>
> Enviado: quinta-feira, 21 de setembro de 2023 09:35
> Para: dev@nuttx.apache.org <dev@nuttx.apache.org>
> Assunto: Re: different IP than expected
>
> I think that you misunderstood the data flow a bit.
>
> So you have
> ...
>     address.sin_family = AF_INET;
>     address.sin_addr.s_addr = INADDR_ANY;
>     address.sin_port = htons(PORT);
>
>     if (bind(server_fd, (struct sockaddr *)&address, sizeof(address)) < 0)
>     {
>         perror("bind failed");
>         exit(EXIT_FAILURE);
>     }
> ...
>     printf("waiting for requests at %s:%d...\n",
> inet_ntoa(address.sin_addr), PORT);
>
> So you assign INADDR_ANY to a address.sin_addr.s_addrand then call "int
> bind(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen);" that
> has "const" modifier for "addr" parameter hoping that it will modify the
> value that you just assigned. That just simply will not work.
>
> чт, 21 вер. 2023 р. о 15:22 Gustavo Soares <
> gustavo.felipesoa...@hotmail.com<mailto:gustavo.felipesoa...@hotmail.com>>
> пише:
> I've attached a simpler version of the server file removing the logic for
> the incoming requests so you can take a better look. How should I make the
> API call to get the device IP?
> ________________________________
> De: Petro Karashchenko <petro.karashche...@gmail.com<mailto:
> petro.karashche...@gmail.com>>
> Enviado: quinta-feira, 21 de setembro de 2023 09:00
> Para: dev@nuttx.apache.org<mailto:dev@nuttx.apache.org> <
> dev@nuttx.apache.org<mailto:dev@nuttx.apache.org>>
> Assunto: Re: different IP than expected
>
> Yeah,
>
> But what is in between
> [image.png]
> and
> [image.png]
> ???
>
> Do you have any API call to get the IP? Because I read that like "int a =
> 10; printf("%d", a);"
>
> If there is no API call to update "address" then you simply will print
> "INADDR_ANY" value.
>
> чт, 21 вер. 2023 р. о 14:42 MIGUEL ALEXANDRE WISINTAINER <
> tcpipc...@hotmail.com<mailto:tcpipc...@hotmail.com>> пише:
> I mean, ifconfig, and capture the ip…
>
> Enviado do meu iPhone
>
> Em 21 de set. de 2023, à(s) 08:24, Gustavo Soares <
> gustavo.felipesoa...@hotmail.com<mailto:gustavo.felipesoa...@hotmail.com>>
> escreveu:
>
> 
> Hi, Petro!
>
>  I use this struct:
>
> [image.png]
>
> and this where I use the inet_ntoa:
>
> [image.png]
> ________________________________
> De: Petro Karashchenko <petro.karashche...@gmail.com<mailto:
> petro.karashche...@gmail.com>>
> Enviado: quinta-feira, 21 de setembro de 2023 08:16
> Para: dev@nuttx.apache.org<mailto:dev@nuttx.apache.org> <
> dev@nuttx.apache.org<mailto:dev@nuttx.apache.org>>
> Assunto: Re: different IP than expected
>
> Hi,
>
> But what do you pass to "inet_ntoa"? Maybe you get the IP of your PC or a
> default router IP and try to print it?
>
> Best regards,
> Petro
>
> чт, 21 вер. 2023 р. о 14:06 Gustavo Soares <
> gustavo.felipesoa...@hotmail.com<mailto:gustavo.felipesoa...@hotmail.com>>
> пише:
> I don't know if I can reproduce this in another app, but my question is
> why does the server listen to requests in one IP adress (ending with 15)
> and when I retrieve its IP it shows a different one? About the ifconfig
> command, this is the output:
>
> [X]
>
> the server response to the GET request (the request was sent to the
> configured IP using ifconfig):
> [X]
>
> the IP address the server returns with the inet_ntoa() method:
> [X]
>
> ________________________________
> From: Petro Karashchenko <petro.karashche...@gmail.com<mailto:
> petro.karashche...@gmail.com>>
> Sent: Thursday, September 21, 2023 6:59:01 AM
> To: dev@nuttx.apache.org<mailto:dev@nuttx.apache.org> <
> dev@nuttx.apache.org<mailto:dev@nuttx.apache.org>>
> Subject: Re: different IP than expected
>
> Hi,
>
> "INADDR_ANY" definitely does not match "listens to the defined IP"
> statement. I do not understand exactly what you are trying to do, but it
> would be good to know what is the output of "ifconfig" running from NSH.
> If you do not want to share code details, maybe you can check how your
> application behaves on Linux and compare to what behavior you observe with
> NuttX.
> Can this somehow be reproduced with one of the apps available in the NuttX
> repo?
>
> Best regards,
> Petro
>
> чт, 21 вер. 2023 р. о 03:09 Gustavo Soares <
> gustavo.felipesoa...@hotmail.com<mailto:gustavo.felipesoa...@hotmail.com>>
> пише:
> Hello everyone!
>
>  I configured NuttX to a certain IP address and I have a webserver which
> listens to the defined IP:
>
> [X]
>
> [X]
>
> The HTML file above has a variable that contains the server IP address,
> but it is a different one:
>
> [X]
>
> the server replaces the text SERVER_IP_ADDRESS to it's actual IP and then
> sends the file to the client. This is the method I used to get the IP
> address:
>
> [X]
>
> Why is it a different IP? The server is listening to one but this method
> returns another one.
>
>
>

Reply via email to