diff --git a/ascon.c b/ascon.c index 3b976a57..fe1f1995 100644 --- a/ascon.c +++ b/ascon.c @@ -218,22 +218,25 @@ int AsconConnectSuccess(int fd) FD_SET(fd, &rmask); ret = uselect(fd + 1, &rmask, &wmask, NULL, &tmo); if (ret > 0) { - /** - * This assertion triggered for some reason: as writing is only done later - * I moved the test for ISSET(wmask) down there - * assert(FD_ISSET(fd, &wmask)); - */ + /** + * MK: + * This assertion triggered for some reason: as writing is only done later + * I moved the test for ISSET(wmask) down there + * assert(FD_ISSET(fd, &wmask)); + * MZ: + * I remember having found this logic on the www. Anyway, your way must be o.k. too + */ if (FD_ISSET(fd, &rmask)) { /* there may already be data for read */ if (recv(fd, NULL, 0, 0) < 0) { /* zero length, check only return value */ ret = ASCON_RECV_ERROR; /* first recv failed */ } } else { - if(FD_ISSET(fd,&wmask)){ - if (send(fd, NULL, 0, 0) < 0) { /* zero length, check only return value */ - ret = ASCON_SEND_ERROR; /* first send failed */ - } - } + if (FD_ISSET(fd,&wmask)) { + if (send(fd, NULL, 0, 0) < 0) { /* zero length, check only return value */ + ret = ASCON_SEND_ERROR; /* first send failed */ + } + } } } fcntl(fd, F_SETFL, oldopts & ~O_NONBLOCK); /* reset to blocking mode */ @@ -498,21 +501,22 @@ int AsconStdHandler(Ascon * a) /** * Treat hex strings as terminators right. Note that this * is limited to single character terminators. + * M.Z. changed strstr to strncmp (more precise) */ static void AsconCheckTerminators(Ascon *a) { - int c; + int c; - if(a->sendTerminator != NULL && strstr(a->sendTerminator,"0x") != NULL){ - sscanf(a->sendTerminator,"%x",&c); - a->sendTerminator[0] = (char)c; - a->sendTerminator[1] = '\0'; - } - if(a->replyTerminator != NULL && strstr(a->replyTerminator,"0x") != NULL){ - sscanf(a->replyTerminator,"%x",&c); - a->replyTerminator[0] = (char)c; - a->replyTerminator[1] = '\0'; - } + if (a->sendTerminator != NULL && strncmp(a->sendTerminator,"0x",2) == 0) { + sscanf(a->sendTerminator,"%x",&c); + a->sendTerminator[0] = (char)c; + a->sendTerminator[1] = '\0'; + } + if (a->replyTerminator != NULL && strncmp(a->replyTerminator,"0x",2) == 0) { + sscanf(a->replyTerminator,"%x",&c); + a->replyTerminator[0] = (char)c; + a->replyTerminator[1] = '\0'; + } } int AsconInterpreteArgs(int argc, char *argv[], @@ -579,7 +583,7 @@ int AsconStdInit(Ascon *a, SConnection *con, int argc, char *argv[]) } else { a->sendTerminator = strdup("\n"); } - if (pars[1] && pars[2] != '\0') { + if (pars[1] && pars[1][0] != '\0') { a->timeout = atof(pars[1]); } else { a->timeout = 2.0; /* sec */