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 ...

Get The Database Hacker's Handbook: Defending Database Servers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.