Created
January 9, 2025 23:58
-
-
Save djberg96/110ab882478984188f7e7a2746a42f64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cc -o sendv_client sendv_client.c | |
// Run after starting recvv_server in another console | |
#include <stdio.h> | |
#include <string.h> | |
#include <errno.h> | |
#include <arpa/inet.h> | |
#include <netinet/sctp.h> | |
#include <unistd.h> | |
#define IOV_MAX (sysconf(_SC_IOV_MAX)) | |
int main(){ | |
int fileno, num_ip; | |
ssize_t num_bytes; | |
struct iovec iov[IOV_MAX]; | |
struct sctp_sendv_spa spa; | |
struct sockaddr_in addrs[2]; | |
sctp_assoc_t assoc; | |
bzero(&iov, sizeof(iov)); | |
bzero(&spa, sizeof(spa)); | |
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_connectx(fileno, (struct sockaddr *)&addrs, 2, &assoc) < 0){ | |
printf("sctp_connectx failed: %s\n", strerror(errno)); | |
close(fileno); | |
return -1; | |
} | |
spa.sendv_sndinfo.snd_flags = SCTP_UNORDERED; | |
//spa.sendv_sndinfo.snd_assoc_id = 1; | |
iov[0].iov_base = "hello"; | |
iov[0].iov_len = 5; | |
iov[1].iov_base = "world"; | |
iov[1].iov_len = 5; | |
num_bytes = sctp_sendv( | |
fileno, | |
iov, | |
2, | |
(struct sockaddr*)&addrs, | |
2, | |
&spa, | |
sizeof(spa), | |
SCTP_SENDV_SPA, | |
0 | |
); | |
if(num_bytes < 0){ | |
printf("sctp_sendv failed: %s\n", strerror(errno)); | |
close(fileno); | |
return -1; | |
} | |
else{ | |
printf("Sent %li bytes.\n", num_bytes); | |
} | |
close(fileno); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment