コード例 #1
0
ファイル: lhtran.c プロジェクト: zzuse/cplusSnip
//************************************************************************************
//
// function main
//
//************************************************************************************
int main(int argc, char* argv[])
{
    char **p;
    char sConnectHost[HOSTLEN], sTransmitHost[HOSTLEN];
    int iConnectPort=0, iTransmitPort=0;
    char *logfile=NULL;
//    ver();
    memset(sConnectHost, 0, HOSTLEN);
    memset(sTransmitHost, 0, HOSTLEN);
    p=argv;
    while(*p)
    {
          if(strstr(*p, "-log") !=NULL)
          {
                if(testifisvalue(*(p+1)))
                {
                      logfile = *(++p);
                }
                else
                {
                      printf("[-] ERROR: Must supply logfile name.\r\n");
                      return;
                }
                p++;
                continue;
          }

          p++;
    }
    if(logfile !=NULL)
    {
          fp=fopen(logfile,"a");
          if(fp == NULL )
          {
                printf("[-] ERROR: open logfile");
                return;
          }
          makelog("====== Start ======\r\n", 22);
    }

    if(argc > 2)
    {
   if(!strcmp(argv[1], "-listen") && argc >=4)
          {
                iConnectPort = atoi(argv[2]);
                iTransmitPort = atoi(argv[3]);
                method = 1;
          }
          else

          if(!strcmp(argv[1], "-tran") && argc >= 5)
          {
                iConnectPort = atoi(argv[2]);
                strncpy(sTransmitHost, argv[3], HOSTLEN);
                iTransmitPort = atoi(argv[4]);
                method = 2;
          }
          else
          if(!strcmp(argv[1], "-slave") && argc >= 6)
          {
                strncpy(sConnectHost, argv[2], HOSTLEN);
                iConnectPort = atoi(argv[3]);
                strncpy(sTransmitHost, argv[4], HOSTLEN);
                iTransmitPort = atoi(argv[5]);
                method = 3;
          }
    }
    switch(method)
    {
    case 1:
          bind2bind(iConnectPort, iTransmitPort);
          break;
    case 2:
          bind2conn(iConnectPort, sTransmitHost, iTransmitPort);
          break;
    case 3:
          conn2conn(sConnectHost, iConnectPort, sTransmitHost, iTransmitPort);
          break;
    default:
          usage(argv[0]);
          break;
    }

    if(method)
    {
          closeallfd();
    }
    return 0;
}
コード例 #2
0
ファイル: HTran.cpp プロジェクト: bGN4/HTran
/*************************************************************************************
*                                                                                    *
* function main                                                                      *
*                                                                                    *
*************************************************************************************/
int main(int argc, char* argv[]) {
    char **p;
    char sConnectHost[HOSTLEN], sTransmitHost[HOSTLEN];
    int  iConnectPort = 0, iTransmitPort = 0;
    char *logfile = NULL;

    ver();
    memset(sConnectHost, 0, HOSTLEN);
    memset(sTransmitHost, 0, HOSTLEN);

    p = argv;
    while (*p) {
        if (stricmp(*p, "-log") == 0) {
            if (testifisvalue(*(p + 1))) {
                logfile = *(++p);
            } else {
                printf("[-] ERROR: Must supply logfile name.\n\n");
                return 0;
            }
            p++;
            continue;
        }
        p++;
    }
    if (logfile != NULL) {
        if (NULL == (fp = fopen(logfile, "a"))) {
            printf("[-] ERROR: open logfile");
            return 0;
        }
        char s[] = "====== Start ======\r\n";
        makelog(s, sizeof(s) / sizeof(char));
    }

#ifdef WIN32
    // Win Start Winsock.
    WSADATA wsadata;
    WSAStartup(MAKEWORD(1, 1), &wsadata);
#endif //WIN32

    signal(SIGINT, &getctrlc);

    if (argc > 2) {
        if (stricmp(argv[1], "-listen") == 0 && argc >= 4) {
            iConnectPort = atoi(argv[2]);
            iTransmitPort = atoi(argv[3]);
            method = 1;
        } else if (stricmp(argv[1], "-tran") == 0 && argc >= 5) {
            iConnectPort = atoi(argv[2]);
            strncpy(sTransmitHost, argv[3], HOSTLEN);
            iTransmitPort = atoi(argv[4]);
            method = 2;
        } else if (stricmp(argv[1], "-slave") == 0 && argc >= 6) {
            strncpy(sConnectHost, argv[2], HOSTLEN);
            iConnectPort = atoi(argv[3]);
            strncpy(sTransmitHost, argv[4], HOSTLEN);
            iTransmitPort = atoi(argv[5]);
            method = 3;
        }
    }

    switch (method) {
    case 1:
        bind2bind(iConnectPort, iTransmitPort);
        break;
    case 2:
        bind2conn(iConnectPort, sTransmitHost, iTransmitPort);
        break;
    case 3:
        conn2conn(sConnectHost, iConnectPort, sTransmitHost, iTransmitPort);
        break;
    default:
        usage(argv[0]);
        break;
    }

    if (method) {
        closeallfd();
    }

#ifdef WIN32
    WSACleanup();
#endif //WIN32

    return 0;
}
コード例 #3
0
ファイル: trtool.c プロジェクト: neroanelli/trtool
int main(int argc,char **argv)
{
    char **p;
    char host1[HOSTLEN],host2[HOSTLEN];
    int port1=0,port2=0,method=0;
    int length;
    char *logfile=NULL;

    p=argv;
    memset(host1,0,HOSTLEN);
    memset(host2,0,HOSTLEN);
    while(*p)
    {
        if(strcmp(*p,"-v")==0)
        {
            printf("Socket data transport tool.\r\nVersion:%s\r\n",VERSION);
            p++;
            continue;
        }
        if(strcmp(*p,"-h1")==0)
        {
            if(testifisvalue(*(p+1))==1)
            {
                length=(strlen(*(p+1))>HOSTLEN-1)?HOSTLEN-1:strlen(*(p+1));
                strncpy(host1,*(++p),length);
            }
            p++;
            continue;
        }
        if(strcmp(*p,"-h2")==0)
        {
            if(testifisvalue(*(p+1))==1)
            {
                length=(strlen(*(p+1))>HOSTLEN-1)?HOSTLEN-1:strlen(*(p+1));
                strncpy(host2,*(++p),length);
            }
            p++;
            continue;
        }
        if(strcmp(*p,"-p1")==0)
        {
            if(testifisvalue(*(p+1))==1)
                port1=atoi(*(++p));
            p++;
            continue;
        }
        if(strcmp(*p,"-p2")==0)
        {
            if(testifisvalue(*(p+1))==1)
                port2=atoi(*(++p));
            p++;
            continue;
        }
        if(strcmp(*p,"-m")==0)
        {
            if(testifisvalue(*(p+1))==1)
                method=atoi(*(++p));
            p++;
            continue;
        }
        if(strcmp(*p,"-log")==0)
        {
            if(testifisvalue(*(p+1))==1)
                logfile=*(++p);
            else
            {
                printf("[ERROR]:must supply logfile name\r\n");
                exit(0);
            }
            p++;
            continue;
        }
        p++;
    }
    signal(SIGCLD,SIG_IGN);
    signal(SIGINT,&closeallfd);
    if(logfile !=NULL)
    {
        fp=fopen(logfile,"a");
        if(fp == NULL )
        {
            perror("open logfile");
            exit(0);
        }
    }
    makelog("######################## start ################\r\n",49);
    switch(method)
    {
    case 0:
        usage(argv[0]);
        break;
    case 1:
        if((port1==0) || (port2==0))
        {
            printf("[ERROR]:must supply PORT1 and PORT2.\r\n");
            break;
        }
        if(strlen(host2)==0)
        {
            printf("[ERROR]:must supply HOST2.\r\n");
            break;
        }
        bind2conn(port1,host2,port2);
        break;
    case 2:
        if((port1==0) || (port2==0))
        {
            printf("[ERROR]:must supply PORT1 and PORT2.\r\n");
            break;
        }
        bind2bind(port1,port2);
        break;
    case 3:
        if((port1==0) || (port2==0))
        {
            printf("[ERROR]:must supply PORT1 and PORT2.\r\n");
            break;
        }
        if(strlen(host1)==0)
        {
            printf("[ERROR]:must supply HOST1.\r\n");
            break;
        }
        if(strlen(host2)==0)
        {
            printf("[ERROR]:must supply HOST2.\r\n");
            break;
        }
        conn2conn(host1,port1,host2,port2);
        break;
    default:
        usage(argv[0]);
    }
    closeallfd(0);
    return 0;
}