sctpserv07.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "unp.h"
  2. int
  3. main(int argc, char **argv)
  4. {
  5. int sock_fd,msg_flags;
  6. char readbuf[BUFFSIZE];
  7. struct sockaddr_in cliaddr;
  8. struct sctp_sndrcvinfo sri;
  9. struct sctp_event_subscribe evnts;
  10. socklen_t len;
  11. size_t rd_sz;
  12. /* include mod_serv07 */
  13. if(argc < 2)
  14. err_quit("Error, use %s [list of addresses to bind]\n",
  15. argv[0]);
  16. sock_fd = Socket(AF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP);
  17. if(sctp_bind_arg_list(sock_fd, argv + 1, argc - 1))
  18. err_sys("Can't bind the address set");
  19. bzero(&evnts, sizeof(evnts));
  20. evnts.sctp_data_io_event = 1;
  21. /* end mod_serv07 */
  22. evnts.sctp_association_event = 1;
  23. evnts.sctp_address_event = 1;
  24. evnts.sctp_send_failure_event = 1;
  25. evnts.sctp_peer_error_event = 1;
  26. evnts.sctp_shutdown_event = 1;
  27. evnts.sctp_partial_delivery_event = 1;
  28. evnts.sctp_adaption_layer_event = 1;
  29. Setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS,
  30. &evnts, sizeof(evnts));
  31. Listen(sock_fd, LISTENQ);
  32. for ( ; ; ) {
  33. len = sizeof(struct sockaddr_in);
  34. rd_sz = Sctp_recvmsg(sock_fd, readbuf, sizeof(readbuf),
  35. (SA *)&cliaddr, &len,
  36. &sri,&msg_flags);
  37. if(msg_flags & MSG_NOTIFICATION) {
  38. print_notification(readbuf);
  39. continue;
  40. }
  41. Sctp_sendmsg(sock_fd, readbuf, rd_sz,
  42. (SA *)&cliaddr, len,
  43. sri.sinfo_ppid,
  44. sri.sinfo_flags,
  45. sri.sinfo_stream,
  46. 0, 0);
  47. }
  48. }