2006-03-24 nvidia woes
Why nvidia don't use the GPL license is beyond me. I could have saved much time fiddling around with twin view after getting the 2.6.16 sources today. For those who may also have problems, note that the nvidia binary driver itself is subject to requireing patches.
2006-03-18 cgi in c
Today I have spent a couple of minutes looking at how I can tackle a problem of CGI in C. To begin with I started with a simple program, just to print the HTML headers
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[] )
{
printf( "Content-type: text/html\n\n" );
printf( "<form method=post action=/cgi-bin/a.out?test=true>\n" );
printf( "<input type=text name=formtest>\n" );
printf( "<input type=submit>\n" );
printf( "</form>" );
return( 0 );
}
This was as much to test that the webserver is going to process the CGI as it was to test the program would run. So then I decided to send form data to the program and see where it turns up. It could be part of the environment variables or perhaps part of the environment variables setup before the server execs.
int main( int argc, char *argv[], char *env[] )
{
int i;
FILE *fp;
printf( "Content-type: text/html\n\n" );
printf( "<form method=post action=/cgi-bin/a.out?test=true>\n" );
printf( "<input type=text name=formtest>\n" );
printf( "<input type=submit>\n" );
printf( "</form>" );
for( i=0 ; env[i] != NULL ; i++ )
{
fprintf( stdout, "ENV %s<br />\n", env[i] );
fflush( stdout );
sleep( 1 );
}
for( i=0 ; i<argc ; i++ )
{
fprintf( stdout, "ARGV %s<br />\n", argv[i] );
fflush( stdout );
sleep( 1 );
}
}
Well, there's no evidence of the form posted values here... We do have the request URI environment though, this will be useful for GET posts. Well, after some digging it was aparent that the values are sent to the CGI by a pipe's STDIN
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[], char *env[] )
{
int i;
FILE *fp;
char *s=malloc( 1000 );
printf( "Content-type: text/html\n\n" );
printf( "<form method=post action=/cgi-bin/a.out?test=true>\n" );
printf( "<input type=text name=formtest>\n" );
printf( "<input type=submit>\n" );
printf( "</form>" );
for( i=0 ; env[i] != NULL ; i++ )
{
fprintf( stdout, "ENV %s<br />\n", env[i] );
fflush( stdout );
sleep( 1 );
}
for( i=0 ; i<argc ; i++ )
{
fprintf( stdout, "ARGV %s<br />\n", argv[i] );
fflush( stdout );
sleep( 1 );
}
while( s=fgets( s, 1000, stdin ) )
{
fprintf( stdout, "%s\n", s );
fflush( stdout );
sleep( 1 );
}
free( s );
}
So there's the full program, we have a means of getting GET and POST data with this, so you may go forth an multiply with this. One or two benefits of writing web apps in C are that it's blindingly fast and you have access to things which may not be platform portable and therefore not available for perl/php/jsp etc.
2006-03-11 perl time warp
Yeah this is the worst article heading, ever. But I struggled for some time to get conversion of dates to work in perl. There are various libraries from CPAN which can do this, but with the risk of adding too many dependencies to a single small script I decided to try this for myself. The problem with perl doing this is that there is just no function to return the system time zone. The solution it seems is to make a POSIX call to strftime. The result can be used to adjust the result of time() calls, when reading and writing out time values.
sub getiso8601
{
my $self = shift;
my $timestamp = shift;
my $zone = POSIX::strftime( "%z", localtime( $timestamp ) );
# print( "Timestamp: $timestamp\n" );
if( $zone =~ /^([\x2B-]{1})([0-9]{2})([0-9]{2})$/ )
{
$timestamp = $timestamp + ( ( $2 * 60 * 60 ) + ( $3 * 60 ) ) if( $1 eq "+" );
$timestamp = $timestamp - ( ( $2 * 60 * 60 ) + ( $3 * 60 ) ) if( $1 eq "-" );
}
# print( "Timestamp: $timestamp\n" );
my $retVal = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime( $timestamp ) );
$zone = substr( $zone, 0, 3 ) . ":" . substr( $zone, 3 );
return( $retVal . $zone );
}
This is all well and good to output a local time, but we must also be able to parse this back into a GMT unix epoch time.
sub getepochfromiso8601
{
my $self = shift;
my $date = shift;
my $epoch = 0;
if( $date =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})([\x2B-]){1}([0-9]{2}):([0-9]{2})$/ )
{
# print( "Year $1 Month $2 Day $3 Hour $4 Minute $5 Seconds $6 neg/pos $7 Offset $8 $9\n" );
$epoch = Time::Local::timelocal( $6, $5, $4, $3, $2-1, $1 );
$epoch = $epoch - ( ( $8 * 60 * 60 ) + ( $9 * 60 ) ) if( $7 eq "+" );
$epoch = $epoch + ( ( $8 * 60 * 60 ) + ( $9 * 60 ) ) if( $7 eq "-" );
}
return( $epoch );
}
2006-03-07 scan results
Well, the scan results were quite good, I acquired s5h.net ;) In capital letters it looks almost like SSH.net, which is great, because I use ssh all day. I'm beginning to think that I own too many, and perhaps my little dydns project has not yet attacted enough attention, thinking about it, most people have a fixed broadband IP address these days so there is less requirement for this, when I was using modem connections I loved the ability to use my own email server. I guess we're not all the same.
NTL inform they're to take away the 0800 052 2000 free-phone number for complaints, the sameday, they take away the route for most of the major sites. I know from first hand experience how difficult it is to carry out technical work in an ISP, but with correct thoughts, backups and restoration, it can be calm work. It's when some clueless member of staff is doing stuff that theres problems. SO fucking pissed off with this ISP. it's effected all UK members from colaboration with others who are at a distance.
This is a joke, we pay for 24/7 connectivity, and I rely on my evenings to get stuff done, most of which revolves around programming on the internet in one way or another, if someone's going to freak aroudn with the routing tables, why can't they do it during the early hours, not when people are going to notice things.
> 07:38 < timecop> http://www.microsoft.com//windowsxp/mysterysolved/corp/default.mspx > Click on "Valuable Information" on the right column. Answers > are 2 and true for the rest.
2006-03-05 scan the internet
Considering the number of possible three letter domains there are, I have decided to start looking for one. I don't care what it's called, but I just want it for email and stuff. There are the possible combinations a-z and 0-9 (36)^3, 46656 possible names.
How does one go about doing this you might ask. Well, we make use of the whois service from verisign.
'whois' is a lookup tool, usually packaged with most (real) operating systems, but if it's not, do not worry you can make use of this all the same with telnet:
telnet whois.crsnic.net 43 Trying 198.41.3.54... Connected to whois.crsnic.net. Escape character is '^]'. domain =microsoft.com Whois Server Version 1.3 Domain names in the .com and .net domains can now be registered with many different competing registrars. Go to http://www.internic.net for detailed information. Domain Name: MICROSOFT.COM Registrar: TUCOWS INC. Whois Server: whois.opensrs.net Referral URL: http://domainhelp.tucows.com Name Server: NS3.MSFT.NET Name Server: NS1.MSFT.NET Name Server: NS5.MSFT.NET ... Connection closed by foreign host.
From experience all the various different lookup providers change the protocol slightly, or don't ever implement it correctly.
What you should notice from the above in particular is the query which is passed to the lookup service, it begins with 'domain' (unlike nominet's), and the domain itself is prefixed with '='. This tells the service to return only direct matches of the domain itself. Reasons for this are because the lookup service also returns nameservers which match by default, although it is possible to lookup just a nameserver by using 'nameserver' rather than 'domain'.
Part of the service advises against harvesting, and I have noticed on a busy day that the servie might lock up and leave the connection open. So if you're using perl, one trick you might use is like so:
sub mysub
{
alarm( 10 );
$SIG{ALRM} = sub { return( -1 ); };
... lookup code here
alarm( 0 );
return( 1 );
}
This informs perl to have a signal sent in 10 seconds time, which makes a sub, to return to caller. So if you are getting 'greylisted' by the lookup tool why not exit after a nominal period, and try the lookup later?
When the above runs you might notice that the sub 'mysub' always returns 1, even if the signal was called. The reason for this is that the signal is just like a signal in any other language, even though it's been defined within a function $SIG is still a global. So, we have to attack this problem like it was a low level languge and look at those calls which could take some time, then put a 'ERRNO' style if right after the call.
#!/usr/bin/perl
use strict;
use warnings;
my $val = 0;
$SIG{ALRM} = sub { $val = 2 ; return( 1 ) };
sub mysub
{
alarm( 1 );
sleep( 10 );
print( $val . "\n" );
alarm( 0 );
return( 1 );
}
print( mysub() . "\n" );
If you run the above you will notice that the print is called after a couple of seconds after the sleep( 10 ) starts. The alarm kills the atomic function.
When Larry Wall talks about avoiding languages with 'bondage and disciplin' I'm not quite sure what he means, take the following 'switch-case' for example
sub isodate
{
my $date = shift;
my @parts = split( /-/, $date );
for( lc( $parts[1] ) )
{
/jan/ && do { $parts[1] = "01" ; last ; };
/feb/ && do { $parts[1] = "02" ; last ; };
/mar/ && do { $parts[1] = "03" ; last ; };
/apr/ && do { $parts[1] = "04" ; last ; };
/may/ && do { $parts[1] = "05" ; last ; };
/jun/ && do { $parts[1] = "06" ; last ; };
/jul/ && do { $parts[1] = "07" ; last ; };
/aug/ && do { $parts[1] = "08" ; last ; };
/sep/ && do { $parts[1] = "09" ; last ; };
/oct/ && do { $parts[1] = "10" ; last ; };
/nov/ && do { $parts[1] = "11" ; last ; };
/dec/ && do { $parts[1] = "12" ; last ; };
$parts[1] = "01";
}
return( "$parts[2]-$parts[1]-$parts[0]" );
}
Info