Notice
Recent Posts
Recent Comments
250x250
Creative Code
Chapter9(버퍼 입력받기) 본문
728x90
※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);
// Output buffer size (송신 버퍼 크기) 조회
len = sizeof(snd_buf);
state = getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (void*)&snd_buf, &len);
if (state)
error_handling("getsockopt() error");
// Input buffer size (수신 버퍼 크기) 조회
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\n", rcv_buf);
printf("Output buffer size: %d\n", snd_buf);
return 0;
}
// 에러 핸들링 함수
void error_handling(char *message)
{
fputs(message, stderr);
fputc('\n', stderr);
exit(1);
}
728x90
'TCP IP 소켓프로그래밍' 카테고리의 다른 글
Chapter18(쓰레드,세마포어,mutex) (0) | 2023.10.11 |
---|---|
Chapter8(호스트 정보 조회) (1) | 2023.10.11 |
Chapter5(echo_client) (0) | 2023.10.11 |
Chapter4(서버에 순차접속) (0) | 2023.10.11 |
Chapter3(서버에 접속한 IP주소, 포트번호 출력) (0) | 2023.10.10 |