Last active
January 8, 2025 00:42
-
-
Save djberg96/fa2b10e182dea2bdcdde64aac897a6cc to your computer and use it in GitHub Desktop.
Attempt at getting sctp_bindx to work
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
/* | |
sudo pkg install sctplib | |
I created two interfaces like so: | |
sudo ifconfig lo1 create | |
sudo ifconfig lo1 1.1.1.1/24 up | |
sudo ifconfig lo2 create | |
sudo ifconfig lo2 1.1.1.2/24 up | |
> ifconfig -a | |
lo1: flags=1008049<UP,LOOPBACK,RUNNING,MULTICAST,LOWER_UP> metric 0 mtu 16384 | |
options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6> | |
inet 1.1.1.1 netmask 0xffffff00 | |
inet6 fe80::1%lo1 prefixlen 64 scopeid 0x3 | |
groups: lo | |
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL> | |
lo2: flags=1008049<UP,LOOPBACK,RUNNING,MULTICAST,LOWER_UP> metric 0 mtu 16384 | |
options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6> | |
inet 1.1.1.2 netmask 0xffffff00 | |
inet6 fe80::1%lo2 prefixlen 64 scopeid 0x4 | |
groups: lo | |
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL> | |
*/ | |
#include <stdio.h> | |
#include <string.h> | |
#include <arpa/inet.h> | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <netinet/sctp.h> | |
#include <errno.h> | |
#include <unistd.h> | |
int main(){ | |
int fileno; | |
int port = 62324; | |
int domain = AF_INET; | |
int sock_type = SOCK_SEQPACKET; | |
int flag = SCTP_BINDX_ADD_ADDR; | |
struct sockaddr_in addrs[2]; | |
char* ip1 = "1.1.1.1"; | |
char* ip2 = "1.1.1.2"; | |
bzero(&addrs, sizeof(addrs)); | |
fileno = socket(domain, sock_type, IPPROTO_SCTP); | |
if(fileno < 0){ | |
printf("Socket creation failed\n"); | |
return -1; | |
} | |
addrs[0].sin_family = domain; | |
addrs[0].sin_port = htons(port); | |
addrs[0].sin_addr.s_addr = inet_addr(ip1); | |
addrs[1].sin_family = domain; | |
addrs[1].sin_port = htons(port); | |
addrs[1].sin_addr.s_addr = inet_addr(ip2); | |
// THIS FAILS, WHY? | |
// Tried this | |
/* | |
if(sctp_bindx(fileno, (struct sockaddr*)addrs, 2, flag) != 0){ | |
printf("sctp_bindx 1 failed: %s\n", strerror(errno)); | |
return -1; | |
} | |
*/ | |
// And also this | |
if(sctp_bindx(fileno, (struct sockaddr*)&addrs[0], 1, flag) != 0){ | |
printf("sctp_bindx 1 failed: %s\n", strerror(errno)); | |
return -1; | |
} | |
if(sctp_bindx(fileno, (struct sockaddr*)&addrs[1], 1, flag) != 0){ | |
printf("sctp_bindx 2 failed: %s\n", strerror(errno)); | |
return -1; | |
} | |
close(fileno); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment