Greetings,
This is my main question:
Quote:
|
In raw socket sniffing: how do I copy data from a structure into a char[] or pointer?
|
My problem:
I started doing some raw socket programming in OpenWRT (I'm a newbie) for research. It's been a long time since the last time I programmed in C, so here's my newbie question/problem.
I'm receiving packets and using an .h file with the structures to get the information of each 802.11 packet in monitor mode (attached to this post).
My (simple) goal is to get the Tx MAC Address. No luck.
This is my "read the prism header" function:
Code:
ParsePrismHeader(unsigned char *packet,int len)
{
wlan_header *wlan;ieee_802_11_header *i802;u_int16_t eth_type;
unsigned char *mac;unsigned char *mac2;
wlan = (wlan_header *)packet;
i802 = (ieee_802_11_header *)(packet + wlan->msglen);
//copy the DESTINATION mac address to a pointer
getMACaddr((i802)->mac1,mac);
//is this packet for me? -- Is the DES MAC my mac?
if(strcmp(localMAC,mac)==0)
{
//let's print my own mac address (DEST mac)
printf(" %s ",mac);
//now copy the Transmitting mac
getMACaddr((i802)->mac2,mac2);
}
}
this is the getMACaddr function:
Code:
getMACaddr(unsigned char *p,unsigned char *macx){
int s=0;
char tmp[50]="";
for( s = 0; s < 6; s++ )
{
sprintf(tmp,"%.2X", *p);
strcat(macx,tmp);
p++;
}
size_t begin=1;
size_t end=12;
sprintf(macx,"%s",substring(macx,begin,end));
}
mac, which is the Destination MAC (my mac), does the job and prints it without problem
BUT when I use getMACaddress the second time, it prompts the 'C' character, like this:
Code:
687F7427B81C 4FD370694
687F7427B81C 4FD3706940
687F7427B81C 4FD37069404
687F7427B81C 4FD370694040
687F7427B81C FD3706940404
687F7427B81C D37069404040
687F7427B81C 370694040404
687F7427B81C 706940404040
687F7427B81C 069404040404
687F7427B81C 694040404040
687F7427B81C 940404040400
the first one is my MAC (it's ok), the second it's NOT :/
now again, HOW do I copy data from a structure TO a char[] or a pointer? why is it copying one and not the other one?
thank you for your indulgence.