in reply to Managing C structs -with Perl-
update:
I tried the above, and got#!/usr/bin/perl -w use C::Include; use strict; use vars qw/$inc $send $buffer/; $inc = new C::Include( \*DATA ); # Make struct instance $send = $inc->make_struct('send'); use Data::Dumper; print Dumper $send; # Fill struct fields $$send{prevpass} = '0123456789'; $$send{answer} = 1; # Pack struct to buffer $buffer = $send->pack(); # Struct size printf "Size of struct send: %d bytes\n", $send->size; printf "Size of unsigned long: %d bytes\n", $inc->sizeof('unsigned lon +g'); # Print buffer to STDOUT &hview( \$buffer ); #require 'hview.pl'; ## crazyinsomniac's note ~ hview.pl is distributed with the module, pr +ops to the author sub hview(\$){ my $str = shift; my @lines = unpack 'a16'x(length($$str)/16+(length($$str)%16?1:0)) +, $$str; for( 0..$#lines ){ printf "%08X: %-17sł %-17s %-16s\n", $_*16, (map{ sprintf '%-2s ' x 8, map{ sprintf'%02X',$_ }unpack 'C*', $_ }unpack 'a8a8', $lines[$_]), $lines[$_]; } } 1; __END__ #define PORT 2345 #define CHALLENGE 0 #define CORRECT 1 #define WRONG 2 struct recv { int flag; int b[4]; char nextpass[10]; }; typedef struct recv t_recv; struct send { int answer; char prevpass[10]; }; typedef struct send t_send;
That seems pretty cool.$>perl test4.pl $VAR1 = bless( { '' => { 'length' => 14, 'mask' => 'iZ10', 'tag' => 'send', 'buffers' => [ \undef, \undef ] }, 'prevpass' => ${$VAR1->{''}{'buffers'}[1]}, 'answer' => ${$VAR1->{''}{'buffers'}[0]} }, 'C::Include::Struct' ); Size of struct send: 14 bytes Size of unsigned long: 4 bytes 00000000: 01 00 00 00 30 31 32 33 ¦ 34 35 36 37 38 00 012 +345678 $>
I tried $VERSION = 1.20;, but It didn't like your macro (WARNING: Unashed code ...) so I upgraded ... and all this after plenty of rum and coke (and some Jose Quervo tequila to boot)
| ______crazyinsomniac_____________________________ Of all the things I've lost, I miss my mind the most. perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;" |
|
|---|