Where to find the correct definitions

Hi all,

Sorry for the following (probably very thumb) question:
I allways fight with finding the correct definition of functions and especially of structures.
This time - for example - I try to analyse ‘struct mg_connection’, because I want to extract the peer ip address. Surfing through the internet, I find two different definitions of this structure: One containing a member ‘peer’ and a second with a member ‘sa’. Obviously, when I do a remote build with mos.exe (version 2.19.0), the second one is taken. I do not know why, because the remote build is a black box for me.
So my question: Where do I find ALL the necessary/correct include files that are taken by mos.exe in a remote build for ESP8266 and ESP32?

Thanks for any input and sorry again for this question.
Rolf

struct mg_connection is defined in mongoose.h from the mongoose library.

You can search the include files for the libraries your application is using. Usually a library places the public include files in the include directory. E.g. https://github.com/mongoose-os-libs/mongoose/tree/master/include

Hi nliviu,

Thanks for your answer.
And what is the next step? I am locking now for ‘union socket_address’. Do you know, where can I find this? And is there a general rule how to find the next include file?
Its a kind of ‘needle in the hay’ …

Rolf

union socket_address is defined in the same file.

And ‘struct sockaddr’?
And is ‘MG_ENABLE_IPV6’ set or not?

Check the mos.yml of the relevant libray/libraries:

Thanks, very interesting!
And ‘struct sockaddr’?

Sorry, I mean ‘SlSockAddr_t’, because this is used to define ‘sockaddr’:


#define socklen_t SlSocklen_t
#define sockaddr SlSockAddr_t
#define sockaddr_in SlSockAddrIn_t
#define in_addr SlInAddr_t

Shortly: I like to extract the senders ip address from an incomming connecten to my UDP server. As text or as integer, whatever …

You need the sa.sin.sin_addr.s_addr component of struct mg_connection

  // remote IP
  uint32_t remote_ip_network_order =
      nc->sa.sin.sin_addr.s_addr;  // network order
  uint32_t remote_ip_host_order = ntohl(remote_ip_network_order);  // host order
  // remote ip as string. Modified from
  // https://github.com/mongoose-os-libs/http-server/blob/5b4c77fb71e151625470b09fe52a1b0dbddadc77/src/mgos_http_server.c#L177-L180
  char addr[32];
  mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
                      MG_SOCK_STRINGIFY_IP);  // needs #include "mongoose.h"

  LOG(LL_INFO, ("remote_ip_network_order: 0x%08lX, remote_ip_host_order: "
                "0x%08lX, addr: %s",
                (unsigned long) remote_ip_network_order,
                (unsigned long) remote_ip_host_order, addr));

where nc is a struct mg_connection *.

Google for struct sockaddr_in.

Thanks a lot, it works!
But is there a generic way to find these definitions that lay outside of mos?

sockaddr_in is standard socket interface, Berkeley sockets; you will most likely find them in many networking stacks.