HELP writing ethernet traffic generator

Dave Carhart drc at konkord.uucp
Mon Sep 17 02:46:51 AEST 1990


I'm trying to write a traffic generator for the ethernet using the nit I'm
not having any luck.  what follows is basiclly the code that I have
written to do this.  All the functions returns protperly and the write
command says it's writing to the device.  But when I look on the line with
the lanalyzer or the light on the delni (sp?) there is NO activity on my
ethernet line.

This is being done on a Sun Sparc Station 1+ using Sun-OS Ver. 4.1

ANY help would be greatly appreciated.  Please E-mail me at this address
...

Dave Carhart		Phone	508-460-4646    FAX 508-481-9772 
Concord Communications, Inc.		 	Telex  910-240-1986	
753 Forest St. 			uucp     -->	uunet!konkord!drc
Marlboro, MA 01572 USA	        internet -->    drc%konkord at uunet.uu.net

------------------------------------------------------------------------

/* 
 * initdevice for "SUNOS4" from s.nit_streams.c
 * needed to access NIT (Network Interface Tap)
 */
#define CHUNKSIZE	3072
#define BUFSPACE	4*CHUNKSIZE
#define ALIGNMENT	4   /* align on integer boundries */
#define NIT_DEV		"/dev/nit"
#define FBUFSIZE	600000
#define TELNETSIZE	60

int if_fd = -1;
int tflag = 1;		/* true if NI_TIMESTAMP is set */
int dflag = 1;		/* true if NI_DROPS is set */
/* NI_LEN is set if snaplen > 0 */
u_long	chunksize;
u_long	snaplen = ((sizeof(struct ether_header)
			+ 64 /* Max IP hdr */
			+ sizeof(union ip_data)
			+ 3) / 4) * 4;      /* even 4-byte boundary */

/* sizeof headers (20) + snaplen (108) = 128 */
/* (snaplen + nit headers) should ideally divide chunksize */

char *EtherIface = "le0";   /*  Ethernet interface name */
int  nit_opened = FALSE;

static char telnet[TELNETSIZE] = {    8,    0, 0x14, 0x30, 0x42, 0x21,    8,    0,
				   0x20,    1, 0x91, 0x30,    8,    0, 0x45,    0, 
				      0, 0x29, 0x76, 0x99,    0,    0, ox1e,    6, 
				   0x70, 0x2f, 0x59, 0x81,    1, 0x83, 0x59, 0x81, 
				      1, 0x82,    0, 0x17,    7, 0x83, 0x70, 0xb6, 
				   0xb5, 0x49, 0x20, 0x5a,    1, 0x20, 0x50, 0x10, 
				   0x10,    0, 0x3d, 0xad,    0,    0, 0x5d, 0x61, 
				   0x73, 0x68,    8,    0};  /* telnet frame */

#define XMITSIZE TELNETSIZE

/***************************************************************
 * Create Network Interface Tap (NIT) Protocol socket and initialize it.
 *  Can look for specified Ethernet Type, or NT_ALLTYPES.
 *    #define EtherIface	-1	selects promiscous mode 
 */
