Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-06

Linux RecvMsg( ) Calls Missing

3 messages · 1 person · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

I was looking through the RTL and found that cfprecvmsg( ) socket calls into the C Run Time library were commented out.

Also commented out cfpsendmsg( ) calls.

While recvfrom( ) is available, it does not include the PTKINFO options necessary to determine a destination IP address on a multi interface Linux server.

Nor does it offer the ability to set the Source Address when sending via sendto( )

Anybody have a quick suggestion or must I spend the afternoon implementing cfprecvmsg( ) and cfpsendmsg( ) calls.

Thanks,

Marco

Reply by email

Unknown author
to Unknown author

Ok, I am getting closer.

Under the unixsockets in RTL, it has all the declarations necessary.

Anybody have an idea on how to use unixsockets in a uses clause so the compiler will not trigger:

Can't find unit 'unixsockets' used by xxxx.pas

Or should I just add the RTL to my project path?

Thanks for any responses,

marco

Show quoted text 23 lines
I was looking through the RTL and found that cfprecvmsg( ) socket calls into the C Run Time library were commented out. Also commented out cfpsendmsg( ) calls. While recvfrom( ) is available, it does not include the PTKINFO options necessary to determine a destination IP address on a multi interface Linux server. Nor does it offer the ability to set the Source Address when sending via sendto( ) Anybody have a quick suggestion or must I spend the afternoon implementing cfprecvmsg( ) and cfpsendmsg( ) calls. Thanks, Marco _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Unknown author
to Unknown author

See solution below:

Show quoted text 28 lines
On 6/15/2014 6:08 PM, wrote: > I was looking through the RTL and found that cfprecvmsg( ) socket calls > into the C Run Time library were commented out. > > Also commented out cfpsendmsg( ) calls. > > While recvfrom( ) is available, it does not include the PTKINFO options > necessary to determine a destination IP address on a multi interface > Linux server. > > Nor does it offer the ability to set the Source Address when sending via > sendto( ) > > Anybody have a quick suggestion or must I spend the afternoon > implementing cfprecvmsg( ) and cfpsendmsg( ) calls. > > Thanks, > > Marco > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

On 6/15/2014 6:26 PM, wrote:> Ok, I am getting closer.

Show quoted text 16 lines
Under the unixsockets in RTL, it has all the declarations necessary. Anybody have an idea on how to use unixsockets in a uses clause so the compiler will not trigger: Can't find unit 'unixsockets' used by xxxx.pas Or should I just add the RTL to my project path? Thanks for any responses, marco

It borrows heavily from RTL, but is now confirmed to work on Linux 2.6.x +

Sorry to pepper the list...

Here is the solution:

A copied unixsockets file usable in fpc 2.6.4/lazarus 1.2.x

unit fpunixsocket;
{$mode objfpc}{$H+}
{$packrecords C}
interface

uses
sockets,
cTypes,

  BaseUnix;
type
  Piovec = ^Tiovec;
  Tiovec = record
    iov_base : pointer;
    iov_len : size_t;
  end;
  Pmsghdr = ^Tmsghdr;
  Tmsghdr = record
     msg_name : pointer; //8
     msg_namelen : socklen_t; //4
     msg_iov : piovec; //8
     msg_iovlen : size_t; //8
     msg_control : pbyte ; //8
     msg_controllen : size_t; //8
     msg_flags : cInt; //4
  end;
  Pcmsghdr = ^Tcmsghdr;
  Tcmsghdr = record
    cmsg_len   : size_t;
    cmsg_level : cInt;
    cmsg_type  : cInt;
  end;
  Ppktinfo = ^Tpktinfo;
  Tpktinfo = record
    ipi_ifindex : longint;
    ipi_spec_dst : in_addr;
    ipi_addr : in_addr;
  end;
  function fpsendmsg(__fd: cInt; __message: pmsghdr; __flags: cInt):
ssize_t; cdecl; external 'c' name 'sendmsg';
  function fprecvmsg(__fd: cInt; __message: pmsghdr; __flags: cInt):
ssize_t; cdecl; external 'c' name 'recvmsg';
  function __cmsg_nxthdr(__mhdr:Pmsghdr;
__cmsg:Pcmsghdr):Pcmsghdr;cdecl;external 'c' name '__cmsg_nxthdr';
  function CMSG_FIRSTHDR(mhdr: Pmsghdr): Pcmsghdr;
  function CMSG_NXTHDR(mhdr: Pmsghdr; cmsg: Pcmsghdr): Pcmsghdr;
  function CMSG_ALIGN(len: size_t): size_t;
  function CMSG_SPACE(len: size_t): size_t;
  function CMSG_LEN(len: size_t): size_t;
  function CMSG_DATA(cmsg: Pcmsghdr): Pointer;
implementation
function CMSG_FIRSTHDR(mhdr: Pmsghdr): Pcmsghdr;
begin
  if mhdr^.msg_controllen >= SizeOf(Tcmsghdr) then
    Result:=Pointer(mhdr^.msg_control)
  else
    Result:=nil;
end;
function CMSG_NXTHDR(mhdr: Pmsghdr; cmsg: Pcmsghdr): Pcmsghdr;
begin
   Result:=__cmsg_nxthdr(mhdr, cmsg);
end;
function CMSG_ALIGN(len: size_t): size_t;
begin
  Result:=(len+SizeOf(size_t)-1) and (not(SizeOf(size_t)-1));
end;
function CMSG_SPACE(len: size_t): size_t;
begin
  Result:=CMSG_ALIGN(len)+CMSG_ALIGN(SizeOf(Tcmsghdr));
end;
function CMSG_LEN(len: size_t): size_t;
begin
  Result:=CMSG_ALIGN(SizeOf(Tcmsghdr))+len;
end;
function CMSG_DATA(cmsg: Pcmsghdr): Pointer;
begin
  Result:=Pointer(  cuint64(cmsg) + SizeOf(Tcmsghdr));
end;
end.

Reply by email