Announcement

Collapse
No announcement yet.

problems with coding c++ code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • problems with coding c++ code

    i have been trying to get some code to work that i got out of a 2600 issue but it wont work. I tryed to compile it and run it in unix and microsoft c++.net and microsoft c++ 6.0 and none of them work. They say they are missing about half of the include files. the code is kinda long but it is the forging pings code in the fall 1999 issue if you would like me to post it i will but its like 4 pages. Can somone tell me whats wrong? should i try another compiler. I cant find any solutions on google and no other code like this. I think its c++ or c. thanks

  • #2
    If you e-mail it to me, I can take a look at it.
    the fresh princess of 1338

    What did I do to make you think I give a shit?

    Comment


    • #3
      k here is the code

      #include "stdafx.h"
      #include <stdio.h>
      #include <ctype.h>
      #include <errno.h>
      #include <fcntl.h>
      #include <netdb.h>
      #include <stdlib.h>
      #include <string.h>
      #include <uniastd.h>

      #include <sys/pram.h>
      #include <sys/socket.h>
      #include <sys/time.h>
      #include <sys/ioctl.h>

      #include <netinet/in.h>
      #include <netinet/in_systm.h>
      #include <netinet/ip.h>
      #include <netinet/ip_icmp.h>
      #include <arpa/inet.h>

      #include <net/bpf.h>
      #include <net/if.h>
      #include <netinet/if_ether.h>

      #define PKTSIZE 56
      #define BUFSIZE sizeof(struct ether_header) + siezof(struct ip) + 8 + PKTSIZE

      U_char data[BUFSIZE];

      int resolve(const char *, u_long *);
      int in_cksun(u_short *, int);
      void dump(const u_char *, int);
      void usage(const char *);
      int
      main(int argc, char *argv[])
      {
      extern char *optrag;
      extern int optind;
      struct ether_header *ehdr;
      struct icmp *icp;
      struct ifreq ifr;
      struct ip *iphdr;
      u_char *p = data;
      char *device = "ed0";
      char *pname;
      char bpfdev[32];
      int fd = -1;
      int nbytes = BUFSIZE:
      int n = 0;
      int ch;

      pname = argv[0];
      while ((ch = getopt(argc, argv, "i:")) != EOF) {
      switch (ch) {
      case 'i';
      device = optarg;
      break;
      default:
      return(1);
      }
      }
      argc -= optind;
      argv += optind;
      if (argc !=3) {
      usage(pname);
      return(1);
      }
      srand(getpid());

      do {
      sprintf(bpfdev, "/dev/bpf%d", n++):
      fd= open(bpfdev, O_RDWR);
      } while (fd < 0 && (errno == EBUSY || errno ==EPERM));
      if (fd < 0) {
      perror(bpfdev);
      return(1);
      }

      strncpy(ifr.ifr_name, device, sezeof(ifr.ifr_name));
      if (iotcl(fd, BIOCSETIF, &ifr) < 0) {
      perror("BIOCSETIF");
      return(1);
      }

      if (ioctl(fd, BIOCGDLT, &n) < 0) {
      perror("BIOCGDLT");
      return(1);
      }
      if (n!= DLT_EN10MB) {
      fprintf(stderr, "&s: Unsupported data-link type\n", bpfdev);
      return(1);
      }

      ehdr = (struct ether_header *)p;
      if (ether_hostton(arg[2], ehdr->ehter_dhost)) {
      fprint(stderr, "%s: No hardware adress\n:, argv[2]);
      return(1);
      }
      bzero(ehdr->ether_shost, ETHER_ADDR_LEN);
      edhr->ether_type = htons(ETHERTYPE_IP);
      p += sizeof(struct ether_header);

      iphdr = (struct ip *)p;
      iphdr->ip_v = IPVERSION;
      iphdr->ip_hl = sizeof(struct ip) >> 2;
      iphdr->ip_tos = 0;
      iphdr->ip_len = htons(BUFSIZE - sizeof(struct ether_header));
      iphdr->ip_id = htons(rand() % 0x10000);
      iphdr->ip_off = 0;
      iphdr->ip_ttl = MAXTLL;
      iphdr->ip_p = IPPROTO_ICMP;
      iphdr->ip_sum = 0;
      if (resolve(agrv[0], &iphdr->ip_src.s_addr)) {
      fprintf(stderr, "%s:unkown host\n", argv[1]);
      return(1);
      }
      if (resolve(argv[0], &iphdr->ip_dst.s_addr)) {
      fprintf(stderr, "%s: unkown host\n", argv[0]);
      return(1);
      }
      iphdr->ip_sum = in_cksum((u_short *)iphdr, sizeof(struct ip));
      p += sizeof(struct ip);

      icp = (struct icmp *)p;
      icp->icmp_type = ICMP_ECHO;
      icp->icmp_code = 0;
      icp->icmp_cksum = 0;
      icp->icmp_id = htons(rand() % 0x10000);
      icp->icmp_seq = 0;
      p += 8;
      for (n = 0; n< PKTSIZE; ++n)
      p[n] =n;
      gettimeofday((struct timeval *)p, (struct timezone *)NULL);
      icp->icmp_cksum = in_cksum((u_short *)icp, 8 + PKTSIZE);

      if ((cbytes = write(fd, data, seze of(data))) < 0) {
      perror("write");
      return(1);
      }

      dump(datd, nbytes);

      close(fd);
      return(0);
      }

      int
      resolve(const char *hostname, u_long *addr)
      {
      struct hostent *hp;

      if((hp = gethostbyname(hostname)) == NULL)
      *addr = inet_addr(hostname);
      else
      bcopy(hp->h_addr_list, addr, sizeof(*addr));

      if (*addr == INADDR_NONE)
      return(1);

      return(0);
      }

      int
      in_cksum(u_short *addr, int len)
      {
      register int nleft = len;
      register u_short *w =addr;
      register int sum = 0;
      u_short answer = 0;

      while (nleft >1) {
      sum += *w++;
      nleft -= 2;
      }

      if (nleft ==1) {
      *(u_char *)(&answer) = *(u_char *)w ;
      sum += answer;
      }

      sum = (sum >> 16) + (sum & 0xffff);
      sum += (sum >>16);
      answer = ~sum;
      return(answer);
      }

      Void
      dump(const u_char *p, int n)
      {
      char dec[33];
      char hex[25];
      char asc[9];
      int i = 0;

      while (-n >= 0) {
      sprintf(hex + i * 3, "%02X ", *pP;
      sprintf(dec + i * 4, "%3d ", *p);
      sprintf(asc +i, "%c", isprint(*p) ? *p : '.');
      if ((++i == 8) || (n == 0)) {
      printf("%-32s| %-24s| %-8s\n", dec, hex, asc);
      i = 0;
      }
      p++;
      }
      }

      void
      usage(const char *argv0)
      {
      char *p;

      if ((p = strrchr(argv0, '/')) !=NULL)
      argv0 = p + 1;
      fprintf(stderr, "usage: %s [-i interface] dst src router\n", argv0);
      }

      Comment


      • #4
        He said to email it to him. You can get a persons email by clicking on their member name.

        Comment


        • #5
          Since you are posting public, please add your credit card number. :D

          Comment


          • #6
            what are you trying to compile it with in nix?
            if it gets me nowhere, I'll go there proud; and I'm gonna go there free.

            Comment


            • #7
              why would i add my credit card number? and i tryed the profile it was locked out for the e-mail part. i tryed*nix because war0ps suggested it and could you suggest a compiling program for *nix. anyone have suggestions?

              Comment


              • #8
                Originally posted by jetforce4004
                why would i add my credit card number? and i tryed the profile it was locked out for the e-mail part. i tryed*nix because war0ps suggested it and could you suggest a compiling program for *nix. anyone have suggestions?
                God Forbid you visit the persons website. You might actually find a whole assortment of ways to contact the person. But, shit that would take actually processes of your brain, wouldn't it?

                What *nix distro are you using?

                Comment


                • #9
                  Well, the very first include on the list, "stdafx.h", is a programmer defined file... that's why it's in quotes rather than angle brackets. So... you're not going to find that in any standard library. Without that, it'll never work, but.... I'll continue the explanation anyway.

                  The second one that comes up bad is <uniastd.h>. I can only guess that this is a typo, and they really meant <unistd.h>, a library of misc. UNIX standard symbolic constants and types.

                  The last one that wasn't found was <sys/pram.h>. Again, I'm going with a typo, and assuming this was meant to be <sys/param.h>, which, as you can probably guess, is a library to describe system parameters.

                  There's also an unterminated string on line 97. Just add a double quote before the last paren.

                  These are the errors I got on an initial compile using gcc version 2.95.3 under Slackware 8.1. There may be more, of course, once those are resolved.

                  If the article had an e-mail address for the author, I'd try that for a source for the first header file... otherwise, you're pretty much SOL.

                  Oh, and PerfectSword... I'm a "she". :-)
                  Last edited by octalpus; January 1, 2003, 06:37.
                  the fresh princess of 1338

                  What did I do to make you think I give a shit?

                  Comment


                  • #10
                    It was probably intentional... keep it to those that know
                    if it gets me nowhere, I'll go there proud; and I'm gonna go there free.

                    Comment


                    • #11
                      Originally posted by c0nv3r9
                      It was probably intentional... keep it to those that know
                      ¿Que?
                      the fresh princess of 1338

                      What did I do to make you think I give a shit?

                      Comment


                      • #12
                        Originally posted by octalpussy
                        ¿Que?
                        everyoen but, jetforce4004
                        shit i dunno, i just work at the place.

                        Comment

                        Working...
                        X