#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Posts
    117
    Rep Power
    29

    Convert SDBM_File with hash from little to big endian


    Greetings,

    I've run into an issue where an Apache 'redirect' file, an SDBM file with a .pag and .dir file, that is generated on a little endian machine is not working on the target machine, which is big endian. It appears that Apache is reading the keys but can't determine the values:

    For reasons beyond my control, we have to use SDBM_File in this case as opposed to DB, and the only changes that can be made are on the machine that is the source - not the machine that receives the target redirect files.

    I delved into using pack/unpack in order to convert the stored hash to a big endian friendly format, but the more I work with using pack/unpack, the more I feel that it's either the wrong approach or I'm missing a lot of the details needed to make this work.

    The code below is a compact version of the code that generates the .pag and .dir file for the target Apache server. in this code you can see where I'm attempting to manipulate the hash, unpack it then pack it back into big endian format. I'm so used to hashes just working that I'm not very experienced with reformatting them - I just need this file to work on the target server. Thanks for any help you might be able to provide:

    Code:
    #!/usr/bin/perl
    use Fcntl;   # For O_RDWR, O_CREAT, etc.
    use SDBM_File;
    use Config;
    use Data::Dumper;
    
    print "Byteorder: $Config{ byteorder }\n";
    
    tie(%h, 'SDBM_File', 'packtest', O_RDWR|O_CREAT, 0666)
      or die "Couldn't tie SDBM file 'filename': $!; aborting";
    
    # Add some data to the file
    
    #works when this file script is run on a big endian server to generate the .pag and .dir files
    $h{'/from/test.html'} = '/to/test.html';
    
    %h = pack 's>*', %h;
    
    untie %h;
    Last edited by jkrew_devshed; October 1st, 2013 at 10:46 AM. Reason: Question updated with correct information
    "I'm between quotes right now"

IMN logo majestic logo threadwatch logo seochat tools logo