struct TLV_IPv4_Internal_type *eigrp_read_ipv4_tlv(struct stream *s)
{
struct TLV_IPv4_Internal_type *tlv;
+ uint32_t destination_tmp;
tlv = eigrp_IPv4_InternalTLV_new();
tlv->prefix_length = stream_getc(s);
- if (tlv->prefix_length <= 8) {
- tlv->destination_part[0] = stream_getc(s);
- tlv->destination.s_addr = (tlv->destination_part[0]);
- } else if (tlv->prefix_length > 8 && tlv->prefix_length <= 16) {
- tlv->destination_part[0] = stream_getc(s);
- tlv->destination_part[1] = stream_getc(s);
- tlv->destination.s_addr = ((tlv->destination_part[1] << 8)
- + tlv->destination_part[0]);
- } else if (tlv->prefix_length > 16 && tlv->prefix_length <= 24) {
- tlv->destination_part[0] = stream_getc(s);
- tlv->destination_part[1] = stream_getc(s);
- tlv->destination_part[2] = stream_getc(s);
- tlv->destination.s_addr = ((tlv->destination_part[2] << 16)
- + (tlv->destination_part[1] << 8)
- + tlv->destination_part[0]);
- } else if (tlv->prefix_length > 24 && tlv->prefix_length <= 32) {
- tlv->destination_part[0] = stream_getc(s);
- tlv->destination_part[1] = stream_getc(s);
- tlv->destination_part[2] = stream_getc(s);
- tlv->destination_part[3] = stream_getc(s);
- tlv->destination.s_addr = ((tlv->destination_part[3] << 24)
- + (tlv->destination_part[2] << 16)
- + (tlv->destination_part[1] << 8)
- + tlv->destination_part[0]);
- }
+ destination_tmp = stream_getc(s) << 24;
+ if (tlv->prefix_length > 8)
+ destination_tmp |= stream_getc(s) << 16;
+ if (tlv->prefix_length > 16)
+ destination_tmp |= stream_getc(s) << 8;
+ if (tlv->prefix_length > 24)
+ destination_tmp |= stream_getc(s);
+
+ tlv->destination.s_addr = htonl(destination_tmp);
+
return tlv;
}
stream_putc(s, pe->destination->prefixlen);
- stream_putc(s, pe->destination->u.prefix4.s_addr & 0xFF);
+ stream_putc(s, (ntohl(pe->destination->u.prefix4.s_addr) >> 24) & 0xFF);
if (pe->destination->prefixlen > 8)
- stream_putc(s, (pe->destination->u.prefix4.s_addr >> 8) & 0xFF);
+ stream_putc(s, (ntohl(pe->destination->u.prefix4.s_addr) >> 16) & 0xFF);
if (pe->destination->prefixlen > 16)
- stream_putc(s,
- (pe->destination->u.prefix4.s_addr >> 16) & 0xFF);
+ stream_putc(s, (ntohl(pe->destination->u.prefix4.s_addr) >> 8) & 0xFF);
if (pe->destination->prefixlen > 24)
- stream_putc(s,
- (pe->destination->u.prefix4.s_addr >> 24) & 0xFF);
+ stream_putc(s, ntohl(pe->destination->u.prefix4.s_addr) & 0xFF);
return length;
}