send length + data at the same time
This commit is contained in:
@@ -219,6 +219,7 @@ static ssize_t sendToVICC(struct vicc_ctx *ctx, size_t length, const unsigned ch
|
||||
{
|
||||
ssize_t r;
|
||||
uint16_t size;
|
||||
char *sendBuffer;
|
||||
|
||||
if (!ctx || length > 0xFFFF) {
|
||||
errno = EINVAL;
|
||||
@@ -226,11 +227,11 @@ static ssize_t sendToVICC(struct vicc_ctx *ctx, size_t length, const unsigned ch
|
||||
}
|
||||
|
||||
/* send size of message on 2 bytes */
|
||||
sendBuffer = (char *) alloca(length + 2);
|
||||
size = htons((uint16_t) length);
|
||||
r = sendall(ctx->client_sock, (void *) &size, sizeof size);
|
||||
if (r == sizeof size)
|
||||
/* send message */
|
||||
r = sendall(ctx->client_sock, buffer, length);
|
||||
memcpy(sendBuffer, &size, 2);
|
||||
memcpy(sendBuffer + 2, buffer, length);
|
||||
r = sendall(ctx->client_sock, sendBuffer, length + 2);
|
||||
|
||||
if (r < 0)
|
||||
vicc_eject(ctx);
|
||||
|
||||
Reference in New Issue
Block a user