Recent

Author Topic: Can't find unit unixsockets  (Read 1698 times)

TCH

  • Sr. Member
  • ****
  • Posts: 275
    • Oldschool computer
Can't find unit unixsockets
« on: February 15, 2025, 11:53:59 pm »
I am porting some C code to FreePascal which relies on macros like CMSG_LEN, CMSG_DATA, etc. and types like struct msghdr, struct cmsghdr, etc.

I found these listed in here; for instance: https://www.freepascal.org/daily/packages/libc/libc/cmsghdr.html. It says, it is in unit libc. However, after putting uses libc into the code, i get this message:
Code: [Select]
Fatal: Can't find unit libc used by unit_nameAfter some searching for this error message, i found this topic and this manual page.
Okay, so unit libc is not allowed. But what to use instead? The manuals do not say at all...

After some more searching, i found this mail thread, which states, these are in unit unixsockets. Well, unixsockets is under packages/rtl-extra/src/unix/ all right, but when i put uses unixsockets into the code, i get this message:
Code: [Select]
Fatal: Can't find unit unixsockets used by unit nameSearching for this error message only yielded a supplementary unixsockets unit, but i'd rather use the one provided by the RTL.

How can i use CMSG_LEN, struct msghdr, etc. with FreePascal?

Thaddy

  • Hero Member
  • *****
  • Posts: 16652
  • Kallstadt seems a good place to evict Trump to.
Re: Can't find unit unixsockets
« Reply #1 on: February 16, 2025, 12:42:06 pm »
Why would you want a unit named linux sockets?
The sockets unit is pure berkely sockets, so unix sockets...
Their structures should also have equivalents in fcl-net.
Maybe you want the translated syntax to mimic the C code simply too close and so you would want to work with code that is deprecated.
Any code that requires the libc unit is deprecated, afaik, not the libc library.
This may help:
https://wiki.freepascal.org/libc_unit
That also describes you should use sockets not unixsockets.
In general it will help you port code in a more sane way,
« Last Edit: February 16, 2025, 02:30:51 pm by Thaddy »
But I am sure they don't want the Trumps back...

Alexx2000

  • New Member
  • *
  • Posts: 14
Re: Can't find unit unixsockets
« Reply #2 on: February 16, 2025, 02:27:54 pm »
Quote
How can i use CMSG_LEN, struct msghdr, etc. with FreePascal?
Something like this.

Thaddy

  • Hero Member
  • *****
  • Posts: 16652
  • Kallstadt seems a good place to evict Trump to.
Re: Can't find unit unixsockets
« Reply #3 on: February 16, 2025, 02:30:16 pm »
That would do the trick.. 8)
But I am sure they don't want the Trumps back...

TCH

  • Sr. Member
  • ****
  • Posts: 275
    • Oldschool computer
Re: Can't find unit unixsockets
« Reply #4 on: February 16, 2025, 04:35:39 pm »
Why would you want a unit named linux sockets?
The sockets unit is pure berkely sockets, so unix sockets...
:o What...? Seriously...what? Who wanted a unit named linux sockets? I explicitly wrote unixsockets several times. My post did not even contain the word "Linux". I have no idea what are you talking about.
Their structures should also have equivalents in fcl-net.
Which are...?
Maybe you want the translated syntax to mimic the C code simply too close and so you would want to work with code that is deprecated.
Any code that requires the libc unit is deprecated, afaik, not the libc library.
This may help:
https://wiki.freepascal.org/libc_unit
I know. I've even linked in the very same manual page what you did...
That also describes you should use sockets not unixsockets.
In general it will help you port code in a more sane way,
sockets has already been pulled in (i just forgot to mention it), but it did not provide CMSG_LEN and the rest.
Quote
How can i use CMSG_LEN, struct msghdr, etc. with FreePascal?
Something like this.
Thank you, but this is also just a supplementary unixsockets unit, just like the one made by md and what i use now. I'd like to stick to the RTL. Or do you mean, it is not possible to do it with unixsockets and that one has to provide those functions and structures by hand?
« Last Edit: February 16, 2025, 04:43:32 pm by TCH »

Alexx2000

  • New Member
  • *
  • Posts: 14
Re: Can't find unit unixsockets
« Reply #5 on: February 16, 2025, 04:54:05 pm »
I guess unixsockets unit simply is not installed (binary unixsockets.ppu). What Linux distro do you use?

TCH

  • Sr. Member
  • ****
  • Posts: 275
    • Oldschool computer
Re: Can't find unit unixsockets
« Reply #6 on: February 16, 2025, 04:58:16 pm »
Debian 11, but i use the packages provided by the Lazarus Team, not by Debian Team. unixsockets.pp does exist in packages/rtl-extra/src/unix/. You say, it should be compiled to a PPU? I thought FreePascal automatically does that: if the .ppu does not exist, but the .pp or .pas does, then it compiles the source to a binary unit. Or that only applies to the local units, not the global ones?

Alexx2000

  • New Member
  • *
  • Posts: 14
Re: Can't find unit unixsockets
« Reply #7 on: February 16, 2025, 05:03:05 pm »
Quote
You say, it should be compiled to a PPU?
Yes. It is a standard practice of binary distro.

Quote
I thought FreePascal automatically does that
It can do it. But only if unit in the unit search paths.

TCH

  • Sr. Member
  • ****
  • Posts: 275
    • Oldschool computer
