Recently, I'm modifying some socket program in kernel space. Following is basic server sending function:
static int http_server_send(struct socket *sock, const char *buf, size_t size){ struct msghdr msg = {.msg_name = NULL, .msg_namelen = 0, .msg_control = NULL, .msg_controllen = 0, .msg_flags = 0}; int done = 0; while (done < size) { struct kvec iov = { .iov_base = (void *) ((char *) buf + done), .iov_len = size - done, }; int length = kernel_sendmsg(sock, &msg, &iov, 1, iov.iov_len); if (length < 0) { pr_err("write error: %d\n", length); break; } done += length; } return done;}
I found buf
or iov_base
follow some specific format when it was passed, format is like following which define as macro ( CRLF is define as "\r\n" ):
"" \"HTTP/1.1 200 OK" CRLF "Server: " KBUILD_MODNAME CRLF \"Content-Type: text/plain" CRLF "Content-Length: %d" CRLF \"Connection: Close" CRLF CRLF "%s" CRLF
Some of above format seems can't be changed (Changed will fail to send message), maybe this is kind of protocol. My question is are there any document or reference can I find the regulation of these format?