I am working on Client Server application where I need to send 6 byte mac id (FFF000 - FFF1FF) to the server from the client. I wanted to know the how best to represent in c++.
I thought of declaring it as unsigned long and then covert it in 6 bytes and send it to the server.
Is this correct do this. Any Other alter开发者_如何学Gonative please suggest.
I don't think I'd use an integral type for this, since we would never treat the value as a number. I would represent it as a sequence of 6 bytes. Some possibilities are:
unsigned char macid[6];
typedef unsigned char macid[6];
struct macid {
unsigned char data[6];
};
But in the end, I'd probably opt for:
std::tr1::array<unsigned char, 6> macid;
send(serverFd, &macid[0], macid.size());
精彩评论