On vr, 13 dec 2019 08:24:34 +0100, Oleksij Rempel wrote: > On Fri, Dec 13, 2019 at 08:02:53AM +0100, Oleksij Rempel wrote: > > Hi Elenita, > > > > On Thu, Dec 12, 2019 at 03:49:48PM -0600, Elenita Hinds wrote: > > > Hi Kurt, > > > > > > I tried using getsockname() to retrieve the source address that was > > > successfully claimed by jacd but was always getting 0xfe (I was > > > expecting it to be 0xf9 as claimed by jacd). > > > Is getsockname() expected to be functional for J1939 with kernel v5.4? > > > Is there another way to retrieving the dynamically claimed address real-time? > > > > Current stack implementation will return on getsockname(sock, ...) and > > getpeername(sock, ...) values provided by user via bind() and/or connect(). If > > we configure the socket by name, then address are automatically resolved > > over address claim cache. > > Hm.. this sentence can be misinterpreted. I'll rephrase it: > > The address are automatically resolved for internal use. And could be > potentially resolved for get[sock,peer]name() as well. While being sure that it is possible, looking back at the kernel code, I realised that the effective address is never cached per socket, which is good. > > > The question is, should we return some thing different? > > If yes, it will be interesting to know, why is it needed? What is the > > use case? It started with: > > > > > > (3) The claimed address is only saved to a file when the program > > > > > > terminates. What is the reason for this? Can it not be saved after > > > > > > one is claimed already so that another process can read it real-time > > > > > > if needed? > > > > > > > > > > That should not be necessary. > > > > > At time of writing jacd, you could consult 'ip addr show can0' to find > > > > > out. I'm not sure what option remained to find it. > > > > > I believe you can, from another program, bind() with the same name, and > > > > > then getsockname() will return the complete sockaddr_can with SA filled > > > > > in. Getting the response from the kernel would eliminate a cache effect, but I'm wrong there, a result via getsockname() is equally subject to caching. > > > > > > Also, in cases of a program crash or a power outage, the > > > > > > claimed address is still saved. > > > > > > > > > > That is a true remark. > > > > > Given a power outage (the program never crashes :-) ), > > > > > and looking at the code, +10 years later, I would now write to a temp file, > > > > > and rename() the file to make it an atomic operation. > > > > > Doing that regularly, or upon change, would be an improvement. Since saving the address in a cache file from jacd is good practise to guard against power failures, the quick solution is to use that cache file from anywhere you want. Kind regards, Kurt