Here's some working code that I created to show the problem.
First the MySQL database dump
-------------------------------------------------------------
CREATE DATABASE /*!32312 IF NOT EXISTS*/ pbug;
USE pbug;
CREATE TABLE hosts (
id int(11) NOT NULL auto_increment,
ip int(4) unsigned default NULL,
password varchar(32) default NULL,
description varchar(255) default '',
clone int(4) unsigned default '0',
conn int(4) unsigned default '0',
status int(4) unsigned default '0',
tdate timestamp(14) NOT NULL,
alarms int(11) unsigned default '0',
monitored int(11) unsigned default '0',
installed int(11) unsigned default '0',
soft_ver_major int(4) default '0',
soft_ver_minor int(4) default '0',
soft_ver_incr int(4) default '0',
hard_ver_major int(4) default '0',
hard_ver_minor int(4) default '0',
hard_ver_incr int(4) default '0',
case_temp int(4) default '-1',
cpu1_temp int(4) default '-1',
cpu2_temp int(4) default '-1',
ext_temp int(4) default '-1',
PRIMARY KEY (id),
UNIQUE KEY ip (ip)
) TYPE=MyISAM;
INSERT INTO hosts VALUES (1,168430090,'crystal','Demo
XXXXXXXX',0,129,0,20031020210116,0,61,7,0,0,0,0,0, 0,29,-1,-1,-1);
INSERT INTO hosts VALUES (2,185273099,'password','Test XXXXXXXX
#1\r\n',0,129,0,20031020210117,57,2045,2047,0,0,0, 0,0,0,31,-1,-1,-1);
INSERT INTO hosts VALUES (3,202116108,'password','Another
XXXXXXXX\r\n\r\n',0,129,0,20031020210118,3,7,63,0, 0,0,0,0,0,30,-1,-1,-1);
--------------------------------------------
Put this into a file and add it to your mysql server.
type: mysql -u <username> -p<password> < pbug.sql
Ok, and here's my little perl module that demonstrates the error (or
my stupidity).
------------------------------------------------
#!/usr/bin/perl -w
use strict;
use warnings;
use DBI;
foreach (1..3)
{
my @dat = &GetHostStatus( $_ );
print "$_: ";
#printf "0x%x & 0x%x & 0x%x & 0x7fff = ", $dat[3], $dat[4],
$dat[5];
print $dat[3] & $dat[4] & $dat[5] & 0x7fff;
print "\n";
}
1;
################################################## ######################
sub GetHostStatus()
{
my $id = shift || return ();
my $db = DBI->connect( 'dbi:mysql

bug','bla','bla' ) || die(
DBI->errstr );
my $query = "SELECT ip, password, description, alarms, monitored,
installed, case_temp, cpu1_temp, cpu2_temp, ext_temp FROM hosts WHERE
id = $id";
my $sth = $db->prepare( $query ) || die( DBI->errstr );
$sth->execute() || die( DBI->errstr );
my @row = $sth->fetchrow_array();
$sth->finish;
$db->disconnect;
return @row;
}
--------------------------------------------------
When I run this on my system, here is my output:
1: 0
2: 0
3: 2
Clearly incorrect. Now, when I uncomment that printf line:
1: 0x0 & 0x3d & 0x7 & 0x7fff = 0
2: 0x39 & 0x7fd & 0x7ff & 0x7fff = 57
3: 0x3 & 0x7 & 0x3f & 0x7fff = 3
Then it works.. Hmm...
I've tested this on 2 separate systems now with the same results, I'd
be interested to see if any of you guys can duplicate it also? Or
tell me where I screwed up, that would be better (and more likely).
Regardless, I'd appreciate any feedback.
- Chris