in reply to Re^9: Help with Lorcon XS library
in thread Help with Lorcon XS library

Hi again, yes, I am considering the idea of donating something,I have good memories linked to Perl, since the start of this summer I started writing some articles for the perl.com, I am still waiting the publication, hope soon. I am writing again because the "enemy" strickes back, while I was testing the lorcon_create I tried to put everything into the "new" subroutine for the function initialization, the code is as follows:
sub new { my (undef, undef, $interface, undef, $driver) = @_; my $self = shift->SUPER::new( driver => $driver, interface => $interface, @_, ); my $drv = lorcon_find_driver($self->driver); if (! $drv) { die "[*] new: lorcon_find_driver: failed\n"; return; } $self->driver( $drv ); my $context = lorcon_create($self->interface, $drv); #_drv if (! $context) { die "[*] new: lorcon_create: failed\n"; return; } $self->_context($context) or die $!; return $self; }
the only big problem stands when I tried to call the setInjectMode it produces a core dump (again). the code is:
sub setInjectMode { my $self = shift; my $r = lorcon_open_inject($self->_context);#->_context); if ($r == -1) { die "[*] setInjectMode: lorcon_open_inject: " . lorcon_get_error +( $self->_context ) . "\n"; return; } return 1; }
I think that there is something wrong in the $self->_context variable, perhaps I haven't understood the use of "_context" **update** dumping the Lorcon initialization variable the result was:
$VAR1 = bless( [ \152150320, 'wlo1', undef, \152168944 ], 'Net::Lorcon2' );
I think that the "undef" is referred to the _drv, the \152150320 is the $driver. the \152150320 changes to 'madwifing' modifyng those 2 lines
# $self->driver( $drv ) ; my $context = lorcon_create($self->interface, $drv); #_drv
regards Edoardo M.

Replies are listed 'Best First'.
Re^11: Help with Lorcon XS library
by syphilis (Archbishop) on Jul 22, 2020 at 01:59 UTC
    ... when I tried to call the setInjectMode it produces a core dump (again)

    Unfortunately I know as much about Lorcon as AnomalousMonk.
    All I'm doing is going from the module's documentation, and the two scripts that ship with the Net-Lorcon2-2.03 source distribution (in the examples folder).
    One of those scripts (inject.pl) demonstrates a correct way to call lorcon_open_inject as follows:
    use strict; use warnings; my $interface = 'wlan1'; my $driver = 'mac80211'; use Net::Lorcon2 qw(:subs); my $lorcon = Net::Lorcon2->new( interface => $interface, driver => $driver, ); $lorcon->setInjectMode; # Beacon my $packet = "\x80\x00\x00\x00\xff\xff\xff\xff\xff\xff\x00\x02\x02\xe2 +\xc4\xef\x00\x02\x02\xe2\xc4\xef\xd0\xfe\x37\xe0\xae\x0c\x00\x00\x00\ +x00\x64\x00\x21\x08\x00\x0b\x4e\x65\x74\x3a\x3a\x4c\x6f\x72\x63\x6f\x +6e\x01\x08\x82\x84\x8b\x96\x0c\x12\x18\x24\x03\x01\x0d\x05\x04\x00\x0 +1\x00\x00\x2a\x01\x00\x32\x04\x30\x48\x60\x6c"; while (1) { my $t = $lorcon->sendBytes($packet); if (! $t) { print "[-] Unable to send bytes\n"; exit 1; } print "T: $t\n"; sleep(1); }
    (You might want to change the strings that are assigned to $interface and $driver.)
    Assuming that works ok for you, my advice would be to just stick with the approaches that you know to work.

    Note that the SYNOPSIS section of the documentation in Lorcon2.pm (run perldoc Net::Lorcon2 to view it) mentions 2 ways to writing Net::Lorcon2 code.
    Firstly there's "Usage in an OO-way", which involves calling new(). This is the way taken by the code that I've provided in this post.
    Secondly there's "Usage with lorcon2 library API", in which new() is not called. This is the way taken by the code I provided in my earlier posts.

    It's best to stick to just one of those ways throughout your script. Mixing them together in the same script will likely lead to errors or segfaults.

    Also, if you hit a problem, please post the entire script you ran - not just bits of it.
    If the script is a large one you should reduce it so that it:
    a) still demonstrates the problem you are facing;
    b) is as small as possible.
    But, for now, while the scripts are quite small, just post them in full.

    Cheers,
    Rob
      Hi! your program crashes. the smallest program which let me crash is the following:
      use strict; use warnings; my $interface = 'wlo1'; my $driver = 'madwifing'; use Net::Lorcon2 qw(:subs); my $lorcon = Net::Lorcon2->new( interface => $interface, driver => $driver, ); $lorcon->setInjectMode;
      I think that the problem still stands in the code, also if I call  lorcon_open_inject the program crashes,regarding the code probably the "_context" make some type of error:
      our @AS = qw( driver interface _drv _context ); __PACKAGE__->cgBuildAccessorsScalar(\@AS); __PACKAGE__->cgBuildIndices; # ... sub new { my $drv = lorcon_find_driver($self->driver); if (! $drv) { die "[*] new: lorcon_find_driver: failed\n"; return; } $self->driver( $drv ) ; my $context = lorcon_create($self->interface, $drv); #_drv if (! $context) { die "[*] new: lorcon_create: failed\n"; return; } $self->_context($context) or die $!; return $self; } sub setInjectMode { my $self = shift; my $r = lorcon_open_inject($self->_context);#->_context);
      The most interesting part is at the end, it calls  lorcon_open_inject with $self->_context which is into
      our @AS = qw( driver interface _drv _context );
      but I haven't still understood for what stands. also the  lorcon_open_inject( $lorcon ); # where $lorcon = lorcon_create($if, $driver) causes a crash regards. Edoardo M.
        I wasn't expecting an example script provided in the Net-Lorcon2-2.03 distribution to fail.
        Question 1: What version of perl are you running ? (The output of perl -v probably tells us enough.)
        Question 2: Have you installed version 2.03 of Net::Lorcon2 ? If not, please install version 2.03.
        Question 3: Have you altered any of the code in any of the Net::Lorcon2 files ? If so, please revert your changes and install Net-Lorcon-2.03 again.

        Otherwise, it's a bug in Net::Lorcon2 or Class::Gomor::Array and we will probably need Gomor (or someone else) to sort it out for us.

        I think you're right to be suspicious of the _context method.
        "_context" starts off as a string in Net::Lorcon2, but apparently gets transformed by the involvement of Class::Gomor::Array into a method. I haven't looked at how that process might be working (or malfunctioning).
        I fear that I wouldn't understand it even if I did look.

        Cheers,
        Rob
Re^11: Help with Lorcon XS library
by AnomalousMonk (Archbishop) on Jul 21, 2020 at 16:36 UTC

    Unfortunately, I know nothing of Lorcon2 or any other Lorcon! :( Perhaps consider sending a private /msg to syphilis to alert him to the presence of your latest node (node number 11119611).


    Give a man a fish:  <%-{-{-{-<