setsockopt
函数第二个参数level是被设置的选项的级别,如果想要在套接字级别上设置选项,就必须把level设置为 SOL_SOCKET。
int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
memset
函数void *memset(void *s, int ch, size_t n);
作用
En
Copies the value static_cast<unsigned char>
(ch) into each of the first count characters of the object pointed to by dest. If the object is a potentially-overlapping subobject or is not TriviallyCopyable (e.g., scalar, C-compatible struct, or an array of trivially copyable type), the behavior is undefined. If count is greater than the size of the object pointed to by dest, the behavior is undefined.
Ch
将ch的值复制到dest指向的对象的前count个字符中。如果对象是潜在重叠的子对象或不是TriviallyCopyable(例如,标量,C兼容的结构或平凡可复制的类型的数组),则行为是未定义的。如果count大于dest指向的对象的大小,则行为是未定义的。
复制ch的值到 s 指向的对象的前 n 个字符中。
void *memset(void *s, int ch, size_t n);
返回一个指向内存块 s 的指针。
snprintf
函数En Writes formatted data from variable argument list to sized buffer. Ch 将格式化的数据从变量参数列表写入大小缓冲区。
int snprintf( char *buffer, size_t buf_size, const char *format, ... );//可变参数
memcpy
函数En
Copies count bytes from the object pointed to by src to the object pointed to by dest.
Both objects are reinterpreted as arrays of unsigned char.
If the objects overlap, the behavior is undefined.
If either dest or src is a potentially-overlapping subobject
(e.g., a field in a C-compatible struct) or is not TriviallyCopyable
(e.g., scalar, C-compatible struct, or an array thereof),
the behavior is undefined. If count is zero, the function does nothing.
Ch
将src指向的对象的count个字节复制到dest指向的对象。
两个对象都被重新解释为无符号字符数组。
如果对象重叠,则行为是未定义的。
如果dest或src是潜在重叠的子对象(例如,C兼容结构中的字段)
或不是TriviallyCopyable(例如,标量,C兼容结构或其数组),
则行为是未定义的。如果count为零,则函数不执行任何操作。
void *memcpy(void *dest, const void *src, size_t count);
void *memcpy(void *dest, const void *src, size_t count)
{
char *d = dest;
const char *s = src;
while (count--)
*d++ = *s++;
return dest;
}