Jan-Benedict Glaw writes:
 > 
 > ...I'm interested in that piece of code, too! Please send a copy!
 >> 
 >> How does your wrapper dump to the network?

Here's my wrapper. It's nothing fancy. It dumps an ethernet frame onto
the network. I set the src and dst address to that of the sending device, so
nobody else feels responsible for the packet. I also used an ethernet
protocol number which is (hopefully) unused. One of my hosts has a WaveLAN
card running in promiscuous mode and just listening to the traffic. This
way I can pick up all the network traffic with tcpdump and write it
to a file to analyse it later.

#define ETHERTYPE_RETHER_DEBUG 0x0808

void
print_wl(const rtnode_t *node, int mode, const char *fmt, ...)
{
  static char buf[256];
  char *strBuf = NULL;
  va_list ap;

  switch(mode) {
  case DEBUG_INFO:
    strcpy(buf, "--- ");
    strBuf = buf;
    break;
  case DEBUG_ERROR:
    strcpy(buf, "*** ");
    strBuf = buf;
    break;
  default:
    strBuf = buf+4;    
  }

  va_start(ap, fmt);
  vsprintf(buf+4, fmt, ap);
  va_end(ap);

  if (mode == DEBUG_ERROR)
    printk(KERN_WARNING "%s", strBuf);

#ifdef NET_DUMP_DEBUG
  {
    int bufLen;
    struct sk_buff *skb;
    unsigned short proto = htons(ETHERTYPE_RETHER_DEBUG);

    bufLen = strlen(strBuf);
    if (!bufLen)
      return;

    if (strBuf[bufLen-1] == '\n')
      strBuf[bufLen-1] = 0;
    else
      bufLen++;

    skb = alloc_skb(ETH_HLEN+bufLen, GFP_ATOMIC);
  
    skb->dev = node->dev;
    memcpy(skb_put(skb, ETH_ALEN), node->dev->dev_addr, ETH_ALEN);
    memcpy(skb_put(skb, ETH_ALEN), node->dev->dev_addr, ETH_ALEN);
    memcpy(skb_put(skb, 2), &proto, 2);
    memcpy(skb_put(skb, bufLen), strBuf, bufLen);
                
    wl_transmit_skb(skb); // see below
  }
#endif
}

void
wl_transmit_skb(struct sk_buff *skb)
{
  if (!skb) {
    printk("wl *** wl_transmit_skb(): skb NULL pointer\n");
    return;
  }

  // spinlock until device is ready
  while(skb->dev->tbusy)
    ;

  // this transmits the buffer to the WaveLAN card 
  // and dumps it onto the network
  wv_packet_write(skb->dev, skb->data, skb->len);

  dev_kfree_skb(skb, FREE_WRITE);
}
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]

Reply via email to