第16行:$'\ r':找不到命令(pscan2.c)

时间:2017-03-12 19:07:41

标签: c++ linux ubuntu

#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 个答案:

答案 0 :(得分:1)

您正在尝试通过Bash(或其他类似的shell语言)运行您的程序。这是一个C ++程序 1 ,在运行它之前必须编译到可执行文件中。你不能跑&#34;你的源代码。

1)实际上,这将编译为C,因为您使用C语言编写而不是C标准库。这是一个好兆头,你应该首先把你的程序写成C.要么就是这样,要么转而写出好的,恰当的,惯用的C ++。

相关问题