I am trying to return unsigned characters from one function to another, but am unable to, since I am new to C and it's data structures are still a mystery to me. Here is the function that is calling the function....
void print_ethernet_data(const u_char * Buffer, int Size)
{
unsigned char destination, src;
unsigned short qtype;
get_ethernet_header(Buffer , Size, &destination, &src, &qtype); //The function that is supposed to return the values
printf("|-Dest : %u \n", destination);
printf("|-Protocol : %u \n",qtype);
}
This is the description of the function get_internet_header:
void get_ethernet_header(const u_char *Buffer, int Size, unsigned char* destination, unsigned char* src, unsigned short* qtype)
{
struct ether_header *eth = (struct ether_header *)Buffer;
printf( "\n");
printf( "Ethernet Header\n");
printf( " |-Destination Address : %.2X:%.2X:%.2X:%.2X:%.2X:%.2X \n", eth->dhost[0] , eth->dhost[1] , eth->dhost[2] , eth->dhost[3] , eth->dhost[4] , eth->dhost[5] );
printf( " |-Source Address : %.2X:%.2X:%.2X:%.2X:%.2X:%.2X \n", eth->shost[0] , eth->shost[1] , eth->shost[2] , eth->shost[3] , eth->shost[4] , eth->shost[5] );
printf( " |-Protocol : %u \n",(unsigned short)eth->type);
*destination = eth->dhost;
*src = eth->shost;
*qtype = (unsigned short)eth->type;
}
But for some reason unknown to me, I am unable to do the same as this is what it prints for me.
Ethernet Header
|-Destination Address : 58:49:3B:38:B5:11
|-Source Address : E4:FC:82:FD:32:C1
|-Protocol : 8
|-Dest : 134 //I suppose that this is the address the pointer points to
|-Protocol : 8 //This matches the Protocol printed above
Is it because I'm returning it the wrong way or because the formatting where I am printing the data is wrong? Note that the Protocol is printed the right way, just what I wanted. But the destination mac does not.
I read various answers on StackOverflow but couldn't make it work. I'd be greatful if somebody could help me out with the problem. Thanks in advance.
P.S: I dont think the description of struct ether_header is required, but if it is, then I can edit it later.
EDIT-1:
struct ether_header {
unsigned char dhost[ETHER_ADDR_LEN]; // Destination host address
unsigned char shost[ETHER_ADDR_LEN]; // Source host address
unsigned short type; // IP? ARP? RARP? etc
};