X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=dev%2Fetherpkt.hh;h=abdf301663216d69de3be99865e7df2aa4a713f8;hb=c9e6a15196a87fd1aa923b9ee0f6ff736ad6d33b;hp=76b4a9156978423d37b2223e987814db32c7d0e6;hpb=ca0dcd048c02ac1857d487e4f027bf8bf18e4266;p=gem5.git diff --git a/dev/etherpkt.hh b/dev/etherpkt.hh index 76b4a9156..abdf30166 100644 --- a/dev/etherpkt.hh +++ b/dev/etherpkt.hh @@ -64,11 +64,17 @@ class EtherPacket : public RefCounted bool isIpPkt() { eth_header *eth = (eth_header *) data; - return (eth->type == 0x800); + return (eth->type == 0x8); + } + bool isTcpPkt(ip_header *ip) { + return (ip->protocol == 0x6); } bool isTcpPkt() { ip_header *ip = getIpHdr(); - return (ip->protocol == 6); + return (ip->protocol == 0x6); + } + bool isUdpPkt(ip_header *ip) { + return (ip->protocol == 17); } bool isUdpPkt() { ip_header *ip = getIpHdr(); @@ -81,11 +87,13 @@ class EtherPacket : public RefCounted } tcp_header *getTcpHdr(ip_header *ip) { - return (tcp_header *) (ip + (ip->vers_len & 0xf)); + assert(isTcpPkt(ip)); + return (tcp_header *) ((uint8_t *) ip + (ip->vers_len & 0xf)*4); } udp_header *getUdpHdr(ip_header *ip) { - return (udp_header *) (ip + (ip->vers_len & 0xf)); + assert(isUdpPkt(ip)); + return (udp_header *) ((uint8_t *) ip + (ip->vers_len & 0xf)*4); } typedef RefCountingPtr PacketPtr;