O'Reilly logo

The Database Hacker's Handbook: Defending Database Servers by Bill Grindlay, John Heasman, Chris Anley, David Litchfield

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sybase Version Tool

The following is the source code to the Sybase version-grabbing tool mentioned earlier in this chapter. It is written for the Windows platform.

// sybaseversion.cpp
// Chris Anley [chris@ngssoftware.com]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock.h>
#include <time.h>
int syntax()
{
   printf("syntax: sybaseversion <host> <port>\n");
   return 1;
}
int err( char *psz )
{
     printf("%s\n", psz );
     return 0;
}
int init_sockets()
{
   int ret=0;
   WORD wVersionRequested;
   WSADATA wsaData;
   // Initialise Winsock in this thread
   wVersionRequested = MAKEWORD( 2, 0 );
   ret = WSAStartup( wVersionRequested, &wsaData );
   if ( ret != 0 )
return err( "Couldn't start sockets" ); if ( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 0 ) return err( "Wrong version of sockets" ); return 1; } int create_tcp_socket() { return (int)socket( AF_INET, SOCK_STREAM, 0 ); } int set_timeout( int socket, int timeout_milliseconds ) { if ( setsockopt( socket, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout_milliseconds, sizeof( int ) ) != 0 ) return 0; if ( setsockopt( socket, SOL_SOCKET, SO_SNDTIMEO, (const char *)&timeout_milliseconds, sizeof( int ) ) != 0 ) return 0; return 1; } int bind_to_port( int socket, int port ) { struct sockaddr_in sa; int ret; sa.sin_port = htons( (short)port ); sa.sin_family=AF_INET; sa.sin_addr.s_addr = INADDR_ANY; ret = bind( socket, (struct sockaddr *)&sa, sizeof( struct sockaddr ) ); if ( ret != 0 ) return err("Couldn't bind ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required