int initdevice(EtherType)
int EtherType;
{
  struct strioctl si;
  struct ifreq    ifr;
  struct timeval  timeout;
  u_long if_flags = 0;
  chunksize = CHUNKSIZE;


  if ((if_fd = open(NIT_DEV, O_RDWR)) < 0)
    {
	perror("nit open");
	printf("NIT OPEN FAILED");
	return(BAD);    
    }
  printf("NIT OPENED if_fd= %x", if_fd);
  nit_opened = TRUE;

        si.ic_timout = INFTIM;

        /* Push and configure the buffering module.  */
        if (ioctl(if_fd, I_PUSH, "nbuf") < 0)
	 {
                perror("ioctl (I_PUSH \"nbuf\")");
                return(BAD);    
         }
        timeout.tv_sec = 1;
        timeout.tv_usec = 0;
        si.ic_cmd = NIOCSTIME;
        si.ic_len = sizeof timeout;
        si.ic_dp = (char *)&timeout;
        if (ioctl(if_fd, I_STR, (char *)&si) < 0) 
	 {
                perror("ioctl (I_STR: NIOCSTIME)");
                return(BAD);    
         }

        si.ic_cmd = NIOCSCHUNK;
        si.ic_len = sizeof chunksize;
        si.ic_dp = (char *)&chunksize;
        if (ioctl(if_fd, I_STR, (char *)&si) < 0) 
	 {
                perror("ioctl (I_STR: NIOCSCHUNK)");
                return(BAD);    
         }

        /*
         * Configure the nit device, binding it to the proper
         * underlying interface, setting the snapshot length,
         * and setting nit_if-level flags.
         */
        (void) strncpy(ifr.ifr_name, EtherIface, sizeof ifr.ifr_name);
        ifr.ifr_name[sizeof ifr.ifr_name - 1] = ' ';
        si.ic_cmd = NIOCBIND;
        si.ic_len = sizeof ifr;
        si.ic_dp = (char *)𝔦
        if (ioctl(if_fd, I_STR, (char *)&si) < 0) 
	 {
                perror("ioctl (I_STR: NIOCBIND)");
                return(BAD);    
         }

        if (snaplen > 0) 
	{
                si.ic_cmd = NIOCSSNAP;
                si.ic_len = sizeof snaplen;
                si.ic_dp = (char *)&snaplen;
                if (ioctl(if_fd, I_STR, (char *)&si) < 0) 
		{
                        perror("ioctl (I_STR: NIOCSSNAP)");
                        return(BAD);    
                }
        }

        if_flags = NI_PROMISC;
        if (tflag) if_flags = if_flags | NI_TIMESTAMP;
        if (dflag) if_flags = if_flags | NI_DROPS;
        if (snaplen > 0) if_flags = if_flags | NI_LEN;

        if (if_flags != 0) 
	{
                si.ic_cmd = NIOCSFLAGS;
                si.ic_len = sizeof if_flags;
                si.ic_dp = (char *)&if_flags;
                if (ioctl(if_fd, I_STR, (char *)&si) < 0) 
		{
                        perror("ioctl (I_STR: NIOCSFLAGS)");
                        return(BAD);    
                }
        }

        /*
         * Flush the read / write queue, to get rid of anything that
         * accumulated before the device reached its final configuration.
         */
        if (ioctl(if_fd, I_FLUSH, (char *)FLUSHRW) < 0) 
	{
                perror("ioctl (I_FLUSH)");
                return(BAD);    

        }
   return(GOOD);
} /* initdevice */

/***************************************************************
 *
 */
deinitdevice()
{
    close(if_fd);
    if_fd = -1;
}



/***************************************************************
 *  Prototype - 
 */

main ()
{
register i;
int ret_val = 2;

  if ((seteuid (geteuid ())))		/* set up as root */
     printf  ("failed seteuid ()\n");
  else
   {
     if ((initdevice(-1)) == BAD)	/* -1 selects promiscous mode */
	printf("\nCouldn't init Device Progam aborting\n");
     else
      {
        printf("\nFile number is %d\nStarting write command\n", if_fd);
        for (i=0; i<30000; i++)
           if ((ret_val = write (if_fd, a, XMITSIZE)) != XMITSIZE)
	    {
		perror ("write error - ");
        	printf("ret_val is %d\n", ret_val);
		break;
	    }
        printf("Stoping write command\n");
        close(if_fd);
      }
   }
  deinitdevice;
}



-- 
Dave Carhart		Phone	508-460-4646    FAX 508-481-9772 
Concord Communications, Inc.		 	Telex  910-240-1986	
753 Forest St. 			uucp     -->	uunet!konkord!drc
Marlboro, MA 01572 USA	        internet -->    drc%konkord at uunet.uu.net



More information about the Comp.sys.sun mailing list