home *** CD-ROM | disk | FTP | other *** search
/ Steganos Hacker Tools / SHT151.iso / programme / scanner / nmapNTsp1 / Win_2000.exe / nmapNT-src / nmapfe / nmapfe_sig.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-08  |  38.9 KB  |  1,124 lines

  1. /* Author: Zach
  2.  * Mail: key@aye.net
  3.  * IRC: EFNet as zach` or key in #bastards or #neatoelito
  4.  * AIM (Aol): GoldMatrix
  5.  *
  6.  * Change the source as you wish, but leave these comments..
  7.  *
  8.  * Long live Aol and pr: Phreak. <grins>
  9.  */
  10.  
  11. #ifndef MAX_PARSE_ARGS
  12. #define MAX_PARSE_ARGS 512
  13. #endif
  14.  
  15. #if MISSING_GTK
  16. /* Do nothing, nmapfe.c will spit out an error */
  17. #else
  18.  
  19. #include <gtk/gtk.h>
  20. #include <stdio.h>
  21. #include <signal.h>
  22. #include <stdlib.h>
  23. #include <unistd.h>
  24. #include <string.h>
  25. #include <sys/types.h>
  26. #include <sys/stat.h>
  27. #include <sys/wait.h>
  28. #include <fcntl.h>
  29. #include <strings.h>
  30. #include <assert.h>
  31. #include <ctype.h>
  32. #include <errno.h>
  33. #include <signal.h>
  34.  
  35. #include "nmapfe.h"
  36. #include "nmapfe_sig.h"
  37.  
  38. /*This is for our timeout function. */
  39. guint32 time_out = 125; /* 1/8 a second */
  40. gint tag; /*tag for the gdk* funcs */
  41. gpointer *data;
  42. int save_open;
  43. extern struct MyWidgets *MW;
  44. extern int our_uid;
  45. extern int view_type;
  46. int machine_yn = 0;
  47. /* Variables for piping */
  48. int nmap_pid = 0;
  49. int pid;
  50. int pid2;
  51. int pipes[2];
  52. int count = 0;
  53. char buf[9024];
  54. char buf2[9024] = "hello";
  55. int verb = 0;
  56. int append = 0;
  57. int rpc_var = 0;
  58. int ping_h = 0;
  59. int which_scan = 1;
  60. extern char **environ;
  61.  
  62. int
  63. main (int argc, char *argv[])
  64. {
  65.   GtkWidget *main_win;
  66.  
  67.   gtk_set_locale ();
  68.   gtk_init (&argc, &argv);
  69.  
  70.   MW = (struct MyWidgets *) malloc(sizeof(struct MyWidgets));
  71.   bzero(MW, sizeof(struct MyWidgets));
  72.   pipes[0] = pipes[1] = -1;
  73.   signal(SIGPIPE, SIG_IGN);
  74.  
  75.   main_win = create_main_win ();
  76.   gtk_widget_show (main_win);
  77.  
  78.   our_uid = getuid();
  79.  
  80.   if(our_uid == 0){
  81.     gtk_text_insert(GTK_TEXT(MW->output), NULL, NULL, NULL, "You are root - All options granted.", -1);
  82.   } else {
  83.     gtk_text_insert(GTK_TEXT(MW->output), NULL, NULL, NULL, "You are *NOT* root - Some options aren't available.", -1);
  84.   }
  85.  
  86.  
  87.   if(our_uid == 0){
  88.     which_scan = 2;
  89.   } else {
  90.     which_scan = 1;
  91.   }
  92.  
  93.  
  94.   gtk_main ();
  95.   return 0;
  96. }
  97.  
  98. void
  99. on_exit_me_clicked                        (GtkButton       *button,
  100.                        gpointer        user_data)
  101. {
  102.   /* First we want to kill the Nmap process that is running */
  103.   stop_scan();
  104.   gtk_main_quit();
  105. }
  106.  
  107.  
  108. void
  109. on_start_scan_clicked                  (GtkButton       *button,
  110.                                         GtkWidget        *entry)
  111. {
  112.   func_start_scan();
  113. }
  114.  
  115. void
  116. on_Close_activate                      (GtkMenuItem    *menuitem,
  117.                                         gpointer        user_data)
  118. {
  119.   gtk_main_quit();
  120. }
  121.  
  122. void
  123. on_Start_Scan_activate                      (GtkMenuItem    *menuitem,
  124.                                              gpointer        user_data)
  125. {
  126.   gtk_main_quit();
  127. }
  128.  
  129. void
  130. on_about_ok_clicked                    (GtkButton       *button,
  131.                                         GtkWidget        *about)
  132. {
  133.   gtk_widget_hide(about);
  134. }
  135.  
  136. void
  137. on_Save_Log_activate                   (GtkMenuItem    *menuitem,
  138.                                         gpointer        user_data)
  139. {
  140.   GtkWidget *save_file;
  141.   save_file = create_fileselection1();
  142.   gtk_widget_show(save_file);
  143.   save_open = 0;
  144. }
  145.  
  146.  
  147. void
  148. on_Open_Log_activate                   (GtkMenuItem    *menuitem,
  149.                                         gpointer        user_data)
  150. {
  151.   GtkWidget *open_file;
  152.   open_file = create_fileselection1();
  153.   gtk_widget_show(open_file);
  154.   save_open = 1;
  155. }
  156.  
  157.  
  158. void
  159. on_Help_Main_activate                  (GtkMenuItem    *menuitem,
  160.                                         gpointer        user_data)
  161. {
  162.  
  163. }
  164.  
  165. void
  166. on_View_Main_activate                  (GtkMenuItem    *menuitem,
  167.                                         gpointer        user_data)
  168. {
  169.  
  170. }
  171.  
  172. void
  173. on_Help_activate                       (GtkMenuItem    *menuitem,
  174.                                         GtkWidget        *help)
  175. {
  176.   GtkWidget *help_win;
  177.   help_win = create_help_window();
  178.   gtk_widget_show(help_win);
  179. }
  180.  
  181.  
  182. void
  183. on_Get_Nmap_Version_activate           (GtkMenuItem    *menuitem,
  184.                                         gpointer        user_data)
  185. {
  186.   execute("nmap -V");
  187. }
  188.  
  189.  
  190. void
  191. on_About_activate                      (GtkMenuItem    *menuitem,
  192.                                         GtkWidget        *about)
  193. {
  194.   GtkWidget *about_win;
  195.   about_win = create_about_window();
  196.   gtk_widget_show(about_win);
  197. }
  198.  
  199. void
  200. on_ok_button1_clicked                  (GtkButton       *button,
  201.                                         GtkWidget        *window)
  202. {
  203.   char ch[50];
  204.   char *filename, *text_contents, *str, *newstr;
  205.   FILE *file;
  206.   GdkFont *fixed, *bold;
  207.   GdkColormap *cmap;
  208.   GdkColor red, blue, green;
  209.             
  210.   /* Get fonts ready */
  211.   cmap = gdk_colormap_get_system();
  212.   red.red = 0xffff;
  213.   red.green = 0;
  214.   red.blue = 0;    
  215.   if (!gdk_color_alloc(cmap, &red)) {
  216.     g_error("couldn't allocate red");
  217.   }
  218.       
  219.   blue.red = 0;
  220.   blue.green = 0;
  221.   blue.blue = 0xffff;    
  222.   if (!gdk_color_alloc(cmap, &blue)) {
  223.     g_error("couldn't allocate blue");
  224.   }
  225.   
  226.   green.red = 0x0000;
  227.   green.green = 0xffff;
  228.   green.blue = 0x0000;    
  229.   if (!gdk_color_alloc(cmap, &green)) {
  230.     g_error("couldn't allocate green");
  231.   }
  232.       
  233.   bold = gdk_fontset_load("-misc-fixed-bold-r-normal-*-*-120-*-*-*-*-*-*");  
  234.   fixed = gdk_fontset_load ("-misc-fixed-medium-r-*-*-*-120-*-*-*-*-*-*");
  235.   filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION (window));
  236.  
  237.   if(save_open == 0) {
  238.     text_contents = gtk_editable_get_chars(GTK_EDITABLE(MW->output), 0, -1);
  239.     if((file = fopen(filename, "w"))){
  240.       fputs(text_contents, file);
  241.       fclose(file);
  242.     }
  243.     free(text_contents);
  244.   } else {
  245.      
  246.     if(!append)
  247.       kill_output(NULL);
  248.     
  249.     gtk_text_freeze(GTK_TEXT(MW->output));
  250.     if((file = fopen(filename, "r"))){
  251.       while(fgets(ch, 50, file) != NULL) {
  252.     str = ch;
  253.     if(view_type == 1){
  254.       newstr = strtok(str, " ");
  255.       gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, newstr, -1); 
  256.       gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  257.       do {
  258.         newstr = strtok(NULL, " ");
  259.         if(newstr != NULL){
  260.           /********* CATCH STUFF ****************************/
  261.           if(strstr(newstr, "http://")){
  262.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, "http://", -1);
  263.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  264.           }else if(strstr(newstr, "fingerprint")){
  265.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, "fingerprint:", -1);
  266.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  267.         /********* BEGIN PORT COLOR CODING ****************/
  268.           }else if(strstr(newstr, "sftp")){
  269.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "sftp", -1);
  270.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  271.           }else if(strstr(newstr, "mftp")){
  272.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "mftp", -1);
  273.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  274.           }else if(strstr(newstr, "bftp")){
  275.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "bftp", -1);
  276.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  277.           }else if(strstr(newstr, "NetBus")){
  278.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "NetBus", -1);
  279.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  280.           }else if(strstr(newstr, "kshell")){
  281.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "kshell", -1);
  282.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  283.           }else if(strstr(newstr, "klogin")){
  284.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "klogin", -1);
  285.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  286.           }else if(strstr(newstr, "rtelnet")){
  287.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "rtelnet", -1);
  288.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  289.           }else if(strstr(newstr, "telnet")){
  290.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "telnet", -1);
  291.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  292.           }else if(strstr(newstr, "X11")){
  293.         gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, "X11", -1);
  294.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  295.           }else if(strstr(newstr, "tftp")){
  296.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "tftp", -1);
  297.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  298.           }else if(strstr(newstr, "login")){
  299.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "login", -1);
  300.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  301.           }else if(strstr(newstr, "imap2")){
  302.         gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, "imap2", -1);
  303.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  304.           }else if(strstr(newstr, "ftp")){
  305.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "ftp", -1);
  306.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  307.           }else if(strstr(newstr, "pop-3")){
  308.         gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, "pop-3", -1);
  309.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  310.           }else if(strstr(newstr, "exec")){
  311.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "exec", -1);
  312.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  313.           }else if(strstr(newstr, "imap3")){
  314.         gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, "imap3", -1);
  315.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);                    
  316.           }else if(strstr(newstr, "smtps")){
  317.         gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, "smtps", -1);
  318.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  319.           }else if(strstr(newstr, "smtp")){
  320.         gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, "smtp", -1);
  321.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  322.           }else if(strstr(newstr, "pop-2")){
  323.         gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, "pop-2", -1);
  324.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  325.           }else if(strstr(newstr, "systat")){
  326.         gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, "systat", -1);
  327.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  328.           }else if(strstr(newstr, "netstat")){
  329.         gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, "netstat", -1);
  330.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  331.           }else if(strstr(newstr, "cfingerd")){
  332.         gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, "cfingerd", -1);
  333.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  334.           }else if(strstr(newstr, "finger")){
  335.         gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, "finger", -1);
  336.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  337.           }else if(strstr(newstr, "netbios")){
  338.         gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, "netbios-ssn", -1);
  339.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  340.           }else if(strstr(newstr, "X11")){
  341.         gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, "X11", -1);
  342.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  343.           }else if(strstr(newstr, "nfs")){
  344.         gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, "nfs", -1);
  345.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  346.           }else if(strstr(newstr, "sunrpc")){
  347.         gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, "sunrpc", -1);
  348.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  349.           }else if(strstr(newstr, "https")){
  350.         gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, "https", -1);
  351.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  352.           }else if(strstr(newstr, "kpasswds")){
  353.         gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, "kpasswd", -1);
  354.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);                    
  355.           }else if(strstr(newstr, "http")){
  356.         gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, "http", -1);
  357.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  358.           }else if(strstr(newstr, "ssh")){
  359.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "ssh", -1);
  360.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  361.           }else if(strstr(newstr, "shell")){
  362.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "shell", -1);
  363.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  364.           }else if(strstr(newstr, "linuxconf")){
  365.         gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, "linuxconf", -1);
  366.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  367.  
  368.                 /******* END PORT COLOR CODING, BEGIN OS COLORS *****************/
  369.           }else if(strstr(newstr, "Linux")){
  370.         gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, "Linux", -1);
  371.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  372.           }else if(strstr(newstr, "FreeBSD")){
  373.         gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, "FreeBSD", -1);
  374.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  375.           }else if(strstr(newstr, "Win")){
  376.         gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, "Win", -1);
  377.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  378.           }else if(strstr(newstr, "MacOS")){
  379.         gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, "MacOS", -1);
  380.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  381.           }else if(strstr(newstr, "OpenBSD")){
  382.         gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, "OpenBSD", -1);
  383.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  384.           }else if(strstr(newstr, "IRIX")){
  385.         gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, "IRIX", -1);
  386.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  387.           }else if(strstr(newstr, "Windows")){
  388.         gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, "Windows", -1);
  389.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  390.                     
  391.           }else{ 
  392.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, newstr, -1); 
  393.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  394.           }
  395.         }
  396.       }while(newstr);
  397.     }else if(view_type == 0){            
  398.       while(fgets(ch, 50, file) != NULL){
  399.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, ch, -1);
  400.       }
  401.     }
  402.       }
  403.       gtk_text_thaw(GTK_TEXT(MW->output));
  404.       fclose(file);
  405.     } /*end if for file */
  406.   }
  407.   gtk_widget_hide(window);
  408. }
  409.  
  410.  
  411. void
  412. on_cancel_button1_clicked              (GtkButton       *button,
  413.                                         GtkWidget        *window)
  414. {
  415.   gtk_widget_hide(window);
  416. }
  417.  
  418. void func_start_scan()
  419. {
  420.   char *command;
  421.   /*  fprintf(stderr, "start_scan called\n"); */
  422.   if(GTK_TOGGLE_BUTTON(MW->start_scan)->active){
  423.  
  424.     command = build_command(NULL);
  425.     
  426.     /*printf("%s\n", command);*/
  427.  
  428.     if(!(append))
  429.       kill_output(NULL);
  430.  
  431.     nmap_pid = execute(command);
  432.  
  433.   } else {
  434.     stop_scan();
  435.   }
  436. }
  437.  
  438. void kill_output()
  439. {
  440.  
  441.   guint length;
  442.   length = gtk_text_get_length(GTK_TEXT(MW->output));
  443.   gtk_text_backward_delete (GTK_TEXT(MW->output), length);
  444. }
  445.  
  446. int execute(char *command) {
  447.   /* Many thanks to Fyodor for helping with the piping */
  448.   if(pipe(pipes) == -1)
  449.     perror("poopy pipe error");
  450.  
  451.   if (!(pid = fork())) {
  452.     char **argv;
  453.     int argc;
  454.     /*
  455.     char *argv[4];
  456.  
  457.     argv[0] = "sh";
  458.     argv[1] = "-c";     
  459.     argv[2] = command;
  460.     argv[3] = 0;
  461.     */
  462.     argc = arg_parse(command, &argv);
  463.     if (argc <= 0)
  464.       exit(1);
  465.     dup2(pipes[1], 1);
  466.     dup2(pipes[1], 2);
  467.     fcntl(pipes[0], F_SETFL, O_NDELAY);
  468.     if (execvp("nmap", argv) == -1) {
  469.       fprintf(stderr, "Nmap execution failed.  errno=%d (%s)\n", errno, strerror(errno));
  470.       exit(1);
  471.     }
  472.     /*exit(127);*/
  473.   }
  474.   if (pid == -1) {
  475.     fprintf(stderr, "fork() failed.  errno=%d (%s)", errno, strerror(errno));
  476.     pid = 0;
  477.     close(pipes[0]);
  478.     pipes[0] = -1;
  479.   }
  480.   close(pipes[1]);
  481.   pipes[1] = -1;
  482.   tag = gtk_timeout_add(time_out, read_data, data);
  483.  
  484.   return(pid);
  485. }
  486.  
  487. char *build_command() {
  488.  
  489.   int size;
  490.   static char *command = NULL;
  491.   static int command_size = 0;
  492.   char *val = NULL;
  493.   /* Find how much to malloc() */
  494.   size =     strlen(gtk_entry_get_text(GTK_ENTRY(MW->range_text))) +
  495.     strlen(gtk_entry_get_text(GTK_ENTRY(MW->decoy_text))) +
  496.     strlen(gtk_entry_get_text(GTK_ENTRY(MW->input_text))) +
  497.     strlen(gtk_entry_get_text(GTK_ENTRY(MW->device_text)))+
  498.     strlen(gtk_entry_get_text(GTK_ENTRY(MW->bounce_text)))+
  499.     strlen(gtk_entry_get_text(GTK_ENTRY(MW->host_text))) +
  500.     60;
  501.   /* We get 60 from the chars required for each option */
  502.  
  503.   if (size > command_size)
  504.     command = realloc(command, size);
  505.  
  506.   strcpy(command, "nmap ");
  507.   /*Uhm... yeah.. Spit out which scan to perform based
  508.     on the which_scan variable */
  509.  
  510.   if (GTK_TOGGLE_BUTTON(MW->connect_scan)->active) {
  511.     strncat(command, "-sT ", 4);
  512.   } else if (GTK_TOGGLE_BUTTON(MW->ping_scan)->active) {
  513.     strncat(command, "-sP ", 4);
  514.   } else if (GTK_TOGGLE_BUTTON(MW->udp_scan)->active) {
  515.     strncat(command, "-sU ", 4);
  516.   } else if (GTK_TOGGLE_BUTTON(MW->fin_scan)->active) {
  517.     strncat(command, "-sF ", 4);
  518.   } else if (GTK_TOGGLE_BUTTON(MW->syn_scan)->active) {
  519.     strncat(command, "-sS ", 4);
  520.   }
  521.  
  522.   if (rpc_var)
  523.     strncat(command, " -sR ", 5);
  524.    
  525.   if (GTK_TOGGLE_BUTTON(MW->fast_check)->active)
  526.     strncat(command, " -F ", 4);
  527.  
  528.   if (GTK_TOGGLE_BUTTON(MW->range_check)->active) {
  529.     val = gtk_entry_get_text(GTK_ENTRY(MW->range_text));
  530.     if (val && *val) {   
  531.       strncat(command, " -p ", 4);
  532.       strcat(command, val);
  533.       strncat(command, " ", 1);
  534.     }
  535.   }
  536.  
  537.   if(machine_yn){
  538.     val = MW->machine_file;
  539.     strncat(command, " -m ", 4);
  540.     strcat(command, val);
  541.     strncat(command, " ", 1);
  542.   }
  543.  
  544.   if (GTK_TOGGLE_BUTTON(MW->bounce_check)->active){
  545.     val = gtk_entry_get_text(GTK_ENTRY(MW->bounce_text));
  546.     if (val && *val) {   
  547.       strncat(command, " -b ", 4);
  548.       strcat(command, val);
  549.       strncat(command, " ", 1);
  550.     }
  551.   }
  552.  
  553.   if (GTK_TOGGLE_BUTTON(MW->tcp_check)->active)
  554.     strncat(command, "-PT ", 4);
  555.   if (GTK_TOGGLE_BUTTON(MW->fingerprinting_check)->active)
  556.     strncat(command, "-O ", 4);
  557.   if (GTK_TOGGLE_BUTTON(MW->icmp_check)->active)
  558.     strncat(command, "-PI ", 4);
  559.   if (GTK_TOGGLE_BUTTON(MW->ping_check)->active)
  560.     strncat(command, "-P0 ", 4);
  561.   if (GTK_TOGGLE_BUTTON(MW->fragment_check)->active)
  562.     strncat(command, "-f ", 3);
  563.   if (GTK_TOGGLE_BUTTON(MW->identd_check)->active)
  564.     strncat(command, "-I ", 3);
  565.   if (GTK_TOGGLE_BUTTON(MW->resolveall_check)->active)
  566.     strncat(command, "-R ", 3);
  567.   if (GTK_TOGGLE_BUTTON(MW->resolve_check)->active)
  568.     strncat(command, "-n ", 3);        
  569.   if (GTK_TOGGLE_BUTTON(MW->decoy_check)->active) {
  570.     val = gtk_entry_get_text(GTK_ENTRY(MW->decoy_text));
  571.     if (val && *val) {   
  572.       strncat(command, "-D", 2);
  573.       strcat(command, val);
  574.       strncat(command, " ", 1);
  575.     }
  576.   }
  577.  
  578.   if (GTK_TOGGLE_BUTTON(MW->input_check)->active) {
  579.     val = gtk_entry_get_text(GTK_ENTRY(MW->input_text));
  580.     if (val && *val) {   
  581.       strncat(command, "-i ", 3);
  582.       strcat(command, val);
  583.       strncat(command, " ", 1);
  584.     }
  585.   }
  586.  
  587.   if (GTK_TOGGLE_BUTTON(MW->device_check)->active){
  588.     val = gtk_entry_get_text(GTK_ENTRY(MW->device_text));
  589.     if (val && *val) {   
  590.       strncat(command, "-e ", 3);
  591.       strcat(command, val);
  592.       strncat(command, " ", 1);
  593.     }
  594.   }
  595.  
  596.   if (verb){
  597.     strcat(command, "-v ");
  598.   }
  599.  
  600.   strcat(command, gtk_entry_get_text(GTK_ENTRY(MW->host_text)));
  601.  
  602.   return(command);
  603. }
  604.  
  605. void display_nmap_command() {
  606.   char buf[80];
  607.   int len;
  608.  
  609.   /* Need to use the snprintf which comes with nmap ... */
  610.   len = sprintf(buf, "Output from:  %s", build_command());
  611.   if (len < 0 || len >= sizeof(buf)) {
  612.     strcpy(buf, "Output from Nmap");
  613.   }
  614.   gtk_label_set( GTK_LABEL(MW->output_label), buf);
  615. }
  616.  
  617.  
  618.  
  619. void entry_toggle_checkbox (GtkWidget *entry,
  620.                 GtkWidget *checkbox)
  621. {
  622.   char *txt = gtk_entry_get_text(GTK_ENTRY(entry));
  623.   if (!txt || !*txt)
  624.     return;
  625.   gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (checkbox), TRUE);
  626.   display_nmap_command();
  627. }
  628.  
  629. void display_nmap_command_callback(GtkWidget *target_option, char *ignored) {
  630.   display_nmap_command();
  631.   return;
  632. }
  633.  
  634. void validate_option_change(GtkWidget *target_option, char *ignored)
  635. {    
  636.  
  637.   if (GTK_TOGGLE_BUTTON(target_option)->active)  {
  638.     if (target_option == MW->connect_scan) {
  639.       gtk_entry_set_text( GTK_ENTRY(MW->decoy_text), "");
  640.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->decoy_check), FALSE);
  641.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->fragment_check), FALSE);
  642.       gtk_entry_set_text( GTK_ENTRY(MW->device_text), "");
  643.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->device_check), FALSE);
  644.     } else if (target_option == MW->syn_scan || target_option == MW->fin_scan) {
  645.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->identd_check), FALSE);
  646.     } else if (target_option == MW->udp_scan) {
  647.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->identd_check), FALSE);
  648.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->fragment_check), FALSE);
  649.     } else if (target_option == MW->bounce_check) {
  650.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->identd_check), FALSE);
  651.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->fragment_check), FALSE);
  652.       gtk_entry_set_text( GTK_ENTRY(MW->device_text), "");
  653.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->device_check), FALSE);
  654.       gtk_entry_set_text( GTK_ENTRY(MW->decoy_text), "");
  655.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->decoy_check), FALSE);
  656.     } else if (target_option == MW->ping_scan) {
  657.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->identd_check), FALSE);
  658.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->fragment_check), FALSE);
  659.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->fast_check), FALSE);
  660.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->range_check), FALSE);
  661.       gtk_entry_set_text( GTK_ENTRY(MW->range_text), "");
  662.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->fingerprinting_check), FALSE);
  663.     } else if (target_option == MW->fast_check) {
  664.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->range_check), FALSE);
  665.       gtk_entry_set_text( GTK_ENTRY(MW->range_text), "");
  666.     } else if (target_option == MW->range_check) {
  667.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->fast_check), FALSE);
  668.     } else if (target_option == MW->identd_check) {
  669.       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->connect_scan), TRUE);
  670.       validate_option_change(MW->connect_scan, NULL);
  671.     } else if (target_option == MW->decoy_check ||
  672.            target_option == MW->device_check ||
  673.            target_option == MW->fragment_check ) {
  674.       if (GTK_TOGGLE_BUTTON(MW->connect_scan)->active) {
  675.     gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->syn_scan), TRUE);      
  676.     validate_option_change(MW->syn_scan, NULL); 
  677.       } else if (GTK_TOGGLE_BUTTON(MW->bounce_check)->active) {
  678.     gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->syn_scan), TRUE);
  679.     gtk_entry_set_text( GTK_ENTRY(MW->bounce_text), "");
  680.     validate_option_change(MW->syn_scan, NULL);
  681.       } 
  682.     } else if (target_option == MW->input_check) {
  683.       gtk_entry_set_text( GTK_ENTRY(MW->host_text), "");
  684.     }
  685.   }
  686.   display_nmap_command();
  687. }
  688.  
  689.  
  690.  
  691. void scan_options(GtkWidget *widget, int *the_option)
  692. {
  693.   which_scan = (int)the_option;
  694. }
  695.  
  696. gint read_data(gpointer data)
  697. {
  698.   char *str;
  699.   char *newstr;    
  700.   char *tmpstr;
  701.   GdkFont *fixed;
  702.   GdkFont *bold;
  703.   GdkColormap *cmap;
  704.   GdkColor red, blue, green;
  705.  
  706.   /* Get fonts ready */
  707.  
  708.   cmap = gdk_colormap_get_system();
  709.   red.red = 0xffff;
  710.   red.green = 0;
  711.   red.blue = 0;    
  712.   if (!gdk_color_alloc(cmap, &red)) {
  713.     g_error("couldn't allocate red");
  714.   }
  715.   
  716.   blue.red = 0;
  717.   blue.green = 0;
  718.   blue.blue = 0xffff;    
  719.   if (!gdk_color_alloc(cmap, &blue)) {
  720.     g_error("couldn't allocate blue");
  721.   }
  722.   
  723.   green.red = 0x0000;
  724.   green.green = 0xffff;
  725.   green.blue = 0x0000;    
  726.   if (!gdk_color_alloc(cmap, &green)) {
  727.     g_error("couldn't allocate green");
  728.   }  
  729.   
  730.   
  731.   fixed = gdk_fontset_load ("-misc-fixed-medium-r-*-*-*-120-*-*-*-*-*-*");
  732.   bold = gdk_fontset_load("-misc-fixed-bold-r-normal-*-*-120-*-*-*-*-*-*");
  733.  
  734.   while(pipes[0] != -1 && (count = read(pipes[0], buf, sizeof(buf)-1))) {
  735.     /*    fprintf(stderr, "Count was %d\n", count); */
  736.     buf[count] = '\0';
  737.     if((strcmp(buf, buf2)) == 0) {
  738.       return(1);
  739.     } else {
  740.       if(view_type == 1){
  741.     str = buf;
  742.     newstr = strtok(str, " ");
  743.     if(newstr) gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, newstr, -1); 
  744.     gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  745.     do{
  746.        tmpstr = newstr;
  747.       newstr = strtok(NULL, " ");
  748.       if(tmpstr) tmpstr += strlen(tmpstr)+1; /* position on the start of next token */
  749.       while(tmpstr && (tmpstr++)[0] == 0x20) /* print the leading spaces */
  750.         gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  751.       
  752.       if(newstr != NULL){
  753.         /********* CATCH STUFF ****************************/
  754.         if(newstr[0] == '('){
  755.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, newstr, -1); 
  756.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  757.         }else if(strstr(newstr, "http://")){
  758.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  759.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  760.         }else if(strstr(newstr, "fingerprint")){
  761.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  762.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  763.           /********* BEGIN PORT COLOR CODING ****************/
  764.         }else if(strstr(newstr, "sftp")){
  765.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  766.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  767.         }else if(strstr(newstr, "mftp")){
  768.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  769.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  770.         }else if(strstr(newstr, "bftp")){
  771.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  772.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  773.         }else if(strstr(newstr, "NetBus")){
  774.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  775.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  776.         }else if(strstr(newstr, "kshell")){
  777.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  778.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  779.         }else if(strstr(newstr, "klogin")){
  780.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  781.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  782.         }else if(strstr(newstr, "rtelnet")){
  783.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  784.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  785.         }else if(strstr(newstr, "telnet")){
  786.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  787.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  788.         }else if(strstr(newstr, "X11")){
  789.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  790.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  791.         }else if(strstr(newstr, "tftp")){
  792.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  793.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  794.         }else if(strstr(newstr, "login")){
  795.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  796.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  797.         }else if(strstr(newstr, "imap2")){
  798.           gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, newstr, -1);
  799.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  800.         }else if(strstr(newstr, "ftp")){
  801.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  802.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  803.         }else if(strstr(newstr, "pop-3")){
  804.           gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, newstr, -1);
  805.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  806.         }else if(strstr(newstr, "exec")){
  807.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  808.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  809.         }else if(strstr(newstr, "imap3")){
  810.           gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, newstr, -1);
  811.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);                    
  812.         }else if(strstr(newstr, "smtps")){
  813.           gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, newstr, -1);
  814.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);            
  815.         }else if(strstr(newstr, "smtp")){
  816.           gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, newstr, -1);
  817.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  818.         }else if(strstr(newstr, "pop-2")){
  819.           gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, newstr, -1);
  820.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  821.         }else if(strstr(newstr, "systat")){
  822.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  823.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  824.         }else if(strstr(newstr, "netstat")){
  825.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  826.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  827.         }else if(strstr(newstr, "cfingerd")){
  828.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  829.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  830.         }else if(strstr(newstr, "finger")){
  831.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  832.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  833.         }else if(strstr(newstr, "netbios")){
  834.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  835.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  836.         }else if(strstr(newstr, "X11")){
  837.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  838.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  839.         }else if(strstr(newstr, "nfs")){
  840.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  841.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  842.         }else if(strstr(newstr, "sunrpc")){
  843.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  844.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  845.         }else if(strstr(newstr, "https")){
  846.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  847.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  848.         }else if(strstr(newstr, "kpasswds")){
  849.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  850.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);                    
  851.         }else if(strstr(newstr, "http")){
  852.           gtk_text_insert(GTK_TEXT(MW->output), bold, NULL, NULL, newstr, -1);
  853.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  854.         }else if(strstr(newstr, "ssh")){
  855.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  856.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  857.         }else if(strstr(newstr, "shell")){
  858.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  859.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  860.         }else if(strstr(newstr, "linuxconf")){
  861.           gtk_text_insert(GTK_TEXT(MW->output), bold, &red, NULL, newstr, -1);
  862.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);    
  863.           
  864.                 /******* END PORT COLOR CODING, BEGIN OS COLORS *****************/        
  865.         }else if(strstr(newstr, "Linux")){
  866.           gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, newstr, -1);
  867.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  868.         }else if(strstr(newstr, "FreeBSD")){
  869.           gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, newstr, -1);
  870.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  871.         }else if(strstr(newstr, "Win")){
  872.           gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, newstr, -1);
  873.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  874.         }else if(strstr(newstr, "MacOS")){
  875.           gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, newstr, -1);
  876.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  877.         }else if(strstr(newstr, "OpenBSD")){
  878.           gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, newstr, -1);
  879.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  880.         }else if(strstr(newstr, "IRIX")){
  881.           gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, newstr, -1);
  882.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  883.         }else if(strstr(newstr, "Windows")){
  884.           gtk_text_insert(GTK_TEXT(MW->output), bold, &blue, NULL, newstr, -1);
  885.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  886.           
  887.         }else{ 
  888.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, newstr, -1); 
  889.           gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, " ", -1);
  890.         }
  891.       }
  892.     }while(newstr);
  893.       } /* END VIEW_TYPE == 1 IF */
  894.         
  895.       if(view_type == 0){
  896.     gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, buf, -1);
  897.       }
  898.       /* END VIEW_TYPE == 0 IF */
  899.          
  900.       if(view_type == 2) {
  901.     build_tree(buf);
  902.       }
  903.       strcpy(buf2, buf);
  904.         
  905.     } /*end if*/
  906.   } 
  907.   /*  fprintf(stderr, "Below loop: Count was %d\n", count); */
  908.   if (!nmap_pid || (waitpid(0, NULL, WNOHANG) == nmap_pid)) {
  909.     /*    fprintf(stderr, "Program gone, dead, kablooey!\n"); */
  910.     nmap_pid = 0;
  911.     gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(MW->start_scan), 0);
  912.     return 0;
  913.   }
  914.   return(1);    
  915. }
  916.  
  917. void stop_scan()
  918. {
  919.   /*  fprintf(stderr, "stop scan called -- pid == %d\n", nmap_pid); */
  920.   if (nmap_pid)
  921.     kill(nmap_pid, 9);
  922.   nmap_pid = 0;
  923.   if (pipes[0] != -1) {
  924.     close(pipes[0]);
  925.     pipes[0] = -1;
  926.   }
  927.     
  928. }
  929.  
  930. void
  931. on_verb_activate            (GtkMenuItem    *menuitem,
  932.                      gpointer    user_data)
  933. {
  934.   if(verb){
  935.     verb = 0;
  936.   } else {
  937.     verb = 1;
  938.   }
  939.   display_nmap_command();
  940. }
  941.  
  942. void
  943. on_Append_activate            (GtkMenuItem    *menuitem,
  944.                      gpointer    user_data)
  945. {
  946.   if(append){
  947.     append = 0;
  948.   } else {
  949.     append = 1;
  950.   }    
  951. }
  952.  
  953. void
  954. on_rpc_activate            (GtkMenuItem    *menuitem,
  955.                  gpointer    user_data)
  956. {
  957.   if(rpc_var){
  958.     rpc_var = 0;
  959.   } else {
  960.     rpc_var = 1;
  961.   }    
  962.   display_nmap_command();
  963. }
  964.  
  965. void on_Trad_activate    (GtkMenuItem *menuitem, GtkWidget *trad)
  966. {
  967.   view_type = 0;
  968. }
  969.  
  970. void on_CTrad_activate    (GtkMenuItem *menuitem, GtkWidget *ctrad)
  971. {
  972.   view_type = 1;
  973. }
  974.  
  975. void on_Tree_activate    (GtkMenuItem *menuitem, GtkWidget *tree)
  976. {
  977.   view_type = 2;
  978. }
  979.  
  980. void build_tree(char *buf)
  981. {
  982.   /******************************* THIS IS BROKE RIGHT NOW :) *************************
  983.                    char *str, *token;
  984.                    GdkFont *fixed;
  985.                    fixed = gdk_fontset_load ("-misc-fixed-medium-r-*-*-*-120-*-*-*-*-*-*");
  986.     
  987.                    str = buf;
  988.                    token = strtok(str, " ");
  989.     
  990.                    do{
  991.                    token = strtok(NULL, " ");
  992.     
  993.                    if(strstr(token, "Service")){
  994.                    printf("Wh00p!");
  995.                    token = strtok(NULL, " \t");
  996.                    printf("%s", token);        
  997.                    token = strtok(NULL, " \t");
  998.                    printf("%s", token);
  999.                    printf("That's three\n");
  1000.                    }
  1001.         
  1002.                    gtk_text_freeze(GTK_TEXT(MW->output));
  1003.                    gtk_text_insert(GTK_TEXT(MW->output), fixed, NULL, NULL, "hello", -1);
  1004.         
  1005.                    }while(token);
  1006.     
  1007.                    gtk_text_thaw(GTK_TEXT(MW->output));
  1008.   *****************************************************************************************/
  1009. }
  1010.  
  1011. void on_done_clicked(GtkButton *button, GtkWidget *widget)
  1012. {
  1013.   MW->machine_file = gtk_entry_get_text(GTK_ENTRY(MW->file_entry));
  1014.   machine_yn = 1;
  1015.   gtk_widget_hide(widget);
  1016.   display_nmap_command();
  1017. }
  1018.  
  1019. void on_cancel_clicked(GtkButton *button, GtkWidget *widget)
  1020. {
  1021.   machine_yn = 0;
  1022.   gtk_widget_hide(widget);
  1023. }
  1024.  
  1025. void on_machine_activate()
  1026. {     
  1027.   GtkWidget *save_file;
  1028.   save_file = create_machine_parse_selection();
  1029.   gtk_widget_show(save_file);
  1030. }
  1031.  
  1032. void on_help_ok_clicked(GtkButton *button, GtkWidget    *help)
  1033. {
  1034.   gtk_widget_destroy(help);
  1035. }
  1036. /***************************************************************/
  1037.  
  1038. int Strncpy(char *dest, const char *src, size_t n) {
  1039.   strncpy(dest, src, n);
  1040.   if (dest[n-1] == '\0')
  1041.     return 0;
  1042.   dest[n-1] = '\0';
  1043.   return -1;
  1044. }
  1045.  
  1046. /* This function takes a command and the address of an uninitialized
  1047.    char ** .  It parses the command (by seperating out whitespace)
  1048.    into an argv[] style char **, which it sets the argv parameter to.
  1049.    The function returns the number of items filled up in the array
  1050.    (argc), or -1 in the case of an error.  This function allocates
  1051.    memmory for argv and thus it must be freed -- use argv_parse_free()
  1052.    for that.  If arg_parse returns <1, then argv does not need to be freed.
  1053.    The returned arrays are always terminated with a NULL pointer */
  1054. int arg_parse(const char *command, char ***argv) {
  1055.   char **myargv = NULL;
  1056.   int argc = 0;
  1057.   char mycommand[4096];
  1058.   unsigned char *start, *end;
  1059.   char oldend;
  1060.  
  1061.   *argv = NULL;
  1062.   if (Strncpy(mycommand, command, 4096) == -1) {      
  1063.     return -1;
  1064.   }
  1065.   myargv = malloc((MAX_PARSE_ARGS + 2) * sizeof(char *));
  1066.   bzero(myargv, (MAX_PARSE_ARGS+2) * sizeof(char *));
  1067.   myargv[0] = (char *) 0x123456; /* Integrity checker */
  1068.   myargv++;
  1069.   start = mycommand;
  1070.   while(start && *start) {
  1071.     while(*start && isspace(*start))
  1072.       start++;
  1073.     if (*start == '"') {
  1074.       start++;
  1075.       end = strchr(start, '"');
  1076.     } else if (*start == '\'') {
  1077.       start++;
  1078.       end = strchr(start, '\'');      
  1079.     } else if (!*start) {
  1080.       continue;
  1081.     } else {
  1082.       end = start+1;
  1083.       while(*end && !isspace(*end)) {      
  1084.     end++;
  1085.       }
  1086.     }
  1087.     if (!end) {
  1088.       arg_parse_free(myargv);
  1089.       return -1;
  1090.     }
  1091.     if (argc >= MAX_PARSE_ARGS) {
  1092.       arg_parse_free(myargv);
  1093.       return -1;
  1094.     }
  1095.     oldend = *end;
  1096.     *end = '\0';
  1097.     myargv[argc++] = strdup(start);
  1098.     if (oldend)
  1099.       start = end + 1;
  1100.     else start = end;
  1101.   }
  1102.   myargv[argc+1] = 0;
  1103.   *argv = myargv;
  1104.   return argc;
  1105. }
  1106.  
  1107. /* Free an argv allocated inside arg_parse */
  1108. void arg_parse_free(char **argv) {
  1109.   char **current;
  1110.   /* Integrity check */
  1111.   argv--;
  1112.   assert(argv[0] == (char *) 0x123456);
  1113.   current = argv + 1;
  1114.   while(*current) {
  1115.     free(*current);
  1116.     current++;
  1117.   }
  1118.   free(argv);
  1119. }
  1120.  
  1121.  
  1122.  
  1123. #endif /* MISSING_GTK */
  1124.