Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <errno.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netinet/sctp.h>
- #include <arpa/inet.h>
- #define PORT 5055
- int main(void)
- {
- int sock;
- int retval;
- int iter;
- struct sockaddr_in bind_addr, remote_addr;
- char write_buff[1024];
- sock = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
- if (sock == -1) {
- perror("socket()");
- exit(-1);
- }
- bind_addr.sin_family = AF_INET;
- bind_addr.sin_port = htons(0);
- bind_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
- if (bind_addr.sin_addr.s_addr == INADDR_NONE) {
- perror("inet_addr()");
- exit(-1);
- }
- retval = sctp_bindx(sock, (struct sockaddr *) &bind_addr, 1, SCTP_BINDX_ADD_ADDR);
- if (retval != 0) {
- perror("sctp_bindx()");
- exit(-1);
- }
- remote_addr.sin_family = AF_INET;
- remote_addr.sin_port = htons(PORT);
- remote_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
- if (remote_addr.sin_addr.s_addr == INADDR_NONE) {
- perror("inet_addr()");
- exit(-1);
- }
- for(iter = 0; iter < 20; iter++) {
- snprintf(write_buff, sizeof(write_buff), "Message #%d", iter);
- retval = sctp_sendmsg(sock, (void *)write_buff, sizeof(write_buff),
- (struct sockaddr *) &remote_addr, sizeof(remote_addr),
- 0, 0, 0, 0, 0);
- if (retval < 0) {
- perror("sctp_sendmsg()");
- exit(-1);
- }
- sleep(1);
- }
- retval = close(sock);
- if (retval != 0) {
- perror("close()");
- exit(-1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment