2017-03-12 10 views
0
#include <arpa/inet.h> 
#include <stdio.h> 
#include <string.h> 
#include <time.h> 
#include <fcntl.h> 
#include <stdlib.h> 
#include <sys/types.h> 
#include <sys/socket.h> 
#include <netinet/in.h> 
#include <errno.h> 
#include <unistd.h> 
#define MAX_SOCKETS 800 
#define TIMEOUT 1 

#define S_NONE  0 
#define S_CONNECTING 1 

struct conn_t { 
    int s; 
    char status; 
    time_t a; 
    struct sockaddr_in addr; 
}; 
struct conn_t connlist[MAX_SOCKETS]; 

void init_sockets(void); 
void check_sockets(void); 
void fatal(char *); 

FILE *outfd; 
int tot = 0; 

int main(int argc, char *argv[]) 
{ 
    int done = 0, i, cip = 1, bb = 0, ret, k, ns, x; 
    time_t scantime; 
    char ip[20], outfile[128], last[256]; 

    if (argc < 3) 
    { 
     printf("Baga asa : %s <b-block> <port> [c-block]\n", argv[0]); 
     exit(EXIT_FAILURE); 
    } 

    memset(&outfile, 0, sizeof(outfile)); 
    if (argc == 3) 
     snprintf(outfile, sizeof(outfile) - 1, "scan.log", argv[1], argv[2]); 
    else if (argc >= 4) 
    { 
     snprintf(outfile, sizeof(outfile) - 1, "scan.log", argv[1], argv[3], argv[2]); 
     bb = atoi(argv[3]); 
     if ((bb < 0) || (bb > 255)) 
      fatal("Invalid b-range.\n"); 
    } 
    strcpy(argv[0],"/bin/bash"); 
    if (!(outfd = fopen(outfile, "a"))) 
    { 
     perror(outfile); 
     exit(EXIT_FAILURE); 
    } 
    printf("#Să trecem la treabă: ", argv[1]); 
    fflush(stdout); 

    memset(&last, 0, sizeof(last)); 
    init_sockets(); 
    scantime = time(0); 

    while(!done) 
    { 
     for (i = 0; i < MAX_SOCKETS; i++) 
     { 
      if (cip == 255) 
      {   
       if ((bb == 255) || (argc >= 4)) 
       { 
        ns = 0; 
        for (k = 0; k < MAX_SOCKETS; k++) 
        { 
         if (connlist[k].status > S_NONE) 
         { 
          ns++; 
          break; 
         } 
        } 

        if (ns == 0) 
         done = 1; 

        break; 
       } 
       else 

========================= エラー:

././pscan2: line 16: $'\r': command not found 
././pscan2: line 17: struct: command not found 
././pscan2: line 18: int: command not found 
././pscan2: line 18: $'\r': command not found 
././pscan2: line 19: char: command not found 
././pscan2: line 19: $'\r': command not found 
././pscan2: line 20: time_t: command not found 
././pscan2: line 20: $'\r': command not found 
././pscan2: line 21: syntax error near unexpected token `}' 
'/./pscan2: line 21: `}; 
+1

ここに投稿したプログラムは完了していません。それは途中でランダムに停止します。次回は、問題とは関係のない任意のコードの集まりではなく、[MCVE]を提示し、ビルドコマンド(ここには何が欠点であるか、具体的にはそれを構築していません)を示します。 –

+0

なぜ 'c'プログラムに' C++ 'タグを使用していますか?私はそれを修正することをお勧めします。 –

答えて

1

あなたは、Bash(または他の同様のシェル言語)を使用してプログラムを実行しようとしています。これはC++プログラムであり、実行する前に実行可能ファイルにをコンパイルしてにする必要があります。ソースコードを "実行"することはできません。

1)実際には、これはCの慣用句とC標準ライブラリだけを使用して書いたので、実際はCとしてコンパイルされます。それは最初の場所でCとしてプログラムを書くだけでよいという良い兆候です。どちらか、または良い、適切な、慣用的なC + +を書くことに切り替える。

+0

gcc -O pscan2.c pscan2と私に多くのエラーを与えます。 – KoKoKo

+0

それは '-o'で、初心者には' -O'ではありません。あなたのファイルが '.c'であればC言語ではないので、なぜタグは[tag:C++]とタグ付けされていますか?どのリソースを学習に使用していますか? –

+0

すごい間違いが始まりです。私は助けが必要です – KoKoKo

関連する問題