2009年3月26日 星期四

Socket Options

#include <sys/socket.h>
int getsockopt(int sockfd,int level,int optname,void *optval,socklen_t *optlen);
int setsockopt(int sockfd,int level,int optname,const void *optval,socklen_t optlen);
Both return:0 if OK, -1 on error

主要用來設定socket的一些行為,若想要更深入的使用socket的話,這兩個函數一定要會使用。
而SCTP一共有17種Socket Options
1. SCTP_ADAPTION_LAYER
這一個不是很懂。
2. SCTP_ASSOCINFO
這一個主要有三個目的
(i)去檢索目前某一個存在的association
(ii)去改變目前存在的association的相關參數
(iii)去設定未來所要建立的association的預設參數
會用到的資料結構
struct sctp_assocparams {
sctp_assoc_t sasoc_assoc_id;
uint16_t sasoc_asocmaxrxt;
uint16_t sasoc_number_peer_destinations;
uint32_t sasoc_peer_rwnd;
uint32_t sasoc_local_rwnd;
uint32_t sasoc_cookie_life;
};

3. SCTP_AUTOCLOSE
當idle超過一段時間,則自動切斷連線
4. SCTP_DEFAULT_SEND_PARAM
設定當此association_id要傳送資料給對方時,則要設定哪一個ip為主要的primary ip(因為,SCTP有multi-homing的特性),會用到的資料結構為
struct sctp_sndrcvinfo {
uint16_t sinfo_stream;
uint16_t sinfo_ssn;
uint16_t sinfo_flags;
uint32_t sinfo_ppid;
uint32_t sinfo_context;
uint32_t sinfo_timetolive;
uint32_t sinfo_tsn;
uint32_t sinfo_cumtsn;
sctp_assoc_t sinfo_assoc_id;
};

其中sinfo_flags有以下數值
SCTP_ABORT:Invoke ABORTIVE termination of the association
SCTP_ADD_OVER:Specify that SCTP should override the primary address and use the provided address instead
SCTP_EOF:Invoke graceful termination after the sending of this message
SCTP_UNORDERED:Specify that this message uses the unordered message service
5. SCTP_DISABLE_FRAGMENTS
當要傳送的封包太大時,必需要分割。而預設是有份割的。
若設定預設不分割,當資料太大時,會回傳EMSGSIZE的錯誤訊息
6. SCTP_EVENT
非常重要。
用來設定是否額外傳送資料以外的訊息
struct sctp_event_subscribe {
uint8_t sctp_data_io_event;
uint8_t sctp_association_event;
uint8_t sctp_address_event;
uint8_t sctp_send_failure_event;
uint8_t sctp_peer_error_event;
uint8_t sctp_shutdown_event;
uint8_t sctp_partial_delivery_event;
uint8_t sctp_adaption_layer_event;
};

7. SCTP_GET_PEER_ADDR_INFO
用來讀取對方某一個位址(ip)的資訊
會用到的資料結構為
struct sctp_paddrinfo {
sctp_assoc_t spinfo_assoc_id;
struct sockaddr_storage spinfo_address;
int32_t spinfo_state;
uint32_t spinfo_cwnd;
uint32_t spinfo_srtt;
uint32_t spinfo_rto;
uint32_t spinfo_mtu;
};

spinfo_state:有以下可能數值
SCTP_ACTIVE:Address is active and reachable
SCTP_INACTIVE:Address cannot currently be reached
SCTP_ADDR_UNCONFIRMED:No heartbeat or data has confirmed this address
8. SCTP_I_WANT_MAPPED_V4_ADDR
在傳送給Application前,會把ip4的位址轉換成ipv6的位址(預設是enabled)
9. SCTP_INITMSG
用來設定要傳送INIT message的參數
會用到以下資料結構
struct sctp_initmsg {
uint16_t sinit_num_ostreams;
uint16_t sinit_max_instreams;
uint16_t sinit_max_attempts;
uint16_t sinit_max_init_timeo;
};

10. SCTP_MAXBURST
不太了解
11. SCTP_MAXSEG
設定segment的最大值
12. SCTP_NODELAY
設定SCTP傳送是不DELAY的,預設是關的
13. SCTP_PEER_ADDR_PARAMS
用來取得或是改變association的參數值。
資料結構
struct sctp_paddrparams {
sctp_assoc_t spp_assoc_id;
struct sockaddr_storage spp_address;
uint32_t spp_hbinterval;
uint16_t spp_pathmaxrxt;
};

14. SCTP_PRIMARY_ADDR
用來決定某一個association要送過去的address主要是哪一個
要用到的資料結構
struct sctp_setprim {
sctp_assoc_t ssp_assoc_id;
struct sockaddr_storage ssp_addr;
};

15. SCTP_RTOINFO
設定封包來回的時間
struct sctp_rtoinfo {
sctp_assoc_t srto_assoc_id;
uint32_t srto_initial;
uint32_t srto_max;
uint32_t srto_min;
};

16. SCTP_SET_PEER_PRIMARY_ADDR
請peer設定一個IP Address為其peer的primary address
struct sctp_setpeerprim {
sctp_assoc_t sspp_assoc_id;
struct sockaddr_storage sspp_addr;
};

17. SCTP_STATUS
檢索目前association的情況
struct sctp_status {
sctp_assoc_t sstat_assoc_id;
int32_t sstat_state;
u_int32_t sstat_rwnd;
u_int32_t sstat_unackdata;
u_int32_t sstat_penddata;
u_int32_t sstat_instrms;
u_int32_t sstat_outstrms;
u_int32_t sstat_fragmentation_point;
struct sctp_paddrinfo sstat_primary;
};

沒有留言: