I am using VC++ .Net 2003 and have a question about putting a byte
array returned from a socket receivefrom method in to a struct.
Here is what I have:
Socket* s = 0;
Byte RecvBytes[] = new Byte[1500];
try {
IPEndPoint* endPoint = new IPEndPoint(IPAd dress::Any, 1646);
s = new Socket(endPoint->Address->AddressFamil y,
SocketType::Dgr am, ProtocolType::U dp);
s->Bind(endPoint) ;
Console::WriteL ine (S"Waiting to receive datagrams from client...");
IPEndPoint* sender = new IPEndPoint(IPAd dress::Any, 0);
EndPoint* senderRemote = __try_cast<EndP oint*>(sender);
Int32 LengthBytes = s->ReceiveFrom(Re cvBytes, 0,
RecvBytes->Length, SocketFlags::No ne, &senderRemot e);
Console::WriteL ine(S"Datagram Received from -> {0} {1} Bytes",
senderRemote->ToString(), Convert::ToStri ng(LengthBytes) );
I get a the RecvBytes byte array back and I want to put it in a
structure.
__gc struct auth_hdr {
Byte code;
Byte id;
UInt16 length;
Byte vector[];
Byte data[];
};
What is the best way to do it? I have tried to cast it like auth_hdr*
authhdr = reinterpret_cas t<auth_hdr*>(Re cvBytes) but it does
not work. Would it be better to try something like:
[StructLayout(La youtKind::Expli cit)]
public __gc class Packet
{
public:
[FieldOffset(0)] Byte Code;
[FieldOffset(1)] Byte ID;
[FieldOffset(2)] UInt16 Length;
[FieldOffset(20)] Byte Vector;
[FieldOffset(38)] Byte Data;
};
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---