共2条
1/1 1 跳转至页
,VXWORKS,NUCLEUS,keil,for,arm,01a,ccd,13581980230, 请问各位大虾,很简单的一个问题,我想不明白,在51中可以?
问
请问,就是下面的问题
typedef struct
{
unsigned short h_type;
unsigned short p_type;
unsigned char h_len;
unsigned char i_len;
unsigned short m_type;
unsigned char sr[6];
unsigned int sddr;
unsigned char dr[6];
unsigned int dddr;
} ARP_HEADER;
uchar RXT[] = {
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x03,0x0F,
0xF9,0xAE,0xF9,0x08,0x06,0x00,0x01,0x08,0x00,
0x06,0x04,0x00,0x01,0x00,0x03,0x0F,0xF9,0xAE,
0xF9,0xC0,0xA8,0x01,0xFA,0x00,0x00,0x00,0x00,
0x00,0x01,0xC0,0xA8,0x01,0xFA,0x66
};
uint volatile w;
ARP_HEADER * ar;
arp = (ARP_HEADER *)(RXT + 14);
w = ar->daddr; //这个总是不对
w = ar->sddr; //这个正确
这样的结构我读dddr的数据总是不对,为什么? 答 1: ALIGN 引起的.#pragma pack(push,1)
typedef struct
{
unsigned short h_type;
unsigned short p_type;
unsigned char h_len;
unsigned char i_len;
unsigned short m_type;
unsigned char sr[6];
unsigned int sddr;
unsigned char dr[6];
unsigned int dddr;
} ARP_HEADER;
#pragma pack(pop)
typedef struct
{
unsigned short h_type;
unsigned short p_type;
unsigned char h_len;
unsigned char i_len;
unsigned short m_type;
unsigned char sr[6];
unsigned int sddr;
unsigned char dr[6];
unsigned int dddr;
} ARP_HEADER;
uchar RXT[] = {
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x03,0x0F,
0xF9,0xAE,0xF9,0x08,0x06,0x00,0x01,0x08,0x00,
0x06,0x04,0x00,0x01,0x00,0x03,0x0F,0xF9,0xAE,
0xF9,0xC0,0xA8,0x01,0xFA,0x00,0x00,0x00,0x00,
0x00,0x01,0xC0,0xA8,0x01,0xFA,0x66
};
uint volatile w;
ARP_HEADER * ar;
arp = (ARP_HEADER *)(RXT + 14);
w = ar->daddr; //这个总是不对
w = ar->sddr; //这个正确
这样的结构我读dddr的数据总是不对,为什么? 答 1: ALIGN 引起的.#pragma pack(push,1)
typedef struct
{
unsigned short h_type;
unsigned short p_type;
unsigned char h_len;
unsigned char i_len;
unsigned short m_type;
unsigned char sr[6];
unsigned int sddr;
unsigned char dr[6];
unsigned int dddr;
} ARP_HEADER;
#pragma pack(pop)
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |