3 static u16
uip_csum(u16 csum
, u8
*addr
, u16 count
)
14 sum
+= *(unsigned char *)addr
;
17 sum
= (sum
& 0xffff) + (sum
>> 16);
22 u16
uip_csum_ip(struct uip_ip
*ip
)
24 return uip_csum(0, &ip
->vhl
, uip_ip_hdrlen(ip
));
27 u16
uip_csum_icmp(struct uip_icmp
*icmp
)
32 return icmp
->csum
= uip_csum(0, &icmp
->type
, htons(ip
->len
) - uip_ip_hdrlen(ip
) - 8); /* icmp header len = 8 */
35 u16
uip_csum_udp(struct uip_udp
*udp
)
37 struct uip_pseudo_hdr hdr
;
47 hdr
.proto
= ip
->proto
;
50 udp_len
= uip_udp_len(udp
);
53 pad
= (u8
*)&udp
->sport
+ udp_len
;
55 memcpy((u8
*)&udp
->sport
+ udp_len
+ 1, &hdr
, sizeof(hdr
));
56 return uip_csum(0, (u8
*)&udp
->sport
, udp_len
+ 1 + sizeof(hdr
));
58 memcpy((u8
*)&udp
->sport
+ udp_len
, &hdr
, sizeof(hdr
));
59 return uip_csum(0, (u8
*)&udp
->sport
, udp_len
+ sizeof(hdr
));
64 u16
uip_csum_tcp(struct uip_tcp
*tcp
)
66 struct uip_pseudo_hdr hdr
;
72 tcp_len
= ntohs(ip
->len
) - uip_ip_hdrlen(ip
);
77 hdr
.proto
= ip
->proto
;
78 hdr
.len
= htons(tcp_len
);
80 if (tcp_len
> UIP_MAX_TCP_PAYLOAD
+ 20)
81 pr_warning("tcp_len(%d) is too large", tcp_len
);
84 pad
= (u8
*)&tcp
->sport
+ tcp_len
;
86 memcpy((u8
*)&tcp
->sport
+ tcp_len
+ 1, &hdr
, sizeof(hdr
));
87 return uip_csum(0, (u8
*)&tcp
->sport
, tcp_len
+ 1 + sizeof(hdr
));
89 memcpy((u8
*)&tcp
->sport
+ tcp_len
, &hdr
, sizeof(hdr
));
90 return uip_csum(0, (u8
*)&tcp
->sport
, tcp_len
+ sizeof(hdr
));