Fix IPv4 Addresses Network Byte Order mistake.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6442 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -14,10 +14,7 @@
|
|||||||
|
|
||||||
#include "net_stack.h"
|
#include "net_stack.h"
|
||||||
|
|
||||||
typedef struct ipv4_addr {
|
typedef uint32 ipv4_addr;
|
||||||
uint8 byte[4];
|
|
||||||
} _PACKED ipv4_addr;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct ipv4_header {
|
typedef struct ipv4_header {
|
||||||
uint8 version_header_length;
|
uint8 version_header_length;
|
||||||
@@ -46,14 +43,23 @@ static struct net_stack_module_info *g_stack = NULL;
|
|||||||
string_token ethernet_protocol_attr;
|
string_token ethernet_protocol_attr;
|
||||||
static uint32 g_next_ipv4_id = 0;
|
static uint32 g_next_ipv4_id = 0;
|
||||||
|
|
||||||
|
static void dump_ipv4_addr(ipv4_addr *addr)
|
||||||
|
{
|
||||||
|
uint8 *bytes = (uint8 *) addr;
|
||||||
|
|
||||||
|
// NOTE: addr should point to a Network Byte Order'ed (aka Big Endian) IPv4 address
|
||||||
|
|
||||||
|
dprintf("%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3]);
|
||||||
|
}
|
||||||
|
|
||||||
static void dump_ipv4_header(net_buffer *buffer)
|
static void dump_ipv4_header(net_buffer *buffer)
|
||||||
{
|
{
|
||||||
ipv4_header iph;
|
ipv4_header ip;
|
||||||
const char *pname;
|
const char *pname;
|
||||||
|
|
||||||
g_stack->read_buffer(buffer, 0, &iph, sizeof(iph));
|
g_stack->read_buffer(buffer, 0, &ip, sizeof(ip));
|
||||||
|
|
||||||
switch(iph.protocol) {
|
switch(ip.protocol) {
|
||||||
case 1: pname = "ICMP"; break;
|
case 1: pname = "ICMP"; break;
|
||||||
case 6: pname = "TCP"; break;
|
case 6: pname = "TCP"; break;
|
||||||
case 17: pname = "UDP"; break;
|
case 17: pname = "UDP"; break;
|
||||||
@@ -62,19 +68,22 @@ static void dump_ipv4_header(net_buffer *buffer)
|
|||||||
|
|
||||||
dprintf("========== Internet Protocol (IPv4) =============\n");
|
dprintf("========== Internet Protocol (IPv4) =============\n");
|
||||||
|
|
||||||
dprintf("Station: %d.%d.%d.%d ----> %d.%d.%d.%d\n",
|
dprintf("Station: ");
|
||||||
iph.src.byte[3], iph.src.byte[2], iph.src.byte[1], iph.src.byte[0],
|
dump_ipv4_addr(&ip.src);
|
||||||
iph.dst.byte[3], iph.dst.byte[2], iph.dst.byte[1], iph.dst.byte[0]);
|
dprintf(" ----> ");
|
||||||
dprintf("Protocol: %d (%s)\n", iph.protocol, pname);
|
dump_ipv4_addr(&ip.dst);
|
||||||
dprintf("Version: %d\n", iph.version_header_length >> 4);
|
dprintf("Protocol: %d (%s)\n", ip.protocol, pname);
|
||||||
dprintf("Header Length (32 bit words): %d\n", iph.version_header_length & 0x0f);
|
dprintf("Version: %d\n", ip.version_header_length >> 4);
|
||||||
|
dprintf("Header Length (32 bit words): %d (%d bytes)\n",
|
||||||
|
ip.version_header_length & 0x0f,
|
||||||
|
4 * (ip.version_header_length & 0x0f));
|
||||||
// TODO: dprintf("Precedence: \n");
|
// TODO: dprintf("Precedence: \n");
|
||||||
dprintf("Total length: %d\n", ntohs(iph.total_length));
|
dprintf("Total length: %d\n", ntohs(ip.total_length));
|
||||||
dprintf("Identification: %d\n", ntohs(iph.identification));
|
dprintf("Identification: %d\n", ntohs(ip.identification));
|
||||||
// TODO: dprintf("Fragmentation allowed, Last fragment\n");
|
// TODO: dprintf("Fragmentation allowed, Last fragment\n");
|
||||||
dprintf("Fragment Offset: %d\n", ntohs(iph.flags_frag_offset) & 0x1fff);
|
dprintf("Fragment Offset: %d\n", ntohs(ip.flags_frag_offset) & 0x1fff);
|
||||||
dprintf("Time to Live: %d second(s)\n", iph.ttl);
|
dprintf("Time to Live: %d second(s)\n", ip.ttl);
|
||||||
dprintf("Checksum: 0x%X (%s)\n", ntohs(iph.header_checksum), "Valid"); // TODO: check the checksum!
|
dprintf("Checksum: 0x%X (%s)\n", ntohs(ip.header_checksum), "Valid"); // TODO: check the checksum!
|
||||||
}
|
}
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|||||||
Reference in New Issue
Block a user