/[lwip]/lwip/proj/unixsim/apps/shell.c
ViewVC logotype

Diff of /lwip/proj/unixsim/apps/shell.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by likewise, Sat Oct 19 13:00:00 2002 UTC revision 1.2 by adamdunkels, Wed Oct 23 20:12:18 2002 UTC
# Line 48  struct command { Line 48  struct command {
48    char *args[10];    char *args[10];
49  };  };
50    
51    /* Following #undefs are here to keep compiler from issuing warnings
52       about them being double defined. (They are defined in lwip/inet.h
53       as well as the Unix #includes below.) */
54    #undef htonl
55    #undef ntohl
56    #undef htons
57    #undef ntohs
58    #undef HTONL
59    #undef NTOHL
60    #undef HTONS
61    #undef NTOHS
62    #undef IP_HDRINCL
63    
64  #include <stdio.h>  #include <stdio.h>
65  #include <errno.h>  #include <errno.h>
66    #include <sys/types.h>
67    #include <sys/socket.h>
68    #include <netinet/in.h>
69    #include <arpa/inet.h>
70    #include <stdlib.h>
71    #include <limits.h>
72    
73  #define ESUCCESS 0  #define ESUCCESS 0
74  #define ESYNTAX -1  #define ESYNTAX -1
# Line 225  com_open(struct command *com) Line 244  com_open(struct command *com)
244    int i;    int i;
245    err_t err;    err_t err;
246    
247    if(inet_aton(com->args[0], &ipaddr) == -1) {    if(inet_aton(com->args[0], (struct in_addr *)&ipaddr) == -1) {
248      sendstr(strerror(errno), com->conn);      sendstr(strerror(errno), com->conn);
249      return ESYNTAX;      return ESYNTAX;
250    }    }
# Line 266  com_open(struct command *com) Line 285  com_open(struct command *com)
285    }    }
286    
287    sendstr("Opened connection, connection identifier is ", com->conn);    sendstr("Opened connection, connection identifier is ", com->conn);
288    sprintf(buffer, "%d\n", i);    sprintf((char *)buffer, "%d\n", i);
289    netconn_write(com->conn, buffer, strlen(buffer), NETCONN_COPY);    netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
290        
291    return ESUCCESS;    return ESUCCESS;
292  }  }
# Line 328  com_lstn(struct command *com) Line 347  com_lstn(struct command *com)
347    }    }
348    
349    sendstr("Opened connection, connection identifier is ", com->conn);    sendstr("Opened connection, connection identifier is ", com->conn);
350    sprintf(buffer, "%d\n", i);    sprintf((char *)buffer, "%d\n", i);
351    netconn_write(com->conn, buffer, strlen(buffer), NETCONN_COPY);    netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
352        
353    return ESUCCESS;    return ESUCCESS;
354  }  }
# Line 408  com_acpt(struct command *com) Line 427  com_acpt(struct command *com)
427    }    }
428    
429    sendstr("Accepted connection, connection identifier for new connection is ", com->conn);    sendstr("Accepted connection, connection identifier for new connection is ", com->conn);
430    sprintf(buffer, "%d\n", j);    sprintf((char *)buffer, "%d\n", j);
431    netconn_write(com->conn, buffer, strlen(buffer), NETCONN_COPY);    netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
432    
433    return ESUCCESS;    return ESUCCESS;
434  }  }
# Line 526  com_udpc(struct command *com) Line 545  com_udpc(struct command *com)
545    err_t err;    err_t err;
546    
547    lport = strtol(com->args[0], NULL, 10);    lport = strtol(com->args[0], NULL, 10);
548    if(inet_aton(com->args[1], &ipaddr) == -1) {    if(inet_aton(com->args[1], (struct in_addr *)&ipaddr) == -1) {
549      sendstr(strerror(errno), com->conn);      sendstr(strerror(errno), com->conn);
550      return ESYNTAX;      return ESYNTAX;
551    }    }
# Line 583  com_udpc(struct command *com) Line 602  com_udpc(struct command *com)
602    }    }
603    
604    sendstr("Connection set up, connection identifier is ", com->conn);    sendstr("Connection set up, connection identifier is ", com->conn);
605    sprintf(buffer, "%d\n", i);    sprintf((char *)buffer, "%d\n", i);
606    netconn_write(com->conn, buffer, strlen(buffer), NETCONN_COPY);    netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
607        
608    return ESUCCESS;    return ESUCCESS;
609  }  }
# Line 598  com_udpl(struct command *com) Line 617  com_udpl(struct command *com)
617    err_t err;    err_t err;
618    
619    lport = strtol(com->args[0], NULL, 10);    lport = strtol(com->args[0], NULL, 10);
620    if(inet_aton(com->args[1], &ipaddr) == -1) {    if(inet_aton(com->args[1], (struct in_addr *)&ipaddr) == -1) {
621      sendstr(strerror(errno), com->conn);      sendstr(strerror(errno), com->conn);
622      return ESYNTAX;      return ESYNTAX;
623    }    }
# Line 655  com_udpl(struct command *com) Line 674  com_udpl(struct command *com)
674    }    }
675    
676    sendstr("Connection set up, connection identifier is ", com->conn);    sendstr("Connection set up, connection identifier is ", com->conn);
677    sprintf(buffer, "%d\n", i);    sprintf((char *)buffer, "%d\n", i);
678    netconn_write(com->conn, buffer, strlen(buffer), NETCONN_COPY);    netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
679        
680    return ESUCCESS;    return ESUCCESS;
681  }  }
# Line 670  com_udpn(struct command *com) Line 689  com_udpn(struct command *com)
689    err_t err;    err_t err;
690    
691    lport = strtol(com->args[0], NULL, 10);    lport = strtol(com->args[0], NULL, 10);
692    if(inet_aton(com->args[1], &ipaddr) == -1) {    if(inet_aton(com->args[1], (struct in_addr *)&ipaddr) == -1) {
693      sendstr(strerror(errno), com->conn);      sendstr(strerror(errno), com->conn);
694      return ESYNTAX;      return ESYNTAX;
695    }    }
# Line 727  com_udpn(struct command *com) Line 746  com_udpn(struct command *com)
746    }    }
747    
748    sendstr("Connection set up, connection identifier is ", com->conn);    sendstr("Connection set up, connection identifier is ", com->conn);
749    sprintf(buffer, "%d\n", i);    sprintf((char *)buffer, "%d\n", i);
750    netconn_write(com->conn, buffer, strlen(buffer), NETCONN_COPY);    netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
751        
752    return ESUCCESS;    return ESUCCESS;
753  }  }
# Line 743  com_udpb(struct command *com) Line 762  com_udpb(struct command *com)
762    struct ip_addr bcaddr;    struct ip_addr bcaddr;
763    
764    lport = strtol(com->args[0], NULL, 10);    lport = strtol(com->args[0], NULL, 10);
765    if(inet_aton(com->args[1], &ipaddr) == -1) {    if(inet_aton(com->args[1], (struct in_addr *)&ipaddr) == -1) {
766      sendstr(strerror(errno), com->conn);      sendstr(strerror(errno), com->conn);
767      return ESYNTAX;      return ESYNTAX;
768    }    }
# Line 799  com_udpb(struct command *com) Line 818  com_udpb(struct command *com)
818    }    }
819    
820    sendstr("Connection set up, connection identifier is ", com->conn);    sendstr("Connection set up, connection identifier is ", com->conn);
821    sprintf(buffer, "%d\n", i);    sprintf((char *)buffer, "%d\n", i);
822    netconn_write(com->conn, buffer, strlen(buffer), NETCONN_COPY);    netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
823        
824    return ESUCCESS;    return ESUCCESS;
825  }  }
# Line 862  parse_command(struct command *com, u32_t Line 881  parse_command(struct command *com, u32_t
881    u16_t i;    u16_t i;
882    u16_t bufp;    u16_t bufp;
883        
884    if(strncmp(buffer, "open", 4) == 0) {    if(strncmp((const char *)buffer, "open", 4) == 0) {
885      com->exec = com_open;      com->exec = com_open;
886      com->nargs = 2;      com->nargs = 2;
887    } else if(strncmp(buffer, "lstn", 4) == 0) {    } else if(strncmp((const char *)buffer, "lstn", 4) == 0) {
888      com->exec = com_lstn;      com->exec = com_lstn;
889      com->nargs = 1;      com->nargs = 1;
890    } else if(strncmp(buffer, "acpt", 4) == 0) {    } else if(strncmp((const char *)buffer, "acpt", 4) == 0) {
891      com->exec = com_acpt;      com->exec = com_acpt;
892      com->nargs = 1;      com->nargs = 1;
893    } else if(strncmp(buffer, "clos", 4) == 0) {    } else if(strncmp((const char *)buffer, "clos", 4) == 0) {
894      com->exec = com_clos;      com->exec = com_clos;
895      com->nargs = 1;      com->nargs = 1;
896    } else if(strncmp(buffer, "stat", 4) == 0) {    } else if(strncmp((const char *)buffer, "stat", 4) == 0) {
897      com->exec = com_stat;      com->exec = com_stat;
898      com->nargs = 0;      com->nargs = 0;
899    } else if(strncmp(buffer, "send", 4) == 0) {    } else if(strncmp((const char *)buffer, "send", 4) == 0) {
900      com->exec = com_send;      com->exec = com_send;
901      com->nargs = 2;      com->nargs = 2;
902    } else if(strncmp(buffer, "recv", 4) == 0) {    } else if(strncmp((const char *)buffer, "recv", 4) == 0) {
903      com->exec = com_recv;      com->exec = com_recv;
904      com->nargs = 1;      com->nargs = 1;
905    } else if(strncmp(buffer, "udpc", 4) == 0) {    } else if(strncmp((const char *)buffer, "udpc", 4) == 0) {
906      com->exec = com_udpc;      com->exec = com_udpc;
907      com->nargs = 3;      com->nargs = 3;
908    } else if(strncmp(buffer, "udpb", 4) == 0) {    } else if(strncmp((const char *)buffer, "udpb", 4) == 0) {
909      com->exec = com_udpb;      com->exec = com_udpb;
910      com->nargs = 2;      com->nargs = 2;
911    } else if(strncmp(buffer, "udpl", 4) == 0) {    } else if(strncmp((const char *)buffer, "udpl", 4) == 0) {
912      com->exec = com_udpl;      com->exec = com_udpl;
913      com->nargs = 3;      com->nargs = 3;
914    } else if(strncmp(buffer, "udpn", 4) == 0) {    } else if(strncmp((const char *)buffer, "udpn", 4) == 0) {
915      com->exec = com_udpn;      com->exec = com_udpn;
916      com->nargs = 3;      com->nargs = 3;
917    } else if(strncmp(buffer, "usnd", 4) == 0) {    } else if(strncmp((const char *)buffer, "usnd", 4) == 0) {
918      com->exec = com_usnd;      com->exec = com_usnd;
919      com->nargs = 2;      com->nargs = 2;
920    } else if(strncmp(buffer, "help", 4) == 0) {    } else if(strncmp((const char *)buffer, "help", 4) == 0) {
921      com->exec = com_help;      com->exec = com_help;
922      com->nargs = 0;      com->nargs = 0;
923    } else if(strncmp(buffer, "quit", 4) == 0) {    } else if(strncmp((const char *)buffer, "quit", 4) == 0) {
924      printf("quit\n");      printf("quit\n");
925      return ECLOSED;      return ECLOSED;
926    } else {    } else {
# Line 929  parse_command(struct command *com, u32_t Line 948  parse_command(struct command *com, u32_t
948      if(bufp > len) {      if(bufp > len) {
949        return ETOOFEW;        return ETOOFEW;
950      }          }    
951      com->args[i] = &buffer[bufp];      com->args[i] = (char *)&buffer[bufp];
952      for(; bufp < len && buffer[bufp] != ' ' && buffer[bufp] != '\r' &&      for(; bufp < len && buffer[bufp] != ' ' && buffer[bufp] != '\r' &&
953            buffer[bufp] != '\n'; bufp++) {            buffer[bufp] != '\n'; bufp++) {
954        if(buffer[bufp] == '\\') {        if(buffer[bufp] == '\\') {

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26