Re: Can't find unit unixsockets
« Reply #8 on: February 16, 2025, 05:17:18 pm »
I see, thank you. I've tried to do fpc unixsockets.pp, but:
Code: [Select]
Free Pascal Compiler version 3.2.2 [2021/07/09] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling unixsockets.pp
unixsockets.pp(12,2) Warning: Illegal compiler directive "$UNIXSOCKETSH"
unixsockets.pp(16,2) Warning: Illegal compiler directive "$UNIXSOCKETS"
19 lines compiled, 0.0 sec
2 warning(s) issued
The PPU was created, but i guess it is erroneous. Or not? What flags i should provide?

Alexx2000

  • New Member
  • *
  • Posts: 14
Re: Can't find unit unixsockets
« Reply #9 on: February 16, 2025, 05:35:57 pm »
Looks like this unit are buggy. It should be:
Code: Pascal  [Select][+][-]
  1. unit unixsockets;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. {$packrecords C}
  6.  
  7. interface
  8.  
  9. uses
  10.   cTypes, BaseUnix;
  11.  
  12. {$I unixsocketsh.inc}
  13.  
  14. implementation
  15.  
  16. {$I unixsockets.inc}
  17.  
  18. end.
  19.  
also you need to have files:
Quote
rtl-extra\src\linux\unixsockets.inc
rtl-extra\src\linux\unixsocketsh.inc
in the include files search paths.

It looks like no one has even tried to compile it.

TCH

  • Sr. Member
  • ****
  • Posts: 275
    • Oldschool computer
Re: Can't find unit unixsockets
« Reply #10 on: February 16, 2025, 05:57:50 pm »
Thanks, i fixed the file, but i cannot compile it. I tried to include the path with both -I and -Fi, but no avail. I tried /usr/share/fpcsrc/3.2.2/packages/rtl-extra/src/linux/, 3.2.2/packages/rtl-extra/src/linux/, packages/rtl-extra/src/linux/ and rtl-extra/src/linux/, but:
Code: [Select]
unixsockets.pp(12,2) Fatal: Cannot open include file "$unixsocketsh.inc"The file does exist, i've checked it.

Alexx2000

  • New Member
  • *
  • Posts: 14
Re: Can't find unit unixsockets
« Reply #11 on: February 16, 2025, 06:07:17 pm »
Are you fixed a unit as I show above?

Quote
-Fi/usr/share/fpcsrc/3.2.2/packages/rtl-extra/src/linux
should work.


But, looks like this unit a totally broken. I don't know why it is included in the FPC distro at all.

TCH

  • Sr. Member
  • ****
  • Posts: 275
    • Oldschool computer
Re: Can't find unit unixsockets
« Reply #12 on: February 16, 2025, 06:28:48 pm »
I did, but i screwed up, i left the dollar sign at the beginning of the files... :/

Thanks, now it tries to compile, but fails:
Code: [Select]
unixsockets.inc(12,12) Error: Identifier not found "__cmsg_nxthdr"
unixsockets.pp(20) Fatal: There were 1 errors compiling module, stopping
This is caused by rtl-extra/src/linux/unixsockets.inc:12:
Code: Pascal  [Select][+][-]
  1. function CMSG_NXTHDR(mhdr: Pmsghdr; cmsg: Pcmsghdr): Pcmsghdr;
  2. begin
  3.    Result:=__cmsg_nxthdr(mhdr, cmsg);
  4. end;
rtl-extra/src/linux/unixsockets.inc seems to be also buggy: it lacks this line:
Code: Pascal  [Select][+][-]
  1. function __cmsg_nxthdr(__mhdr:Pmsghdr; __cmsg:Pcmsghdr):Pcmsghdr;cdecl;external 'c' name '__cmsg_nxthdr';
If i include it, then it dies with this message:
Code: [Select]
unixsocketsh.inc(32,12) Error: Forward declaration not solved "CMSG_DATA(Pcmsghdr):^Byte;"Which is caused, that rtl-extra/src/linux/unixsocketsh.inc:32 says:
Code: Pascal  [Select][+][-]
  1.   function CMSG_DATA(cmsg : pcmsghdr) : Pbyte;
while rtl-extra/src/linux/unixsockets.inc:32 says:
Code: Pascal  [Select][+][-]
  1. function CMSG_DATA(cmsg: Pointer): PByte;
I am not sure, but i guess, the header is correct and the body is erroneous. After changing cmsg: Pointer to cmsg: Pcmsghdr, the unit finally compiles. Whew...

You were right. It was totally broken. Even the includes were. But now my unit finally compiles with using the bundled unixsockets unit. Thank you very much for your help. :)

I think these fixes on the unit and the includes should be sent to FPC team.

Thaddy

  • Hero Member
  • *****
  • Posts: 16652
  • Kallstadt seems a good place to evict Trump to.
Re: Can't find unit unixsockets
« Reply #13 on: February 17, 2025, 08:18:06 am »
But, looks like this unit a totally broken. I don't know why it is included in the FPC distro at all.
It should be broken, must be broken otherwise and marked as deprecated, because it is deprecated and not maintained. It's presence is unwarranted and it should be removed to prevent people using it.

I told you so, use sockets. Now somebody is writing code that is close to its grave at its conception. You should discourage such code, not try to fix it.
« Last Edit: February 17, 2025, 08:21:02 am by Thaddy »
But I am sure they don't want the Trumps back...

Thaddy

  • Hero Member
  • *****
  • Posts: 16652
  • Kallstadt seems a good place to evict Trump to.
Re: Can't find unit unixsockets
« Reply #14 on: February 17, 2025, 08:30:38 am »
Reported as request to mark deprecated on the bug tracker:
#41152 but I temporary closed it because I can provide a patch.
[edit]
Re-opened without patch. That would be counter to the report.
« Last Edit: February 17, 2025, 08:59:43 am by Thaddy »
But I am sure they don't want the Trumps back...

 

TinyPortal © 2005-2018