Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <linux/tcp.h>
  4. #include <linux/socket.h>
  5. #include <linux/types.h>
  6. #include <sys/types.h>
  7. #include <sys/socket.h>
  8. #include <unistd.h>
  9. #include <netinet/in.h>
  10. #include <arpa/inet.h>
  11. #include <netdb.h>
  12.  
  13. /*
  14.  *  Defines the different buffer and addresses
  15.  *  DISTANT_IP is the IP of a distant server (multipath-tcp.org)
  16.  *  which supports MPTCP
  17.  *  LOCAL_IP# is the (local) IP of one of the internet interface
  18.  *  of the RPI
  19.  */
  20. #define MAXBUF 512
  21. #define DISTANT_IP "130.104.230.45"
  22.  
  23. int main(int argc, char **argv)
  24. {
  25.     // Makes a new TCP socket
  26.     int sockfd;
  27.     if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
  28.         perror("Socket");
  29.         exit(EXIT_FAILURE);
  30.     }
  31.  
  32.     struct sockaddr_in addr;
  33.    
  34.     // Binds
  35.     //      Do not bind: we want the path manager to establish two subflows (if possible)
  36.    
  37.     // Connects to the server
  38.     //     Sets the address
  39.     bzero(&addr, sizeof(addr));
  40.     addr.sin_family = AF_INET;
  41.     addr.sin_port = htons(80);
  42.     if (inet_aton(DISTANT_IP, &addr.sin_addr.s_addr) == 0) {
  43.         perror("inet_aton ");
  44.         exit(EXIT_FAILURE);
  45.     }
  46.  
  47.     //     Makes the connexion
  48.     if (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
  49.         perror("Connect ");
  50.         exit(EXIT_FAILURE);
  51.     }
  52.    
  53.     // List subflows
  54.    
  55.     int i;
  56.     unsigned int optlen;
  57.     struct mptcp_sub_ids *ids;
  58.  
  59.     optlen = 42;
  60.     ids = malloc(optlen);
  61.  
  62.     int res = getsockopt(sockfd, IPPROTO_TCP, MPTCP_GET_SUB_IDS, ids, &optlen);
  63.     if(res < 0){
  64.         perror("Listing subflows: ");
  65.     }
  66.  
  67.     for(i = 0; i < ids->sub_count; i++){
  68.         printf("Subflow id : %i\n",  ids->sub_status[i].id);
  69.         if(i == 0){
  70.             // Close the first subflow
  71.             struct mptcp_close_sub_id command = {ids->sub_status[i].id};
  72.             optlen = sizeof(command);
  73.             res = setsockopt(sockfd, IPPROTO_TCP, MPTCP_CLOSE_SUB_ID, &command, optlen);
  74.            
  75.             if(res < 0){
  76.                 perror("Closing subflow");
  77.             }
  78.            
  79.         }
  80.     }
  81.     return EXIT_SUCCESS;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement