Changeset 192

Show
Ignore:
Timestamp:
06/29/05 15:36:11
Author:
ben
Message:

64-bit port, find socket libraries.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/configure

    r189 r192  
    99use IO::File; 
    1010 
     11$|=1; 
     12 
    1113our $Log; 
    1214our $LogFile='/dev/null'; 
     
    2022 
    2123our %Subst=( 
    22             'CRYPTO_LIBS' => '-lcrypto', 
    23             'INCLUDES' => '', 
     24            CRYPTO_LIBS => '-lcrypto', 
     25            ZLIB => '-lz', 
     26            INCLUDES => '', 
     27             
    2428           ); 
    2529 
     
    3842              my $loc=shift; 
    3943              $Subst{INCLUDES}.=" -I $loc"; 
     44              $Subst{ZLIB}="$loc/libz.a"; 
    4045          }, 
    4146          '--log=' => sub { 
     
    4348              $Log=new IO::File(">$LogFile"); 
    4449              $Log->autoflush(1); 
     50          }, 
     51          '--64' => sub { 
     52              $Subst{CFLAGS}.=' -m64'; 
    4553          } 
    4654         ); 
     55 
     56my %Functions=( 
     57               'socket' => { headers => ['sys/socket.h'], 
     58                             call => 'socket(0,0,0)', 
     59                             libs => [[],['socket','nsl']] }, 
     60               ); 
    4761 
    4862my @Headers=qw(alloca.h); 
     
    7690findHeaders(\@Headers); 
    7791investigateTypes(\@Types); 
     92my $libs=findLibraries(\%Functions); 
     93$Subst{'LIBS'}=join(' ',map { "-l$_" } @$libs); 
     94#exit; 
    7895 
    7996fixSubst(); 
     
    186203sub build { 
    187204    my $code=shift; 
     205    my $link=shift; 
    188206 
    189207    my $cc=getKnowledge('cc'); 
     
    198216    $fh->close(); 
    199217 
    200     my $cmd="$cc $Subst{INCLUDES} -Wall -Werror -c ".$f; 
    201     trace("$cmd\n--code--\n$code\n--------\n"); 
     218    my $cflag=''; 
     219    $cflag='-c' if !defined $link; 
     220    my $cmd="$cc $Subst{CFLAGS} $Subst{INCLUDES} -Wall -Werror $cflag ".$f; 
     221    $cmd.=" $link" if defined $link; 
     222    trace("$cmd\n--code--\n$code--------\n"); 
    202223    my $ret=system("$cmd >> $LogFile 2>&1"); 
    203224 
     
    205226    $obj =~ s/\.c$/.o/; 
    206227    unlink($obj) || $! == ENOENT || croak "unlink($obj): $!"; 
     228    unlink('a.out') || $! == ENOENT || croak "unlink(a.out): $!"; 
    207229 
    208230    chdir($cur) || croak "chdir($cur): $!"; 
     
    246268 
    247269    foreach my $h (@$headers) { 
     270        print "Check required header $h\n"; 
    248271        build("#include <$h>\n") || croak "Can't find required header $h"; 
    249272    } 
    250273} 
     274 
     275sub findLibraries { 
     276    my $funcs=shift; 
     277 
     278    my @libs; 
     279  func: 
     280    foreach my $func (keys %$funcs) { 
     281        print "Checking libraries for $func()\n"; 
     282        my $code=join("\n",map { "#include <$_>" } 
     283                      @{$funcs->{$func}->{headers}}); 
     284        $code.="\nint main() { $funcs->{$func}->{call}; return 0; }\n"; 
     285        foreach my $lgroup (@{$funcs->{$func}->{libs}}) { 
     286            print "  trying ",@$lgroup ? join(', ',@$lgroup) : 'no libraries'; 
     287            if(build($code,join(' ',map { "-l$_" } @$lgroup))) { 
     288                push @libs,@$lgroup; 
     289                print " ... OK\n"; 
     290                next func; 
     291            } 
     292            print " ... no\n"; 
     293        } 
     294    } 
     295    return \@libs; 
     296} 
     297 
  • openpgpsdk/trunk/examples/Makefile.template

    r140 r192  
    33CC=%CC% 
    44 
    5 CFLAGS=-Wall -Werror -g $(DM_FLAGS) -I../include  %INCLUDES% 
    6 LDFLAGS=-g 
     5CFLAGS=-Wall -Werror -g $(DM_FLAGS) -I../include  %INCLUDES% %CFLAGS% 
     6LDFLAGS=-g %CFLAGS% 
    77LIBDEPS=../src/libops.a 
    8 LIBS=$(LIBDEPS) %CRYPTO_LIBS% -lz $(DM_LIB) 
     8LIBS=$(LIBDEPS) %CRYPTO_LIBS% %ZLIB% $(DM_LIB) %LIBS% 
    99 
    1010all: Makefile lib .depend packet-dump verify create-key create-signed-key 
  • openpgpsdk/trunk/include/packet.h

    r178 r192  
    639639typedef struct 
    640640    { 
    641     size_t                    length; 
     641    unsigned                  length; 
    642642    unsigned char               data[8192]; 
    643643    } ops_literal_data_body_t; 
  • openpgpsdk/trunk/src/Makefile.template

    r186 r192  
    33CC=%CC% 
    44 
    5 CFLAGS=-Wall -Werror -g $(DM_FLAGS) -I../include %INCLUDES% 
     5CFLAGS=-Wall -Werror -g $(DM_FLAGS) -I../include %INCLUDES% %CFLAGS% 
    66LDFLAGS=-g 
    77LIBS=libops.a -lcrypto -lz $(DM_LIB) 
  • openpgpsdk/trunk/src/packet-parse.c

    r176 r192  
    242242/** Read a scalar. 
    243243 * 
    244  * Read a Big Endian scalar of length bytes, respecting packet 
     244 * Read a big-endian scalar of length bytes, respecting packet 
    245245 * boundaries (by calling limited_read() to read the raw data). 
    246246 * 
     
    248248 * 
    249249 * \param *dest         The scalar value is stored here 
    250  * \param length        How many bytes make up this scalar 
     250 * \param length        How many bytes make up this scalar (at most 4) 
    251251 * \param *region       Pointer to current packet region 
    252252 * \param *opt          Pointer to parse options to be used 
     
    264264    int n; 
    265265 
     266    assert(length <= 4); 
     267    assert(sizeof(*dest) >= 4); 
    266268    if(!ops_limited_read(c,length,region,opt)) 
    267269        return 0; 
     
    271273    *dest=t; 
    272274 
     275    return 1; 
     276    } 
     277 
     278/** Read a scalar. 
     279 * 
     280 * Read a big-endian scalar of length bytes, respecting packet 
     281 * boundaries (by calling limited_read() to read the raw data). 
     282 * 
     283 * The value read is stored in a size_t, which is a different size 
     284 * from an unsigned on some platforms. 
     285 * 
     286 * This function makes sure to respect packet boundaries. 
     287 * 
     288 * \param *dest         The scalar value is stored here 
     289 * \param length        How many bytes make up this scalar (at most 4) 
     290 * \param *region       Pointer to current packet region 
     291 * \param *opt          Pointer to parse options to be used 
     292 * \param *cb           The callback 
     293 * \return              1 on success, 0 on error (calls the cb with OPS_PARSER_ERROR in limited_read()). 
     294 * 
     295 * \see RFC2440bis-12 3.1 
     296 */ 
     297static int limited_read_size_t_scalar(size_t *dest,unsigned length, 
     298                                      ops_region_t *region, 
     299                                      ops_parse_options_t *opt) 
     300    { 
     301    unsigned tmp; 
     302 
     303    assert(sizeof(*dest) >= 4); 
     304 
     305    /* Note that because the scalar is at most 4 bytes, we don't care 
     306       if size_t is bigger than usigned */ 
     307    if(!limited_read_scalar(&tmp,length,region,opt)) 
     308        return 0; 
     309 
     310    *dest=tmp; 
    273311    return 1; 
    274312    } 
     
    10001038        /* 2 octets of name length */ 
    10011039 
    1002         if (!limited_read_scalar(&C.ss_notation_data.name.len, 2, 
    1003                                 &subregion, opt)) 
     1040        if (!limited_read_size_t_scalar(&C.ss_notation_data.name.len, 2, 
     1041                                       &subregion, opt)) 
    10041042            return 0; 
    10051043 
    10061044        /* 2 octets of value length */ 
    10071045 
    1008         if (!limited_read_scalar(&C.ss_notation_data.value.len, 2, 
    1009                                 &subregion, opt)) 
     1046        if (!limited_read_size_t_scalar(&C.ss_notation_data.value.len, 2, 
     1047                                       &subregion, opt)) 
    10101048            return 0; 
    10111049