티스토리 뷰

 getsockopt() 예제  


/* buffer_check.c */

#include<stdio.h>
#include<sys/socket.h>
#include<stdlib.h>

int main()
{
    int tcp_sock, udp_sock ;
    int snd_buf, rcv_buf ;
    socklen_t len ;

    tcp_sock = socket(PF_INET, SOCK_STREAM, 0) ;
    udp_sock = socket(PF_INET, SOCK_DGRAM, 0) ;

    if ( getsockopt ( tcp_sock, SOL_SOCKET, SO_SNDBUF, &snd_buf, &len))
    {
        printf("getsockopt() error!\n") ;
        exit(1) ;
    }

    if ( getsockopt ( tcp_sock, SOL_SOCKET, SO_RCVBUF, &rcv_buf, &len))
    {
        printf("getsocket() error!\n") ;
        exit(1) ;
    }
    
    printf("TCP send buffer size : %d\n", snd_buf ) ;
    printf("TCP receive buffer size : %d\n", rcv_buf ) ;

    if ( getsockopt(udp_sock, SOL_SOCKET, SO_SNDBUF, &snd_buf, &len))
    {
        printf("getsockopt() error!\n");
        exit(1) ;
    }

    if ( getsockopt(udp_sock, SOL_SOCKET, SO_RCVBUF, &rcv_buf, &len))
    {
        printf("getsockopt() error!\n");
        exit(1) ;
    }

    printf("UDP send buffer size : %d\n", snd_buf) ;
    printf("UDP receive buffer size : %d\n", rcv_buf) ;

    return 0 ;
}

 실행 결과  

댓글
댓글쓰기 폼
공지사항
Total
3,562,201
Today
473
Yesterday
583
«   2021/12   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
글 보관함