Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <linux/tcp.h>
- #include <linux/socket.h>
- #include <linux/types.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <unistd.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <netdb.h>
- /*
- * Defines the different buffer and addresses
- * DISTANT_IP is the IP of a distant server (multipath-tcp.org)
- * which supports MPTCP
- * LOCAL_IP# is the (local) IP of one of the internet interface
- * of the RPI
- */
- #define MAXBUF 512
- #define DISTANT_IP "130.104.230.45"
- int main(int argc, char **argv)
- {
- // Makes a new TCP socket
- int sockfd;
- if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- perror("Socket");
- exit(EXIT_FAILURE);
- }
- struct sockaddr_in addr;
- // Binds
- // Do not bind: we want the path manager to establish two subflows (if possible)
- // Connects to the server
- // Sets the address
- bzero(&addr, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(80);
- if (inet_aton(DISTANT_IP, &addr.sin_addr.s_addr) == 0) {
- perror("inet_aton ");
- exit(EXIT_FAILURE);
- }
- // Makes the connexion
- if (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
- perror("Connect ");
- exit(EXIT_FAILURE);
- }
- // List subflows
- int i;
- unsigned int optlen;
- struct mptcp_sub_ids *ids;
- optlen = 42;
- ids = malloc(optlen);
- int res = getsockopt(sockfd, IPPROTO_TCP, MPTCP_GET_SUB_IDS, ids, &optlen);
- if(res < 0){
- perror("Listing subflows: ");
- }
- for(i = 0; i < ids->sub_count; i++){
- printf("Subflow id : %i\n", ids->sub_status[i].id);
- if(i == 0){
- // Close the first subflow
- struct mptcp_close_sub_id command = {ids->sub_status[i].id};
- optlen = sizeof(command);
- res = setsockopt(sockfd, IPPROTO_TCP, MPTCP_CLOSE_SUB_ID, &command, optlen);
- if(res < 0){
- perror("Closing subflow");
- }
- }
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement