Hi j_clifton,

as far as I know, the E&S can use UDP, too. But I´ve written a little
C-program to send raw ethernet form linux which compiles fine (I am
using SuSE-Linux, but this should not matter). The code is attached.
I've got the information out of the man pages.

Hope this helps

Bernd



[EMAIL PROTECTED] wrote:
> 
> Anyone (especially simulation types) have any examples of using raw ethernet? I
> am trying to connect a Evans & Sutherland ESIG 5350 Image generator and they use
> raw ethernet. I am running Redhat 6.0/6.1 SMP.
> 
> I read the network newsgroups and cobbled up some code but it doesn't compile.
> Man 4 packet refers to using a sockaddr_ll struct to pass the MAC address but
> bind, sendto, and recvfrom all complain about type errors because they want a
> sockaddr, not a sockaddr_ll. Also, what is a sll_ifindex?
> 
> -- [rtl] ---
> To unsubscribe:
> echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
> echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
> ---
> For more information on Real-Time Linux see:
> http://www.rtlinux.org/rtlinux/
/*
 *  $Id: rp_send.c,v 1.2 2000/01/27 21:43:27 bernd Exp bernd $
 *
 *  raw packet sender for testing rtl-ethernet receiver
 *  -   -      ----
 *
 *  this uses PF_PACKET and SOCK_RAW and must be run as root
 *
 *  (c) Bernd Blessmann
 *
 *  Author: Bernd Blessmann, 26.01.2000
 *
 */


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#include <features.h>    /* for the glibc version number */
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
#include <netpacket/packet.h>
#include <net/ethernet.h>     /* the L2 protocols */
#else
#include <asm/types.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>   /* the L2 protocols */
#endif         


#include "rt_test.h"


int main () {
  char hw_source_addr[ETH_ALEN] = {0x00, 0x00, 0xF8, 0x09, 0x9C, 0x71};
  char hw_dest_addr[ETH_ALEN]   = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  char* msg;        /* to send; contains header and data */
  short int proto = ETH_P_IP;
  int i;
  int msg_size;
  int packet_socket;
  struct sockaddr_ll ll_source_addr;
  struct sockaddr_ll ll_dest_addr;
  struct ethhdr ether_header;
  data_struct_t data;


  if ( (packet_socket = socket(PF_PACKET, SOCK_RAW, htons(proto))) == -1 ) {
    perror("rp_send: main(): socket()");
    exit (1);
  }

  /* source address for bind */
  ll_source_addr.sll_family = AF_PACKET;
  ll_source_addr.sll_protocol = htons(proto);
  ll_source_addr.sll_ifindex = 3;
  ll_source_addr.sll_halen = ETH_ALEN;
  memcpy (ll_source_addr.sll_addr, hw_source_addr, ETH_ALEN);

  /* destinatin address for sendto */
  ll_dest_addr.sll_family = AF_PACKET;
  ll_dest_addr.sll_protocol = htons(proto);
  ll_dest_addr.sll_ifindex = 3;
  ll_dest_addr.sll_halen = ETH_ALEN;
  memcpy (ll_dest_addr.sll_addr, hw_dest_addr, ETH_ALEN);

  if (bind (packet_socket,
            (struct sockaddr*)&ll_source_addr,
            sizeof(ll_source_addr)) == -1 ) {
    perror("rp_send: main(): bind()");
    exit (1);
  }

  /* ethernet header */
  memcpy (ether_header.h_dest, hw_dest_addr, ETH_ALEN);
  memcpy (ether_header.h_source, hw_source_addr, ETH_ALEN);
  /* length of data instead of protocol */
  /* ether_header.h_proto = htons(proto); */
  ether_header.h_proto = htons(sizeof(data));

  /* data */
  data.len = sizeof(data);
  data.timestamp = ~0;          /* no timestamp for now */
  data.da_len = DATA_COUNT;
  for (i = 0; i < DATA_COUNT; i++) {
    data.da[i] = i;
  }

  /* msg */
  msg_size = sizeof(ether_header) + sizeof(data);
  if ( (msg = malloc(msg_size)) == NULL ) {
    fprintf(stderr, "rp_send: main(): malloc(): No memory available\n");
    exit (1);
  }
  memcpy (msg, &ether_header, sizeof(ether_header));


  for (i = 0; i < 5; i++) {
    int j;

    data.seq_nr = i;
    memcpy (msg + sizeof(ether_header), &data, sizeof(data));

    for (j = 0; j < msg_size; j++) {
      printf ("0x%2.2X ", msg[j] & 0x000000FF);
    }
    printf ("\n\n");

    if ( sendto(packet_socket, msg, msg_size, 0,
                (struct sockaddr*)&ll_dest_addr,
                sizeof(ll_dest_addr)) == -1 ) {
      perror("rp_send: main(): sendto()");
      exit (1);
    }
  }

  close (packet_socket);

  return 0;
}
    



/*
 *  $Id: rt_test.h,v 1.6 2000/03/02 14:37:31 e6t40 Exp e6t40 $
 *
 *  RealtimeLinuxEthernet
 *  Header fuer Testmodule
 *
 *  Autor: Bernd Blessmann
 *  Datum: 19.01.2000
 *
 */


#ifndef rt_test_h
#define rt_test_h

#ifdef __RTL__
# include <rtl.h>
#endif /* __RTL__ */


#define MS 1000000              /* one ms in ns */
#define PERIOD (2*MS)           /* send period; recv period is half of that */

#define DATA_COUNT 2000

typedef struct {
  int len;
  int seq_nr;

#ifdef __RTL__
  hrtime_t timestamp;
#else
  long long timestamp;
#endif /* __RTL__ */

  int da_len;
  int da[DATA_COUNT];
} data_struct_t;


#endif /* rt_test_h */

Reply via email to