How can I fix this switch case menu error in C? -


well first let me show code...

#include <stdio.h> #include <stdlib.h> #include <string.h>     #include <errno.h>  #include <sys/socket.h>     #include <netinet/in.h>  #include <arpa/inet.h>  #include <unistd.h>       void load_menu(void); void flood(void); void dos(void); void scan(void);   int main(int argc, char** argv) {      // ip values     const char* google_dns_server = "192.168.1.1";     int dns_port = 53;      struct sockaddr_in serv;      int sock = socket ( af_inet, sock_dgram, 0);      //socket not created     if(sock < 0)     {         perror("socket error");     }      printf ("                                                      \n");     printf ("                 __     __   ____  ____               \n");     printf ("                (  )   (  ) (  , |(  , |              \n");     printf ("                 )(__  )__(  ) _/  ) _/               \n");     printf ("                (____)(_)(_)(_)   (_)                 \n");       printf ("                                                      \n");          printf ("                   version [0.1.0]                    \n");     printf ("            https://github.com/abrupt/lapp            \n");     printf ("                                                      \n");     printf ("                                  written @abrrupt \n");      memset( &serv, 0, sizeof(serv) );     serv.sin_family = af_inet;     serv.sin_addr.s_addr = inet_addr( google_dns_server );     serv.sin_port = htons( dns_port );      int err = connect( sock , (const struct sockaddr*) &serv , sizeof(serv) );      struct sockaddr_in name;     socklen_t namelen = sizeof(name);     err = getsockname(sock, (struct sockaddr*) &name, &namelen);      char buffer[100];     const char* p = inet_ntop(af_inet, &name.sin_addr, buffer, 100);      if(p != null) {         printf("local ip: %s \n" , buffer);     }     else{         printf ("error number: %d . error message: %s \n" , errno , strerror(errno));     }      close(sock);      load_menu();     return 0; }  void load_menu(void) {     int choice;     int num;     int ch;          {     printf("+------------------------------------------------------------------+\n");     printf("|            commands           |          description             |\n");     printf("+------------------------------------------------------------------+\n");      printf("+------------------------------------------------------------------+\n");           printf("|(1) syn flood attack           | create new flood;              |\n");     printf("|(2) dos attack                 | start dos attack;              |\n");     printf("|(3) port scan                  | run tcp port scan                |\n");     printf("|(4) delete_all                 | delete exisitng history;     |\n");     printf("+------------------------------------------------------------------+\n");     scanf("%d",&choice);          switch(choice)         {             case 1: flood();                 break;             case 2: dos();                 break;             case 3: scan();                 break;             case 4: printf("quitting program!\n");                 exit( 0 );                 break;             default: printf("invalid choice!\n");                 break;         }      } while (choice != 3);       printf("use > ");     scanf("%d",&num);      /* flushes input buffer newline scanf() */     while ( (ch = getchar()) != '\n' && ch != eof) ;      printf("\n\npress enter continue.");     while ( (ch = getchar()) != '\n' && ch != eof);      return; } 

ok i'm having issue outputting

"_dos", referenced from:       _load_menu in menu-20c7bc.o   "_flood", referenced from:       _load_menu in menu-20c7bc.o   "_scan", referenced from:       _load_menu in menu-20c7bc.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation) 

i'm guessing switch case menu. whole point of menu users interact options (obviously).

i wondering how can fix switch case menu can easy type number option , have code output whatever option chose.

so example:

if chose option 1 output syn flood ip.

that's kinda whole point of switch case menu. thanks

the errors posted linker errors, caused declarations of functions flood(), dos(), , scan() not having definitions. if need test out menu, i'd recommend defining "placeholder" functions each 1 printf statement (or did, put printf statements in cases, you'll end changing later on anyway) until actual functions , running.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -