- int res;
- fd_set input;
- char line[1024], word[1024], arg[1024];
-
- FD_ZERO(&input);
- FD_SET(0, &input);
- if (conn)
- FD_SET(cs_fileno(conn), &input);
- if ((res = select(20, &input, 0, 0, 0)) < 0)
- {
- perror("select");
- exit(1);
- }
- if (!res)
- continue;
- if (FD_ISSET(0, &input))
- {
- /* quick & dirty way to get a command line. */
- if (!gets(line))
- break;
- if ((res = sscanf(line, "%s %[^;]", word, arg)) <= 0)
- {
- strcpy(word, last_cmd);
- *arg = '\0';
- }
- else if (res == 1)
- *arg = 0;
- strcpy(last_cmd, word);
- for (i = 0; cmd[i].cmd; i++)
- if (!strncmp(cmd[i].cmd, word, strlen(word)))
- {
- res = (*cmd[i].fun)(arg);
- break;
- }
- if (!cmd[i].cmd) /* dump our help-screen */
- {
- printf("Unknown command: %s.\n", word);
- printf("Currently recognized commands:\n");
- for (i = 0; cmd[i].cmd; i++)
- printf(" %s %s\n", cmd[i].cmd, cmd[i].ad);
- res = 1;
- }
- if (res < 2)
- printf(C_PROMPT);
- }
- if (conn && FD_ISSET(cs_fileno(conn), &input))
- {
- do
- {
- if ((res = cs_get(conn, &netbuffer, &netbufferlen)) < 0)
- {
- perror("cs_get");
- exit(1);
- }
- if (!res)
- {
- printf("Target closed connection.\n");
- exit(1);
- }
- odr_reset(in); /* release APDU from last round */
- odr_setbuf(in, netbuffer, res, 0);
- if (!z_APDU(in, &apdu, 0))
- {
- odr_perror(in, "Decoding incoming APDU");
- exit(1);
- }
+ int res;
+ fd_set input;
+ char line[1024], word[1024], arg[1024];
+
+ FD_ZERO(&input);
+ FD_SET(0, &input);
+ if (conn)
+ FD_SET(cs_fileno(conn), &input);
+ if ((res = select(20, &input, 0, 0, 0)) < 0)
+ {
+ perror("select");
+ exit(1);
+ }
+ if (!res)
+ continue;
+ if (FD_ISSET(0, &input))
+ {
+ /* quick & dirty way to get a command line. */
+ if (!gets(line))
+ break;
+ if ((res = sscanf(line, "%s %[^;]", word, arg)) <= 0)
+ {
+ strcpy(word, last_cmd);
+ *arg = '\0';
+ }
+ else if (res == 1)
+ *arg = 0;
+ strcpy(last_cmd, word);
+ for (i = 0; cmd[i].cmd; i++)
+ if (!strncmp(cmd[i].cmd, word, strlen(word)))
+ {
+ res = (*cmd[i].fun)(arg);
+ break;
+ }
+ if (!cmd[i].cmd) /* dump our help-screen */
+ {
+ printf("Unknown command: %s.\n", word);
+ printf("Currently recognized commands:\n");
+ for (i = 0; cmd[i].cmd; i++)
+ printf(" %s %s\n", cmd[i].cmd, cmd[i].ad);
+ res = 1;
+ }
+ if (res < 2)
+ printf(C_PROMPT);
+ }
+ if (conn && FD_ISSET(cs_fileno(conn), &input))
+ {
+ do
+ {
+ if ((res = cs_get(conn, &netbuffer, &netbufferlen)) < 0)
+ {
+ perror("cs_get");
+ exit(1);
+ }
+ if (!res)
+ {
+ printf("Target closed connection.\n");
+ exit(1);
+ }
+ odr_reset(in); /* release APDU from last round */
+ odr_setbuf(in, netbuffer, res, 0);
+ if (!z_APDU(in, &apdu, 0))
+ {
+ odr_perror(in, "Decoding incoming APDU");
+ fprintf(stderr, "[Near %d]\n", odr_offset(in));
+ fprintf(stderr, "Packet dump:\n---------\n");
+ odr_dumpBER(stderr, netbuffer, res);
+ fprintf(stderr, "---------\n");
+ exit(1);
+ }