Esempio n. 1
0
static int
sender(int *arg)
{
    int len = BUFFER_SIZE;
    char buffer[BUFFER_SIZE];

    while (1) {
        len = miniterm_read(buffer, BUFFER_SIZE - 1);
        minisocket_send(connection, buffer, len + 1, &error);
    }

    return 0;
}
Esempio n. 2
0
int
transmit(int* arg) {
    char buffer[BUFFER_SIZE];
    int length;
    network_address_t addr;
    miniport_t port;
    miniport_t dest;

    AbortOnCondition(network_translate_hostname(hostname, addr) < 0,
                     "Could not resolve hostname, exiting.");

    port = miniport_create_unbound(42);
    dest = miniport_create_bound(addr, 42);

    minithread_fork(receive, NULL);

    while(1){
      memset(buffer, 0, BUFFER_SIZE);
      length = miniterm_read(buffer, BUFFER_SIZE);
      minimsg_send(port, dest, buffer, length);
    }

    return 0;
}
Esempio n. 3
0
int shell(int *g)
{
    char command[BUFFER_SIZE];
    char func[BUFFER_SIZE],arg1[BUFFER_SIZE],arg2[BUFFER_SIZE];
    int i;

    minifile_cd("/"); //cd to root (will also initialize the system if necessary)
    printf("%s\n", IDstring);

    while(1) {
        memset(command,'\0',BUFFER_SIZE);
        memset(func,'\0',BUFFER_SIZE);
        memset(arg1,'\0',BUFFER_SIZE);
        memset(arg2,'\0',BUFFER_SIZE);
        put_prompt();
        //gets(command);
        miniterm_read(command, BUFFER_SIZE);
        //extract first three strings in command (delimited by spaces)
        sscanf(command,"%s %s %s",func,arg1,arg2);
        if(strcmp(func,"help") == 0)
            help_screen();
        else if(strcmp(func,"cd") == 0)
            minifile_cd(arg1);
        else if(strcmp(func,"ls") == 0 || strcmp(func,"dir") == 0) {
            char **files = minifile_ls(arg1);
            printf("File listing for %s\n", arg1);
            for(i = 0; files != NULL && files[i] != NULL; ++i) {
                printf("\t%s\n",files[i]);
                free(files[i]);
            }
            free(files);
        } else if(strcmp(func,"pwd") == 0)
            printf("%s\n", minifile_pwd());
        else if(strcmp(func,"mkdir") == 0)
            minifile_mkdir(arg1);
        else if(strcmp(func,"rmdir") == 0)
            minifile_rmdir(arg1);
        else if(strcmp(func,"rm") == 0 || strcmp(func,"del") == 0)
            minifile_unlink(arg1);
        else if(strcmp(func,"import") == 0)
            importfile(arg1,arg2);
        else if(strcmp(func,"export") == 0)
            exportfile(arg1,arg2);
        else if(strcmp(func,"type") == 0)
            typefile(arg1);
        else if(strcmp(func,"input") == 0)
            inputfile(arg1);
        else if(strcmp(func,"cp") == 0 || strcmp(func,"copy") == 0)
            copy(arg1,arg2);
        else if(strcmp(func,"mv") == 0 || strcmp(func,"move") == 0)
            move(arg1,arg2);
        else if(strcmp(func,"whoami") == 0)
            printf("You are minithread %d, running our shell\n",minithread_id());
        else if(strcmp(func,"exit") == 0)
            break;
        else if(strcmp(func,"doscmd") == 0)
            system(command+7);
        else if(strcmp(func,"exec") == 0) { //this is not efficient -- just for fun!!!
            char cmdline[BUFFER_SIZE];
            memset(cmdline,'\0',BUFFER_SIZE);
            strcpy(cmdline,"tmp0000~.exe ");
            strcpy(cmdline+13,command+5+strlen(arg1));
            exportfile(arg1,"tmp0000~.exe");
            system(cmdline);
            system("rm tmp0000~.exe");
        } else printf("%s: Command not found\n",func);
    }
    printf("Good-bye :-)\n");
    return 0;
}