You are not logged in.

#1 2009-05-27 11:13:24

Lieyza197
Member
Registered: 2009-05-27
Posts: 2

How to Send Mac Address From Client to Server

Hii everyone. My name is Lieyza. I'm a master student, and i have one task to be finish. Now, I need a help on my C programming coding. I have to send the Mac Address of the Client to the Server. I already do the socket programming but there is still a problem to show up the Mac Add at the Server. Here is my coding to get the Mac Address at the Client Side:

{

int sd, i;
float a_macadd1, a_macadd2, a_macadd3, a_macadd4, a_macadd5, a_macadd6;
struct ifreq ir;

sd=socket(PF_INET, SOCK_STREAM, 0);
memset(&ir, 0, sizeof(ir));

strcpy(ir.ifr_name, "wlan0");
ioctl(sd, SIOCGIFHADDR, &ir);

printf ( "The Mac Address is = %02d : %02d : %02d : %02d : %02d : %02d : %02d \n", ir.ifr_hwaddr.sa_data[0],
                                                                                                                                ir.ifr_hwaddr.sa_data[1],
                                                                                                                                ir.ifr_hwaddr.sa_data[2],
                                                                                                                                ir.ifr_hwaddr.sa_data[3],
                                                                                                                                ir.ifr_hwaddr.sa_data[4],
                                                                                                                                ir.ifr_hwaddr.sa_data[5]);
a_macadd1=ir.ifr_hwaddr.sa_data[0];
a_macadd2=ir.ifr_hwaddr.sa_data[1];
a_macadd3=ir.ifr_hwaddr.sa_data[2];
a_macadd4=ir.ifr_hwaddr.sa_data[3];
a_macadd5=ir.ifr_hwaddr.sa_data[4];
a_macadd6=ir.ifr_hwaddr.sa_data[5];

printf ( " Want to send = %02d : %02d : %02d : %02d : %02d : %02d : %02d \n, a_macadd1, a_macadd2, a_macadd3, a_macadd4, a_macadd5, a_macadd6);


}
     

Then, when i run it at terminal (Client Side) the answer show is like this:

The Mac Address is 00 : 19 : 02 : 11 : 52 : 34
Want to send 00 : 00 : 00 1077084160 : 00 : 1073741824     
         


Then, the programming to show the Mac Add of the Client at the Server is like this :

{

float a_macadd1, a_macadd2, a_macadd3, a_macadd4, a_macadd5, a_macadd6;
......................
......................

printf (" The Mac Address of the Client is %02d : %02d : %02d : %02d : %02d : %02d : %02d \n, a_macadd1, a_macadd2, a_macadd3, a_macadd4, a_macadd5, a_macadd6);                                                                                         

}


and at the terminal, the answer show like this :

The Mac Address of the Client is 00 : -1090542844 : -2147483648 : -1090551438 : -2147483648 : -1074489359

why this happend? and when i run it again, it give a different answer like this :

The Mac Address of the Client is 00 : -1090582268 : -2147483648 : -10906518628 : -2147483648 : -1074489171

WHY? can anybody help me? how to write a coding using C programming to send the Mac address of the client to the server? i'm really need a help.. please help me.......


sad
Lieyza

Offline

#2 2009-05-27 14:10:04

dmartins
Member
Registered: 2006-09-23
Posts: 360

Re: How to Send Mac Address From Client to Server

I'm not all the familiar with C network programming, but why use a float for sa_data? It should only need a (unsigned?) char. I have no idea if that could be causing your problem.

You should be able to use %02X in your printf statements to print the MAC address in the more standard hex format.

Offline

#3 2009-05-27 14:20:12

Lieyza197
Member
Registered: 2009-05-27
Posts: 2

Re: How to Send Mac Address From Client to Server

Hai dmartins.. appreciate for your suggest. Ok. i will try it. Now, i'm still trying.. and i think, my code have alittle bit wrong. This is the correction :

{

int sd, i;
float a_macadd1, a_macadd2, a_macadd3, a_macadd4, a_macadd5, a_macadd6;
struct ifreq ir;

sd=socket(PF_INET, SOCK_STREAM, 0);
memset(&ir, 0, sizeof(ir));

strcpy(ir.ifr_name, "wlan0");
ioctl(sd, SIOCGIFHADDR, &ir);

for (i=0;i<6;i++) {
printf("%.2hhx:", ir.ifr_hwaddr.sa_data[i]); }

}

This correction give new answer of Mac Add and the Mac add is true. But, the problem is. I dont know how to send this MAC ADD to the server and how to declare it at server side?


Lieyza

Offline

Board footer

Powered by FluxBB