Thread: How to Send Mac Address From Client to Server

  1. #1
    Registered User
    Join Date
    May 2009
    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:

    Code:
    {
    
    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 :


    Code:
    {
    
    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.......



    Lieyza

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    %d is for integers, not floats. Why are you using floats, anyway. Just send an array of bytes.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2
    Oh.. ya! but i have try to change it to float.. and it still give the same output.. erm.. but how about using bytes? how is it? can u teach me?
    Last edited by Lieyza197; 05-27-2009 at 10:04 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. multiple forks in one client connection (ftpclient)
    By Dynamo in forum Networking/Device Communication
    Replies: 5
    Last Post: 01-16-2011, 12:41 PM
  2. What does this do (Windows API)?
    By EVOEx in forum Windows Programming
    Replies: 4
    Last Post: 12-19-2008, 10:48 AM
  3. Spoof MAC Address.
    By eXeCuTeR in forum C Programming
    Replies: 10
    Last Post: 02-07-2008, 05:35 PM
  4. Client timed-out once on connect(), can never connect() again
    By registering in forum Networking/Device Communication
    Replies: 6
    Last Post: 10-28-2003, 03:46 PM
  5. MSN Vital Information
    By iain in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 09-22-2001, 08:55 PM

Tags for this Thread