bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: oskit-mach & oskit-20010214: network


From: Daniel Wagner
Subject: Re: oskit-mach & oskit-20010214: network
Date: Wed, 29 Aug 2001 00:46:06 +0200
User-agent: Mutt/1.2.5i

On Mon, 27 Aug 2001, Daniel Wagner wrote:

> I will write such a small test program and post here when I think I got
> it right.

Alright here is my first attempt. After reading some other small
programs it was almost easy to figure out how mach works. I hope it is
not a total mess.

wagi

----------------------- xmit-test.c -----------------------

#include <mach/kern_return.h>
#include <mach/port.h>
#include <assert.h>
#include <hurd.h>

/*
Ethernet (a.k.a. Ethernet II)

+---------+---------+---------+----------
|   Dst   |   Src   |  Type   |  Data... 
+---------+---------+---------+----------
<-- 6 --> <-- 6 --> <-- 2 --> <-46-1500->

Type 0x80 0x00 = TCP/IP
Type 0x06 0x00 = XNS
Type 0x81 0x37 = Novell NetWare
*/

/* Ethernet Version II Frame Format */
struct _ethernet_packet {
  unsigned char da[6];  
  unsigned char sa[6];
  unsigned char ethertype[2];
  unsigned char data[46];
  unsigned long fcs;
} ethernet_packet;


int
main (int argc, char **argv)
{
  kern_return_t err;
  device_t      master_device,ether_port;
  u_int         count, len;

  char *name = "eth0";
  int i;

  /* get the port rights */
  err = get_privileged_ports (0, &master_device);
  if (err)
    return 1;

  err = device_open (master_device, D_WRITE, name, &ether_port);
  mach_port_deallocate (mach_task_self (), master_device);
  if (err)
    return 1;

  /* construct one ethernet packet */
  /* destination mac adress */
  ethernet_packet.da[0] = 0x00;
  ethernet_packet.da[1] = 0x00;
  ethernet_packet.da[2] = 0xB4;
  ethernet_packet.da[3] = 0x55;
  ethernet_packet.da[4] = 0x49;
  ethernet_packet.da[5] = 0xCC;

  /* source mac adress */
  ethernet_packet.sa[0] = 0x00;
  ethernet_packet.sa[1] = 0x00;
  ethernet_packet.sa[2] = 0xB4;
  ethernet_packet.sa[3] = 0xA4;
  ethernet_packet.sa[4] = 0x64;
  ethernet_packet.sa[5] = 0xF4;

  /* type of service, a faked one */
  ethernet_packet.ethertype[0] = 0x12;
  ethernet_packet.ethertype[1] = 0x34;

  /* init the payload */
  for (i=0; i<46; i++) {
    ethernet_packet.data[i] = 0x0;
  }

  len = sizeof (struct _ethernet_packet);
  ethernet_packet.fcs = 0x0;

  for (i=0; i<10; i++)
    {
      err = device_write (ether_port, D_NOWAIT, 0, &ethernet_packet, len, 
&count);
      assert_perror (err);
      assert (count == len);
    }

  mach_port_deallocate (mach_task_self (), ether_port);

  return 0;
}


-- 
Daniel Wagner
email: wagi@gmx.ch

GnuPG: 1024D/DCDE890A (public key available on any keyserver)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]