Attachment 'patch-MCCTCP.cpp.diff'

Download

   1 --- MCCTCP.cpp.orig	2008-02-13 10:24:35.000000000 +0100
   2 +++ MCCTCP.cpp	2008-02-13 18:51:30.000000000 +0100
   3 @@ -39,6 +39,7 @@
   4  #include <sys/socket.h>
   5  #include <arpa/inet.h>
   6  #include <netinet/in.h>
   7 +#include <netdb.h>
   8  #include <errno.h>
   9  #define ErrNo errno
  10  #endif
  11 @@ -84,33 +85,73 @@
  12          return;
  13      }
  14  #endif
  15 +    /* IPv6  compatibility functions */
  16 +    struct addrinfo gaihints, *gaires;
  17 +    int gaierror;
  18 +    char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
  19 +
  20      for(int i = 0;;++i) {
  21          XMLNode l = (*cfg)["Listen"][i];
  22          if(!l) break;
  23          std::string port_s = l["Port"];
  24 -        if(port_s.empty()) {
  25 -            logger.msg(Arc::WARNING, "Missing Port in Listen element");
  26 +        std::string port6_s = l["Port6"];
  27 +        if(port_s.empty() && port6_s.empty()) {
  28 +            logger.msg(Arc::WARNING, "Missing Port or Port6 in Listen element");
  29 +            continue;
  30 +        };
  31 +
  32 +        /* address independent handling of listeining sockets*/
  33 +        memset(&gaihints, 0, sizeof(gaihints));
  34 +	gaihints.ai_socktype = SOCK_STREAM;
  35 +	gaihints.ai_flags = AI_PASSIVE;
  36 +	if (port6_s.empty()) { /* no port6 */
  37 +		gaihints.ai_family = AF_INET;
  38 +		strlcpy(sbuf,port_s.c_str(),NI_MAXSERV);
  39 +	} else { /* port6 */
  40 +		gaihints.ai_family = AF_INET6;
  41 +		strlcpy(sbuf,port6_s.c_str(),NI_MAXSERV);
  42 +	}
  43 +
  44 +	/* we are making assumption that getaddrinfo() return only */
  45 +        /* one server socket per address famility */
  46 +	gaierror = getaddrinfo (NULL, sbuf, &gaihints, &gaires);
  47 +	if (gaierror) {
  48 +	    logger.msg(Arc::WARNING, "Failed to call getaddrinfo ");
  49              continue;
  50          };
  51 -        int port = atoi(port_s.c_str());
  52 -        int s = ::socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
  53 +		
  54 +
  55 +        int s = ::socket(gaires->ai_family,gaires->ai_socktype,gaires->ai_protocol);
  56          if(s == -1) {
  57  	    logger.msg(Arc::WARNING, "Failed to create socket");
  58              continue;
  59          };
  60 -        struct sockaddr_in myaddr;
  61 -        memset(&myaddr,0,sizeof(myaddr));
  62 -        myaddr.sin_family=AF_INET;
  63 -        myaddr.sin_port=htons(port);
  64 -        myaddr.sin_addr.s_addr=INADDR_ANY;
  65 -        if(bind(s,(struct sockaddr *)&myaddr,sizeof(myaddr)) == -1) {
  66 +/* handle IPv6 wildcard sockets properly */
  67 +#ifdef IPV6_V6ONLY
  68 +	const int on = 1;
  69 +        if (gaires->ai_family == AF_INET6 &&
  70 +                    setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on,
  71 +                    sizeof(on)) < 0) {
  72 +	    		logger.msg(Arc::WARNING, "Failed to set IPv6 only the socket");
  73 +                        continue;
  74 +                }
  75 +#endif
  76 +	/* bind the necessary passive socket */
  77 +
  78 +        if(bind(s,gaires->ai_addr,gaires->ai_addrlen) == -1) {
  79  	    logger.msg(Arc::WARNING, "Failed to bind socket");
  80              continue;
  81          };
  82 +	getnameinfo(gaires->ai_addr, gaires->ai_addrlen, hbuf,
  83 +                    sizeof(hbuf), sbuf, sizeof(sbuf),
  84 +                    NI_NUMERICHOST | NI_NUMERICSERV);
  85 +	logger.msg(Arc::INFO, "Trying to listening %s port %s\n", hbuf, sbuf);
  86 +
  87          if(::listen(s,-1) == -1) {
  88  	    logger.msg(Arc::WARNING, "Failed to listen on socket");
  89              continue;
  90          };
  91 +	freeaddrinfo(gaires);
  92          handles_.push_back(s);
  93      };
  94      if(handles_.size() == 0) {

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-02-13 18:46:41, 3.2 KB) [[attachment:patch-MCCTCP.cpp.diff]]
  • [get | view] (2008-02-13 18:47:03, 3.0 KB) [[attachment:patch-PayloadTCPSocket.cpp.diff]]
  • [get | view] (2008-02-13 18:47:38, 1.4 KB) [[attachment:service.xml]]
  • [get | view] (2008-02-13 18:59:44, 9.1 KB) [[attachment:service_script.txt]]
  • [get | view] (2008-02-13 19:08:19, 3.3 KB) [[attachment:test_client_ipv4.cpp]]
  • [get | view] (2008-02-13 18:54:28, 3.3 KB) [[attachment:test_client_ipv6.cpp]]
  • [get | view] (2008-02-13 18:53:03, 25.6 KB) [[attachment:test_service_netstat.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.