//读取创建套接字时默认IO缓冲大小;
//get_buf.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
void error_handling(char*message);
int main(int argc, char *argv[])
{
int sock;
int snd_buf,rcv_buf,state;
socklen_t len;
sock = socket(PF_INET,SOCK_STREAM,0);
len = sizeof(snd_buf);
state=getsockopt(sock,SOL_SOCKET,SO_SNDBUF,(void*)&snd_buf,&len);
if(state)
{
error_handling("getsockopt() error");
}
len=sizeof(rcv_buf);
state=getsockopt(sock,SOL_SOCKET,SO_RCVBUF,(void*)&rcv_buf,&len);
if(state)
{
error_handling("getsockopt() error");
}
printf("Input buffer size:%d
",rcv_buf);
printf("Output buffer size:%d
",snd_buf);
return 0;
}
void error_handling(char*message)
{
fputs(message,stderr);
fputc('
',stderr);
exit(1);
}