eleanor
30th October 2007, 13:11
Hi, I've build ICMP echo request packet:
#include <string.h>
class CIcmp {
public:
CIcmp(char type[8], char code[8], char checksum[8], char identifier[8], char sequenceNumber[8], char *additionalData=0);
~CIcmp();
char* icmpBuildPacket(char *packet);
};
#include "icmp.h"
CIcmp::CIcmp(char type[8], char code[8], char checksum[8], char identifier[8], char sequenceNumber[8], char *additionalData) {
char packet[strlen(type) + strlen(code) + strlen(checksum) + strlen(identifier) + strlen(sequenceNumber) + strlen(additionalData)];
//packet[0] = *type;
strcpy(packet, type);
strcpy(packet, code);
strcpy(packet, checksum);
strcpy(packet, identifier);
strcpy(packet, sequenceNumber);
strcpy(packet, additionalData);
icmpBuildPacket(packet);
}
CIcmp::~CIcmp() {
}
char* CIcmp::icmpBuildPacket(char *packet) {
return packet;
}
Now I want to know, if I did that correctly? (I know I have to calculate the checksum, but let's say the additionalData is always 0 for now)
Well, now I need a way to send this packet over the network to destination --> what would be the best way to do that?
#include <string.h>
class CIcmp {
public:
CIcmp(char type[8], char code[8], char checksum[8], char identifier[8], char sequenceNumber[8], char *additionalData=0);
~CIcmp();
char* icmpBuildPacket(char *packet);
};
#include "icmp.h"
CIcmp::CIcmp(char type[8], char code[8], char checksum[8], char identifier[8], char sequenceNumber[8], char *additionalData) {
char packet[strlen(type) + strlen(code) + strlen(checksum) + strlen(identifier) + strlen(sequenceNumber) + strlen(additionalData)];
//packet[0] = *type;
strcpy(packet, type);
strcpy(packet, code);
strcpy(packet, checksum);
strcpy(packet, identifier);
strcpy(packet, sequenceNumber);
strcpy(packet, additionalData);
icmpBuildPacket(packet);
}
CIcmp::~CIcmp() {
}
char* CIcmp::icmpBuildPacket(char *packet) {
return packet;
}
Now I want to know, if I did that correctly? (I know I have to calculate the checksum, but let's say the additionalData is always 0 for now)
Well, now I need a way to send this packet over the network to destination --> what would be the best way to do that?