0

I have an strace of my program that interacts with USB, and I am wondering what the following write command tells me. I understand the writev iovec structure consists of the data array pointer followed by the length, but what does the "@\10\335 \320\2w\4\240K\252\0\7" in the data array denote? I'm particularly wondering what the @ symbol, 2w, and 240K means as those are not hex data values as I would expect them to be.

I'm running on Linux and here is the writev line:

writev(6, [{"@\10\335 \320\2w\4\240K\252\0\7", 13}, {"\0\0\0\4\0\0\0\4", 8}], 2) = 21
Mihai Maruseac
  • 20,967
  • 7
  • 57
  • 109
ryeager
  • 873
  • 1
  • 10
  • 24

1 Answers1

3

From the man page of writev:

ssize_t readv(int fd, const struct iovec *iov, int iovcnt);

That is, the second argument is an array of size the value of the third argument (2 in your case) elements of type struct iovec.

When strace prints those it octal escapes unprintable characters but displays all other exactly as they can be printed. Hence, @ is just the byte corresponding to @, K is the byte corresponding to K and so on.


Answering your questions in the comment, another look at the man page shows

struct iovec {
    void  *iov_base;    /* Starting address */
    size_t iov_len;     /* Number of bytes to transfer */
};

Which means that {"@\10\335 \320\2w\4\240K\252\0\7", 13} is to be read as iov_len = 13 and iov_base is a memory area containing the bytes printed as @\10\335 \320\2w\4\240K\252\0\7. Fire up gdb if you want to see the binary values:

[mihai@winterfell 1]$ gdb -q
(gdb) p/x "@\10\335 \320\2w\4\240K\252\0\7"
$1 = {0x40, 0x8, 0xdd, 0x20, 0xd0, 0x2, 0x77, 0x4, 0xa0, 0x4b, 0xaa, 0x0, 0x7, 0x0}

Where the last 0x0 is the null terminator of the string and should be ignored.

Mihai Maruseac
  • 20,967
  • 7
  • 57
  • 109