• Support
  • Need a simple socket for inter-process communication

Hello All :
I need to implement an inter-process communication using a socket in order to make this code very portable into other systems.
I do not care what IP address I would use, and honestly I would prefer some RAW socket without IP and a port number if I could.
My options are

  1. use the loopback address (which I have on the system):

    int sd = socket( AF_INET, SOCK_DGRAM, 0 );

    uart_addr.sin_family = AF_INET;
    uart_addr.sin_addr = inet_addr(“127.0.0.1”); (inet_addr is defined in include/arpa/inet.h , and I do not know how to bring in this header file, as I am compiling in samples/net/sockets/can)
    uart_addr.sin_port = htons( 9090 );

  2. Use the PF_LOCAL (but I can not find a good example on this except https://www.gnu.org/software/libc/manual/html_node/Local-Socket-Example.html,
    but what is the ‘filename’ in this case? This example seems to come from the Sun/Oracle project (which is fine, but I do not see the main() here).
    PF_LOCAL is defined in the Zephyr docs: https://docs.zephyrproject.org/latest/connectivity/networking/api/ip_4_6.html

  3. Another thing I tried
    net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)), as in subsys/net/ip/route.c and tests/net/tcp/src/main.c
    (not sure if this is portable, but I can get away with this if I can get DUMMY defined in my project)


Any option would work for me, but I guess I am not understanding on how to get one of them to work. May be there are other options out there that I did not see.
To me, what I am trying to do seems simple, but I am not able to get over the hump. Any ideas are appreciated! Thank you and Happy Easter.

Also the code (any ideas why?)

  c_sock=socket(AF_INET,SOCK_STREAM,0);
    if(c_sock<0)
    {
     // print an error message
    }

    c_addr.sin_family=AF_INET;
    c_addr.sin_addr.s_addr=htonl(INADDR_ANY);
    c_addr.sin_port=htons(6060);

    if(bind(c_sock,(struct sockaddr_in *)&c_addr,sizeof(c_addr))==0)
    {
        LOG_ERR ("Binding succed!...");
    }
    else
    {
        LOG_ERR ("Binding failed...");
        //return 0;
    }
       k_sleep(K_SECONDS(2));

Generates

<wrn> net_if: You have 1 IPv6 net_if addresses but 2 network interfaces
[00:00:00.501,000] <wrn> net_if: Consider increasing CONFIG_NET_IF_MAX_IPV6_COUNT value.
[00:00:00.501,000] <wrn> net_if: You have 1 IPv4 net_if addresses but 2 network interfaces
[00:00:00.501,000] <wrn> net_if: Consider increasing CONFIG_NET_IF_MAX_IPV4_COUNT value.
*** Booting Zephyr OS build zephyr-v3.3.0-962-g523de0d9be80 ***
_____________________________________________
- Application: /home/kore/zephyrproject/zephyr/samples/net/sockets/can
-- **CMake version: 3.22.1**
-- Found Python3: /usr/bin/python3.10 (found suitable exact version "3.10.6") found components: Interpreter 
-- Cache files will be written to: /home/kore/.cache/zephyr
-- **Zephyr version: 3.3.99** (/home/kore/zephyrproject/zephyr)

    Hi olgamill55 unfortunately I haven’t done anything like you’ve suggested above. You may be on your own with this one. 😇

      jaredwolff Thank you, I am figuring it out (slowly). The error that I indicated is fixed by adding to prj.conf:
      CONFIG_NET_IF_MAX_IPV4_COUNT=3 (if the loopback is enabled by CONFIG_NET_LOOPBACK=y0 and
      CONFIG_NET_IF_MAX_IPV4_COUNT=2 (if the loopback is not enabled).
      This error also slows down the startup process because the system is waiting for an interface to appear on the startup, but there is no such an interface.

      Terms and Conditions | Privacy Policy