Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/netinet/libalias/util.c
Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | ip_packet(u_char protocol, size_t len) | ||||
p->ip_ttl = IPDEFTTL; | p->ip_ttl = IPDEFTTL; | ||||
p->ip_p = protocol; | p->ip_p = protocol; | ||||
REQUIRE(p->ip_hl == 5); | REQUIRE(p->ip_hl == 5); | ||||
return (p); | return (p); | ||||
} | } | ||||
struct udphdr * | struct udphdr * | ||||
set_udp(struct ip *p, u_short sport, u_short dport) { | set_udp(struct ip *p, u_short sport, u_short dport) { | ||||
uint32_t *up = (void *)p; | int hlen = p->ip_hl << 2; | ||||
afedorov: Just a side note. Most of the networking code uses: (p-> ip_hl << 2)
Perhaps we need an… | |||||
Not Done Inline ActionsI'd prefer uint8_t. char is not well defined. donner: I'd prefer uint8_t.
char is not well defined.
It might be 32bit long (seen that). | |||||
Done Inline ActionsFreeBSD doesn't work on architectures where char is not a byte. See all the uses of 'caddr_t'. This is the code in udp_input to calculate the pointer: ip = mtod(m, struct ip *); uh = (struct udphdr *)((caddr_t)ip + iphlen); In fact, it'd probably be cleaner to write this instead as struct udphdr *u = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2)); to more closely match udp_input. A hlen helper variable for ip->ip_hl << 2 wouldn't be bad either. jhb: FreeBSD doesn't work on architectures where char is not a byte. See all the uses of 'caddr_t'. | |||||
struct udphdr *u = (void *)&(up[p->ip_hl]); | struct udphdr *u = (struct udphdr *)((uintptr_t)p + hlen); | ||||
int payload = ntohs(p->ip_len) - 4*p->ip_hl; | int payload = ntohs(p->ip_len) - hlen; | ||||
REQUIRE(payload >= (int)sizeof(*u)); | REQUIRE(payload >= (int)sizeof(*u)); | ||||
p->ip_p = IPPROTO_UDP; | p->ip_p = IPPROTO_UDP; | ||||
u->uh_sport = htons(sport); | u->uh_sport = htons(sport); | ||||
u->uh_dport = htons(dport); | u->uh_dport = htons(dport); | ||||
u->uh_ulen = htons(payload); | u->uh_ulen = htons(payload); | ||||
return (u); | return (u); | ||||
} | } |
Just a side note. Most of the networking code uses: (p-> ip_hl << 2)
Perhaps we need an appropriate macro for this.