2013-02-25 1 views
4

왜 sockaddr_storage가 정확히 128 바이트인지 궁금합니다. 나는 그것이 IPv6를 위해 적어도 28 바이트가되어야한다는 것을 이해한다. 그러나 이것은 sockaddr_in6보다 100 여분의 바이트가 더 많도록 약간 과장된 것으로 보인다. 스토리지 구조체를 미래에 증명할 수 있을까요? 아니면 지금 당장 필요로하는 이유가 있습니까?sockaddr_storage size of 128 bytes

+0

은'구조체 sockaddr_atmsvc' 얼마나 큰? 나도 몰라,하지만 나는 28 바이트 이상을 걸었다. –

답변

3

§3.10의 질문에 대한 답변은 rfc 2553이고이 부분은 SO post입니다.

이유는 적어도 효율 정렬 IP6와 다른 프로토콜 데이터및 64 비트를 보유한다 의 조합이다. 은 RFC의 관련 부분에서

: 응용 프로그램
작가를 도울 수있는 소켓 API에

하나의 간단한 추가는 "구조체 sockaddr_storage"입니다. 이 데이터 구조는
코드를 사용하여 여러 주소 패밀리에서 이식 가능한 코드 작성을 간소화하고
플랫폼 일 수 있습니다. 이 데이터 구조는 다음 목표로 설계되었습니다.

- It has a large enough implementation specific maximum size to 
    store the desired set of protocol specific socket address data 
    structures. Specifically, it is at least large enough to 
    accommodate sockaddr_in and sockaddr_in6 and possibly other 
    protocol specific socket addresses too. 
    - It is aligned at an appropriate boundary so protocol specific 
    socket address data structure pointers can be cast to it and 
    access their fields without alignment problems. (e.g. pointers 
    to sockaddr_in6 and/or sockaddr_in can be cast to it and access 
    fields without alignment problems). 
    - It has the initial field(s) isomorphic to the fields of the 
    "struct sockaddr" data structure on that implementation which 
    can be used as a discriminants for deriving the protocol in use. 
    These initial field(s) would on most implementations either be a 
    single field of type "sa_family_t" (isomorphic to sa_family 
    field, 16 bits) or two fields of type uint8_t and sa_family_t 
    respectively, (isomorphic to sa_len and sa_family_t, 8 bits 
    each). 
2

이 구조에도 struct sockaddr_un을 넣을 수있는 시스템이있을 수 있습니다. 후자는 약 100-110 자의 시스템 종속 경로 길이를가집니다. 그리고 128은 아름답게 짝수입니다.