RTP Audio System  2.0.0
ext_socket.h
Go to the documentation of this file.
00001 /*
00002  *  $Id: ext_socket.h 1259 2011-12-17 13:26:09Z dreibh $
00003  *
00004  * SocketAPI implementation for the sctplib.
00005  * Copyright (C) 1999-2012 by Thomas Dreibholz
00006  *
00007  * Realized in co-operation between
00008  * - Siemens AG
00009  * - University of Essen, Institute of Computer Networking Technology
00010  * - University of Applied Sciences, Muenster
00011  *
00012  * Acknowledgement
00013  * This work was partially funded by the Bundesministerium fuer Bildung und
00014  * Forschung (BMBF) of the Federal Republic of Germany (Foerderkennzeichen 01AK045).
00015  * The authors alone are responsible for the contents.
00016  *
00017  * This program is free software: you can redistribute it and/or modify
00018  * it under the terms of the GNU General Public License as published by
00019  * the Free Software Foundation, either version 3 of the License, or
00020  * (at your option) any later version.
00021 
00022  * This program is distributed in the hope that it will be useful,
00023  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025  * GNU General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00029  *
00030  * Contact: discussion@sctp.de
00031  *          dreibh@iem.uni-due.de
00032  *          tuexen@fh-muenster.de
00033  *
00034  * Purpose: Extended Socket API
00035  *
00036  */
00037 
00038 
00039 #ifndef EXTSOCKET_H
00040 #define EXTSOCKET_H
00041 
00042 
00043 #ifndef HAVE_KERNEL_SCTP
00044 
00045 
00046 #include <sys/types.h>
00047 #include <sys/socket.h>
00048 #include <sys/uio.h>
00049 #include <sys/fcntl.h>
00050 #include <sys/time.h>
00051 #include <inttypes.h>
00052 #include <netinet/in.h>
00053 #include <poll.h>
00054 
00055 
00056 #ifndef IPPROTO_SCTP
00057 #define IPPROTO_SCTP 132
00058 #endif
00059 
00060 
00061 #define SOCKETAPI_MAJOR_VERSION  0x2
00062 #define SOCKETAPI_MINOR_VERSION  0x2200
00063 
00064 
00065 /*
00066    The socketapi library internally combines the
00067    flags and sinfo_flags fields! Here, it is
00068    ensured to define unique value.
00069 */
00070 #define MSG_UNORDERED     MSG_DONTROUTE
00071 #define MSG_UNBUNDLED     MSG_CTRUNC
00072 #ifndef MSG_NOTIFICATION
00073 #define MSG_NOTIFICATION  MSG_OOB
00074 #endif
00075 #ifndef MSG_EOF
00076 #define MSG_EOF           MSG_FIN
00077 #endif
00078 #define MSG_SHUTDOWN      MSG_EOF
00079 #define MSG_MULTIADDRS    MSG_TRUNC
00080 
00081 #ifdef MSG_RST
00082 #define MSG_ABORT         MSG_RST
00083 #define MSG_PR_SCTP_TTL   MSG_ERRQUEUE
00084 #define MSG_ADDR_OVER     MSG_MORE
00085 #define MSG_SEND_TO_ALL   MSG_PROXY
00086 #else
00087 #define MSG_ABORT         0x200
00088 #define MSG_PR_SCTP_TTL   0x400
00089 #define MSG_ADDR_OVER     0x800
00090 #define MSG_SEND_TO_ALL   0xc00
00091 #endif
00092 
00093 #define SCTP_UNORDERED    MSG_UNORDERED
00094 #define SCTP_UNBUNDLED    MSG_UNBUNDLED
00095 #define SCTP_NOTIFICATION MSG_NOTIFICATION
00096 #define SCTP_ABORT        MSG_ABORT
00097 #define SCTP_EOF          MSG_EOF
00098 #define SCTP_ADDR_OVER    MSG_ADDR_OVER
00099 #define SCTP_SEND_TO_ALL  MSG_SEND_TO_ALL
00100 #define SCTP_MULTIADDRS   MSG_MULTIADDRS
00101 
00102 
00103 typedef unsigned int   sctp_assoc_t;
00104 typedef unsigned short sctp_stream_t;
00105 
00106 
00107 #define SCTP_UNDEFINED 0
00108 
00109 #define SCTP_INIT 1
00110 struct sctp_initmsg {
00111    uint16_t sinit_num_ostreams;
00112    uint16_t sinit_max_instreams;
00113    uint16_t sinit_max_attempts;
00114    uint16_t sinit_max_init_timeo;
00115 };
00116 
00117 #define SCTP_SNDRCV 2
00118 struct sctp_sndrcvinfo
00119 {
00120    uint16_t     sinfo_stream;
00121    uint16_t     sinfo_ssn;
00122    /* !!! 32 bits instead of 16 bits !!! */
00123    uint32_t     sinfo_flags;
00124    uint32_t     sinfo_ppid;
00125    uint32_t     sinfo_context;
00126    uint32_t     sinfo_timetolive;
00127    uint32_t     sinfo_tsn;
00128    uint32_t     sinfo_cumtsn;
00129    sctp_assoc_t sinfo_assoc_id;
00130 };
00131 
00132 #define SCTP_ASSOC_CHANGE 1
00133 struct sctp_assoc_change
00134 {
00135    uint16_t     sac_type;
00136    uint16_t     sac_flags;
00137    uint32_t     sac_length;
00138    uint16_t     sac_state;
00139    uint16_t     sac_error;
00140    uint16_t     sac_outbound_streams;
00141    uint16_t     sac_inbound_streams;
00142    sctp_assoc_t sac_assoc_id;
00143 };
00144 #define SCTP_COMM_UP        11
00145 #define SCTP_COMM_LOST      12
00146 #define SCTP_RESTART        13
00147 #define SCTP_SHUTDOWN_COMP  14
00148 #define SCTP_CANT_STR_ASSOC 15
00149 
00150 #define SCTP_PEER_ADDR_CHANGE 2
00151 struct sctp_paddr_change
00152 {
00153     uint16_t                spc_type;
00154     uint16_t                spc_flags;
00155     uint32_t                spc_length;
00156     struct sockaddr_storage spc_aaddr;
00157     int                     spc_state;
00158     int                     spc_error;
00159     sctp_assoc_t            spc_assoc_id;
00160 };
00161 #define SCTP_ADDR_REACHABLE   21
00162 #define SCTP_ADDR_UNREACHABLE 22
00163 #define SCTP_ADDR_REMOVED     23
00164 #define SCTP_ADDR_ADDED       24
00165 #define SCTP_ADDR_MADE_PRIM   25
00166 #define SCTP_ADDR_CONFIRMED   26
00167 
00168 #define SCTP_REMOTE_ERROR 3
00169 struct sctp_remote_error
00170 {
00171    uint16_t     sre_type;
00172    uint16_t     sre_flags;
00173    uint32_t     sre_length;
00174    uint16_t     sre_error;
00175    sctp_assoc_t sre_assoc_id;
00176    uint8_t      sre_data[0];
00177 };
00178 
00179 #define SCTP_SEND_FAILED 4
00180 struct sctp_send_failed
00181 {
00182    uint16_t               ssf_type;
00183    uint16_t               ssf_flags;
00184    uint32_t               ssf_length;
00185    uint32_t               ssf_error;
00186    struct sctp_sndrcvinfo ssf_info;
00187    sctp_assoc_t           ssf_assoc_id;
00188    uint8_t                ssf_data[0];
00189 };
00190 #define SCTP_DATA_UNSENT 41
00191 #define SCTP_DATA_SENT   42
00192 
00193 
00194 #define SCTP_SHUTDOWN_EVENT 5
00195 struct sctp_shutdown_event
00196 {
00197    uint16_t     sse_type;
00198    uint16_t     sse_flags;
00199    uint32_t     sse_length;
00200    sctp_assoc_t sse_assoc_id;
00201 };
00202 
00203 
00204 #define SCTP_ADAPTATION_INDICATION 6
00205 struct sctp_adaptation_event
00206 {
00207    uint16_t     sai_type;
00208    uint16_t     sai_flags;
00209    uint32_t     sai_length;
00210    uint32_t     sai_adaptation_ind;
00211    sctp_assoc_t sai_assoc_id;
00212 };
00213 
00214 
00215 #define SCTP_PARTIAL_DELIVERY_EVENT 7
00216 #define SCTP_PARTIAL_DELIVERY_ABORTED 1
00217 struct sctp_pdapi_event
00218 {
00219    uint16_t     pdapi_type;
00220    uint16_t     pdapi_flags;
00221    uint32_t     pdapi_length;
00222    uint32_t     pdapi_indication;
00223    sctp_assoc_t pdapi_assoc_id;
00224 };
00225 
00226 
00227 /*
00228    For interal implementation usage only!
00229  */
00230 #define SCTP_DATA_ARRIVE 8
00231 #define SCTP_ARRIVE_UNORDERED (1 << 0)
00232 struct sctp_data_arrive
00233 {
00234    uint16_t      sda_type;
00235    uint16_t      sda_flags;
00236    uint32_t      sda_length;
00237    sctp_assoc_t  sda_assoc_id;
00238    sctp_stream_t sda_stream;
00239    uint32_t      sda_ppid;
00240    uint32_t      sda_bytes_arrived;
00241 };
00242 
00243 
00244 union sctp_notification {
00245    struct {
00246       uint16_t sn_type;
00247       uint16_t sn_flags;
00248       uint32_t sn_length;
00249    }                           sn_header;
00250    struct sctp_assoc_change    sn_assoc_change;
00251    struct sctp_paddr_change    sn_paddr_change;
00252    struct sctp_remote_error    sn_remote_error;
00253    struct sctp_send_failed     sn_send_failed;
00254    struct sctp_shutdown_event  sn_shutdown_event;
00255    struct sctp_adaptation_event  sn_adaptation_event;
00256    struct sctp_pdapi_event     sn_pdapi_event;
00257 
00258    struct sctp_data_arrive     sn_data_arrive;
00259 };
00260 
00261 
00262 
00263 
00264 
00265 struct sctp_rtoinfo
00266 {
00267    sctp_assoc_t srto_assoc_id;
00268    uint32_t     srto_initial;
00269    uint32_t     srto_max;
00270    uint32_t     srto_min;
00271 };
00272 
00273 
00274 struct sctp_assocparams
00275 {
00276    sctp_assoc_t sasoc_assoc_id;
00277    uint16_t     sasoc_asocmaxrxt;
00278    uint16_t     sasoc_number_peer_destinations;
00279    uint32_t     sasoc_peer_rwnd;
00280    int32_t      sasoc_local_rwnd;
00281    uint32_t     sasoc_cookie_life;
00282 };
00283 
00284 
00285 struct sctp_setprim
00286 {
00287    sctp_assoc_t            ssp_assoc_id;
00288    struct sockaddr_storage ssp_addr;
00289 };
00290 
00291 
00292 struct sctp_setpeerprim
00293 {
00294    sctp_assoc_t            sspp_assoc_id;
00295    struct sockaddr_storage sspp_addr;
00296 };
00297 
00298 
00299 struct sctp_setstrm_timeout
00300 {
00301    sctp_assoc_t ssto_assoc_id;
00302    uint32_t     ssto_timeout;
00303    uint16_t     ssto_streamid_start;
00304    uint16_t     ssto_streamid_end;
00305 };
00306 
00307 
00308 #define SPP_HB_ENABLE         (1 << 0)
00309 #define SPP_HB_DISABLE        (1 << 1)
00310 #define SPP_PMTUD_ENABLE      (1 << 2)
00311 #define SPP_PMTUD_DISABLE     (1 << 3)
00312 #define SPP_SACKDELAY_ENABLE  (1 << 4)
00313 #define SPP_SACKDELAY_DISABLE (1 << 5)
00314 
00315 struct sctp_paddrparams {
00316    sctp_assoc_t            spp_assoc_id;
00317    struct sockaddr_storage spp_address;
00318    uint32_t                spp_hbinterval;
00319    uint16_t                spp_pathmaxrxt;
00320    uint32_t                spp_pathmtu;
00321    uint32_t                spp_sackdelay;
00322    uint32_t                spp_flags;
00323 };
00324 
00325 
00326 struct sctp_paddrinfo {
00327    sctp_assoc_t            spinfo_assoc_id;
00328    struct sockaddr_storage spinfo_address;
00329    int32_t                 spinfo_state;
00330    uint32_t                spinfo_cwnd;
00331    uint32_t                spinfo_srtt;
00332    uint32_t                spinfo_rto;
00333    uint32_t                spinfo_mtu;
00334 };
00335 
00336 
00337 #define SCTP_INACTIVE 0
00338 #define SCTP_ACTIVE   1
00339 
00340 struct sctp_status
00341 {
00342    sctp_assoc_t          sstat_assoc_id;
00343    int32_t               sstat_state;
00344    uint32_t              sstat_rwnd;
00345    uint16_t              sstat_unackdata;
00346    uint16_t              sstat_penddata;
00347    uint16_t              sstat_instrms;
00348    uint16_t              sstat_outstrms;
00349    uint32_t              sstat_fragmentation_point;
00350    struct sctp_paddrinfo sstat_primary;
00351 };
00352 
00353 
00354 struct sctp_event_subscribe
00355 {
00356    uint8_t sctp_data_io_event;
00357    uint8_t sctp_association_event;
00358    uint8_t sctp_address_event;
00359    uint8_t sctp_send_failure_event;
00360    uint8_t sctp_peer_error_event;
00361    uint8_t sctp_shutdown_event;
00362    uint8_t sctp_partial_delivery_event;
00363    uint8_t sctp_adaptation_layer_event;
00364 };
00365 
00366 
00367 struct sctp_assoc_value {
00368    sctp_assoc_t assoc_id;
00369    uint32_t     assoc_value;
00370 };
00371 
00372 
00373 struct sctp_sack_info {
00374    sctp_assoc_t sack_assoc_id;
00375    uint32_t     sack_delay;
00376    uint32_t     sack_freq;
00377 };
00378 
00379 
00380 #define SCTP_INITMSG                1000
00381 #define SCTP_AUTOCLOSE              1001
00382 
00383 #define SCTP_RTOINFO                1010
00384 #define SCTP_ASSOCINFO              1011
00385 #define SCTP_PRIMARY_ADDR           1012
00386 #define SCTP_SET_PEER_PRIMARY_ADDR  1013
00387 #define SCTP_SET_STREAM_TIMEOUTS    1014
00388 #define SCTP_PEER_ADDR_PARAMS       1015
00389 #define SCTP_STATUS                 1016
00390 #define SCTP_GET_PEER_ADDR_INFO     1017
00391 
00392 #define SCTP_NODELAY                1018
00393 #define SCTP_SET_DEFAULT_SEND_PARAM 1019
00394 #define SCTP_EVENTS                 1020
00395 #define SCTP_DELAYED_SACK           1021
00396 #define SCTP_FRAGMENT_INTERLEAVE    1022
00397 #define SCTP_PARTIAL_DELIVERY_POINT 1023
00398 #define SCTP_MAXSEG                 1024
00399 #define SCTP_I_WANT_MAPPED_V4_ADDR  1025
00400 
00401 
00402 
00403 #ifdef __cplusplus
00404 extern "C" {
00405 #endif
00406 
00407 unsigned int socketAPIGetVersion();
00408 int ext_socket(int domain, int type, int protocol);
00409 int ext_open(const char* pathname, int flags, mode_t mode);
00410 int ext_creat(const char* pathname, mode_t mode);
00411 int ext_bind(int sockfd, struct sockaddr* my_addr, socklen_t addrlen);
00412 int ext_connect(int sockfd, const struct sockaddr* serv_addr, socklen_t addrlen);
00413 int ext_listen(int s, int backlog);
00414 int ext_accept(int s,  struct  sockaddr * addr,  socklen_t* addrlen);
00415 int ext_shutdown(int s, int how);
00416 int ext_close(int fd);
00417 int ext_getsockname(int sockfd, struct sockaddr* name, socklen_t* namelen);
00418 int ext_getpeername(int sockfd, struct sockaddr* name, socklen_t* namelen);
00419 int ext_fcntl(int fd, int cmd, ...);
00420 int ext_ioctl(int d, int request, const void* argp);
00421 int ext_getsockopt(int sockfd, int level, int optname, void* optval, socklen_t* optlen);
00422 int ext_setsockopt(int sockfd, int level, int optname, const void* optval, socklen_t optlen);
00423 ssize_t ext_recv(int s, void* buf, size_t len, int flags);
00424 ssize_t ext_recvfrom(int  s,  void * buf,  size_t len, int flags, struct sockaddr* from, socklen_t* fromlen);
00425 ssize_t ext_recvmsg(int s, struct msghdr* msg, int flags);
00426 ssize_t ext_send(int s, const void* msg, size_t len, int flags);
00427 ssize_t ext_sendto(int s, const void* msg, size_t len, int flags, const struct sockaddr* to, socklen_t tolen);
00428 ssize_t ext_sendmsg(int s, const struct msghdr* msg, int flags);
00429 ssize_t ext_read(int fd, void* buf, size_t count);
00430 ssize_t ext_write(int fd, const void* buf, size_t count);
00431 int ext_select(int n, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, struct timeval* timeout);
00432 int ext_poll(struct pollfd* fdlist, long unsigned int count, int time);
00433 
00434 
00435 /* For internal usage only! */
00436 int ext_recvmsg2(int sockfd, struct msghdr* msg, int flags,
00437                  const int receiveNotifications);
00438 
00439 
00440 #define SCTP_BINDX_ADD_ADDR 1
00441 #define SCTP_BINDX_REM_ADDR 2
00442 
00443 int sctp_bindx(int              sockfd,
00444                struct sockaddr* addrs,
00445                int              addrcnt,
00446                int              flags);
00447 
00448 int ext_connectx(int                    sockfd,
00449                  const struct sockaddr* addrs,
00450                  int                    addrcnt,
00451                  sctp_assoc_t*          id);
00452 #define sctp_connectx ext_connectx
00453 
00454 int sctp_peeloff(int sockfd, sctp_assoc_t id);
00455 
00456 int sctp_getpaddrs(int sockfd, sctp_assoc_t id, struct sockaddr** addrs);
00457 void sctp_freepaddrs(struct sockaddr* addrs);
00458 
00459 int sctp_getladdrs(int sockfd, sctp_assoc_t id, struct sockaddr** addrs);
00460 void sctp_freeladdrs(struct sockaddr* addrs);
00461 
00462 int sctp_opt_info(int sd, sctp_assoc_t assocID, int opt, void* arg, socklen_t* size);
00463 
00464 ssize_t sctp_send(int                           s,
00465                   const void*                   data,
00466                   size_t                        len,
00467                   const struct sctp_sndrcvinfo* sinfo,
00468                   int                           flags);
00469 ssize_t sctp_sendx(int                           sd,
00470                    const void*                   data,
00471                    size_t                        len,
00472                    const struct sockaddr*        addrs,
00473                    int                           addrcnt,
00474                    const struct sctp_sndrcvinfo* sinfo,
00475                    int                           flags);
00476 ssize_t sctp_sendmsg(int                    s,
00477                      const void*            data,
00478                      size_t                 len,
00479                      const struct sockaddr* to,
00480                      socklen_t              tolen,
00481                      uint32_t               ppid,
00482                      uint32_t               flags,
00483                      uint16_t               stream_no,
00484                      uint32_t               timetolive,
00485                      uint32_t               context);
00486 ssize_t sctp_recvmsg(int                     s,
00487                      void*                   msg,
00488                      size_t                  len,
00489                      struct sockaddr*        from,
00490                      socklen_t*              fromlen,
00491                      struct sctp_sndrcvinfo* sinfo,
00492                      int*                    msg_flags);
00493 int ext_pipe(int fds[2]);
00494 
00495 
00501 int sctp_isavailable();
00502 
00509 int sctp_enableOOTBHandling(const unsigned int enable);
00510 
00517 int sctp_enableCRC32(const unsigned int enable);
00518 
00519 
00520 #ifdef __cplusplus
00521 }
00522 #endif
00523 
00524 
00525 #else
00526 
00527 
00528 #ifdef __cplusplus
00529 #define ext_socket(a,b,c) ::socket(a,b,c)
00530 #define ext_bind(a,b,c) ::bind(a,b,c)
00531 #define ext_connect(a,b,c) ::connect(a,b,c)
00532 #define ext_listen(a,b) ::listen(a,b)
00533 #define ext_accept(a,b,c) ::accept(a,b,c)
00534 #define ext_shutdown(a,b) ::shutdown(a,b)
00535 #define ext_close(a) ::close(a)
00536 #define ext_getsockname(a,b,c) ::getsockname(a,b,c)
00537 #define ext_getpeername(a,b,c) ::getpeername(a,b,c)
00538 #define ext_fcntl(a,b,c) ::fcntl(a,b,c)
00539 #define ext_ioctl(a,b,c) ::ioctl(a,b,c)
00540 #define ext_getsockopt(a,b,c,d,e) ::getsockopt(a,b,c,d,e)
00541 #define ext_setsockopt(a,b,c,d,e) ::setsockopt(a,b,c,d,e)
00542 #define ext_recv(a,b,c,d) ::recv(a,b,c,d)
00543 #define ext_recvfrom(a,b,c,d,e,f) ::recvfrom(a,b,c,d,e,f)
00544 #define ext_recvmsg(a,b,c) ::recvmsg(a,b,c)
00545 #define ext_send(a,b,c,d) ::send(a,b,c,d)
00546 #define ext_sendto(a,b,c,d,e,f) ::sendto(a,b,c,d,e,f)
00547 #define ext_sendmsg(a,b,c) ::sendmsg(a,b,c)
00548 #define ext_read(a,b,c) ::read(a,b,c)
00549 #define ext_write(a,b,c) ::write(a,b,c)
00550 #define ext_select(a,b,c,d,e) ::select(a,b,c,d,e)
00551 #ifndef USE_SELECT
00552 #define ext_poll(a,b,c) ::poll(a,b,c)
00553 #endif
00554 #define ext_pipe(a) ::pipe(a)
00555 #else
00556 #define ext_socket(a,b,c) socket(a,b,c)
00557 #define ext_bind(a,b,c) bind(a,b,c)
00558 #define ext_connect(a,b,c) connect(a,b,c)
00559 #define ext_listen(a,b) listen(a,b)
00560 #define ext_accept(a,b,c) accept(a,b,c)
00561 #define ext_shutdown(a,b) shutdown(a,b)
00562 #define ext_close(a) close(a)
00563 #define ext_getsockname(a,b,c) getsockname(a,b,c)
00564 #define ext_getpeername(a,b,c) getpeername(a,b,c)
00565 #define ext_fcntl(a,b,c) fcntl(a,b,c)
00566 #define ext_ioctl(a,b,c) ioctl(a,b,c)
00567 #define ext_getsockopt(a,b,c,d,e) getsockopt(a,b,c,d,e)
00568 #define ext_setsockopt(a,b,c,d,e) setsockopt(a,b,c,d,e)
00569 #define ext_recv(a,b,c,d) recv(a,b,c,d)
00570 #define ext_recvfrom(a,b,c,d,e,f) recvfrom(a,b,c,d,e,f)
00571 #define ext_recvmsg(a,b,c) recvmsg(a,b,c)
00572 #define ext_send(a,b,c,d) send(a,b,c,d)
00573 #define ext_sendto(a,b,c,d,e,f) sendto(a,b,c,d,e,f)
00574 #define ext_sendmsg(a,b,c) sendmsg(a,b,c)
00575 #define ext_read(a,b,c) read(a,b,c)
00576 #define ext_write(a,b,c) write(a,b,c)
00577 #define ext_select(a,b,c,d,e) select(a,b,c,d,e)
00578 #ifndef USE_SELECT
00579 #define ext_poll(a,b,c) poll(a,b,c)
00580 #endif
00581 #define ext_pipe(a) pipe(a)
00582 #endif
00583 
00584 #include <sys/types.h>
00585 #include <sys/socket.h>
00586 #include <netinet/in.h>
00587 #include <sys/uio.h>
00588 #include <netinet/sctp.h>
00589 
00590 #ifndef SCTP_DELAYED_SACK
00591 #define SCTP_DELAYED_SACK SCTP_DELAYED_ACK_TIME
00592 #endif
00593 
00594 #endif
00595 
00596 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines