#ifdef __STRICT_ANSI__
#define _BSD_SOURCE
#endif
#include <rfb/rfbconfig.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#if LIBVNCSERVER_HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include <rfb/default8x16.h>
#define width 100
#define height 100
static char* keys[0x400];
static int hex2number(unsigned char c)
{
if(c>'f') return(-1);
else if(c>'F')
return(10+c-'a');
else if(c>'9')
return(10+c-'A');
else
return(c-'0');
}
static void read_keys(void)
{
int i,j,k;
char buffer[1024];
FILE* keysyms=fopen("keysym.h","r");
memset(keys,0,0x400*sizeof(char*));
if(!keysyms)
return;
while(!feof(keysyms)) {
fgets(buffer,1024,keysyms);
if(!strncmp(buffer,"#define XK_",strlen("#define XK_"))) {
for(i=strlen("#define XK_");buffer[i] && buffer[i]!=' '
&& buffer[i]!='\t';i++);
if(buffer[i]==0)
continue;
buffer[i]=0;
for(i++;buffer[i] && buffer[i]!='0';i++);
if(buffer[i]==0 || buffer[i+1]!='x') continue;
for(j=0,i+=2;(k=hex2number(buffer[i]))>=0;i++)
j=j*16+k;
if(keys[j&0x3ff]) {
char*
x=(
char*)malloc(1+strlen(keys[j&0x3ff])+1+strlen(buffer+strlen(
"#define ")));
memset(keys,0,0x400*sizeof(char*));
fclose(keysyms);
return;
}
strcat(
x,buffer+strlen(
"#define "));
free(keys[j&0x3ff]);
} else
keys[j&0x3ff] = strdup(buffer+strlen("#define "));
}
}
fclose(keysyms);
}
static int lineHeight=16,lineY=
height-16;
static void output(rfbScreenInfoPtr s,char* line)
{
}
{
char buffer[1024+32];
sprintf(buffer,"%s: %s (0x%x)",
down?"down":"up",keys[k&0x3ff]?keys[k&0x3ff]:"",(unsigned int)k);
output(cl->screen,buffer);
}
static void doptr(
int buttonMask,
int x,
int y,rfbClientPtr cl)
{
char buffer[1024];
if(buttonMask) {
sprintf(buffer,
"Ptr: mouse button mask 0x%x at %d,%d",buttonMask,
x,
y);
output(cl->screen,buffer);
}
}
{
char buffer[1024];
struct sockaddr_in addr;
socklen_t len=sizeof(addr);
unsigned int ip;
getpeername(cl->sock,(struct sockaddr*)&addr,&len);
ip=ntohl(addr.sin_addr.s_addr);
sprintf(buffer,"Client connected from ip %d.%d.%d.%d",
(ip>>24)&0xff,(ip>>16)&0xff,(ip>>8)&0xff,ip&0xff);
output(cl->screen,buffer);
}
int main(
int argc,
char** argv)
{
if(!s)
return 1;
s->colourMap.count=2;
s->colourMap.data.bytes=(unsigned char*)"\xd0\xd0\xd0\x30\x01\xe0";
s->serverFormat.trueColour=
FALSE;
s->frameBuffer=f;
s->kbdAddEvent=dokey;
s->ptrAddEvent=doptr;
s->newClientHook=newclient;
read_keys();
while(1) {
}
}
void rfbDoCopyRect(rfbScreenInfoPtr rfbScreen, int x1, int y1, int x2, int y2, int dx, int dy)
void rfbInitServer(rfbScreenInfoPtr rfbScreen)
rfbScreenInfoPtr rfbGetScreen(int *argc, char **argv, int width, int height, int bitsPerSample, int samplesPerPixel, int bytesPerPixel)
rfbBool rfbProcessEvents(rfbScreenInfoPtr screenInfo, long usec)
void rfbDrawString(rfbScreenInfoPtr rfbScreen, rfbFontDataPtr font, int x, int y, const char *string, rfbPixel colour)
int main(int argc, char **argv)