Skip to content

Instantly share code, notes, and snippets.

@djberg96
Last active January 10, 2025 00:00
Show Gist options
  • Save djberg96/c57b9bf58de5e9353a099df99a60a03a to your computer and use it in GitHub Desktop.
Save djberg96/c57b9bf58de5e9353a099df99a60a03a to your computer and use it in GitHub Desktop.
// cc -o recvv_server
// Then run it.
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <netinet/sctp.h>
#include <unistd.h>
int main(){
int fileno, flags, on;
ssize_t num_bytes;
uint infotype;
socklen_t infolen;
struct iovec iov[1];
struct sctp_rcvinfo rcvinfo;
struct sockaddr_in addrs[2];
char buffer[1024];
bzero(&iov, sizeof(iov));
bzero(&rcvinfo, sizeof(rcvinfo));
bzero(&buffer, sizeof(buffer));
bzero(&addrs, sizeof(addrs));
iov->iov_base = buffer;
iov->iov_len = sizeof(buffer);
fileno = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
if(fileno < 0){
printf("socket() failed: %s\n", strerror(errno));
return -1;
}
addrs[0].sin_family = AF_INET;
addrs[0].sin_port = htons(62324);
addrs[0].sin_addr.s_addr = inet_addr("1.1.1.1");
addrs[0].sin_len = sizeof(struct sockaddr_in);
addrs[1].sin_family = AF_INET;
addrs[1].sin_port = htons(62324);
addrs[1].sin_addr.s_addr = inet_addr("1.1.1.2");
addrs[1].sin_len = sizeof(struct sockaddr_in);
if(sctp_bindx(fileno, (struct sockaddr*)&addrs, 2, SCTP_BINDX_ADD_ADDR) != 0){
printf("sctp_bindx failed: %s\n", strerror(errno));
close(fileno);
return -1;
}
flags = 0;
on = 1;
if(setsockopt(fileno, IPPROTO_SCTP, SCTP_RECVRCVINFO, &on, sizeof(on)) < 0){
close(fileno);
printf("setsockopt failed: %s\n", strerror(errno));
return -1;
}
infolen = sizeof(struct sctp_rcvinfo);
infotype = 0;
while(1){
printf("IN THE LOOP\n");
// Doesn't appear to get past this line. No errors, just nothing.
num_bytes = sctp_recvv(fileno, iov, 1, NULL, NULL, &rcvinfo, &infolen, &infotype, &flags);
if(infotype != SCTP_RECVV_RCVINFO){
printf("Hm, didn't get the infotype we expected.\n");
}
if(num_bytes < 0){
close(fileno);
printf("sctp_recvv failed: %s\n", strerror(errno));
return -1;
}
else{
printf("Got %li bytes!\n", num_bytes);
printf("Received: %s\n", (char*)iov->iov_base);
}
}
close(fileno);
printf("DONE\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment