April 11, 2021, 02:36:32 PM

Author Topic: buffer.cpp  (Read 530 times)

sit0

  • DarkBlizz
  • Resident
  • *****
  • Posts: 26
    • View Profile
buffer.cpp
« on: January 09, 2011, 12:30:39 PM »
Code: [Select]
#include "bot.h"

void Bot::ABYTE(unsigned char data)
{
*(buff + buflen) = data;
buflen++;
}

void Bot::AWORD(unsigned short data)
{
*(unsigned short *)(buff + buflen) = data;
buflen += 2;
}

void Bot::ADWORD(unsigned long data)
{
*(unsigned long *)(buff + buflen) = data;
buflen += 4;
}

void Bot::ASTRING(char* data)
{
strcpy(buff + buflen, data);
buflen += strlen(data);
}

void Bot::ASTRING0(char* data)
{
ASTRING(data);
ABYTE(0);
}

void Bot::AVOID(void* data, unsigned int len)
{
memcpy(buff + buflen, data, (size_t)len);
buflen += len;
}

void Bot::APACKET(unsigned char PID)
{
buff[1] = PID;
*(unsigned short *)(buff + 2) = buflen;
send(sock, buff, buflen, 0);

if((PSB == SB) && (Dump==true))
hexdump(buff,buflen);

buflen = 4;
}

void Bot::APACKET0(char *Data, ...)
{
char buf[256];
va_list argptr;

va_start(argptr, Data);
vsprintf(buf, Data, argptr);
va_end(argptr);

if (send(sock, buf, strlen(buf), 0) < 0)
exit(1);
}