Fossil

Check-in [beea5987]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the URL parser so that it is able to handle IPv6 addresses. Fixes to the IPv6 client-side code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ipv6
Files: files | file ages | folders
SHA1:beea59873ab1863a625bd31c0beaff8b04adc937
User & Date: drh 2012-07-07 13:32:12
Context
2012-07-07
14:07
Update the inetd handler so that it works with IPv6. check-in: 89fb4142 user: drh tags: ipv6
13:32
Fix the URL parser so that it is able to handle IPv6 addresses. Fixes to the IPv6 client-side code. check-in: beea5987 user: drh tags: ipv6
2012-07-05
21:25
Work toward getting Fossil to be able to sync over IPV6. This check-in compiles, but we do not yet have a server to test it on. check-in: 0268e771 user: drh tags: ipv6
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/http_socket.c.

39
40
41
42
43
44
45

46
47
48
49
50
51
52
...
151
152
153
154
155
156
157

158



159
160
161
162
163
164
165
166

167
168
169
170

171
172
173
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
#  include <arpa/inet.h>
#  include <sys/socket.h>
#  include <netdb.h>
#endif
#include <assert.h>
#include <sys/types.h>
#include <signal.h>


/*
** There can only be a single socket connection open at a time.
** State information about that socket is stored in the following
** local variables:
*/
static int socketIsInit = 0;    /* True after global initialization */
................................................................................
    sHints.ai_family = AF_UNSPEC;
    sHints.ai_socktype = SOCK_STREAM;
    sHints.ai_flags = 0;
    sHints.ai_protocol = 0;
    sqlite3_snprintf(sizeof(zPort), zPort, "%d", g.urlPort);
    rc = getaddrinfo(g.urlName, zPort, &sHints, &p);
    if( rc!=0 ){

      fossil_error("getaddrinfo: %s", gai_strerror(rc));



    }
    addrIsInit = 1;
  }

  while( p ){
    char zHost[NI_MAXHOST];
    iSocket = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
    if( iSocket<0 ){

      p = p->ai_next;
      continue;
    }
    if( connect(iSocket, p->ai_addr, p->ai_addrlen)<0 ){

      p = p->ai_next;
      socket_close();
      continue;
    }
    p->ai_next = 0;
    if( getnameinfo(p->ai_addr, p->ai_addrlen, zHost, sizeof(zHost),
                    0, 0, NI_NUMERICHOST)==0 ){
      g.zIpAddr = mprintf("%s", zHost);
    }else{
      fossil_fatal("cannot find numeric host IP address");
    }

  }
  if( p==0 ){
    socket_set_errmsg("cannot create a socket");
    return 1;
  }
#if !defined(_WIN32)
  signal(SIGPIPE, SIG_IGN);







>







 







>
|
>
>
>








>




>











>







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#  include <arpa/inet.h>
#  include <sys/socket.h>
#  include <netdb.h>
#endif
#include <assert.h>
#include <sys/types.h>
#include <signal.h>
#include <errno.h>

/*
** There can only be a single socket connection open at a time.
** State information about that socket is stored in the following
** local variables:
*/
static int socketIsInit = 0;    /* True after global initialization */
................................................................................
    sHints.ai_family = AF_UNSPEC;
    sHints.ai_socktype = SOCK_STREAM;
    sHints.ai_flags = 0;
    sHints.ai_protocol = 0;
    sqlite3_snprintf(sizeof(zPort), zPort, "%d", g.urlPort);
    rc = getaddrinfo(g.urlName, zPort, &sHints, &p);
    if( rc!=0 ){
      fossil_fatal("getaddrinfo(\"%s\",\"%s\",...): %s",
                   g.urlName, zPort, gai_strerror(rc));
    }
    if( p==0 ){
      fossil_fatal("no IP addresses returned by getaddrinfo()");
    }
    addrIsInit = 1;
  }

  while( p ){
    char zHost[NI_MAXHOST];
    iSocket = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
    if( iSocket<0 ){
      fossil_warning("socket() failed: %s", strerror(errno));
      p = p->ai_next;
      continue;
    }
    if( connect(iSocket, p->ai_addr, p->ai_addrlen)<0 ){
      fossil_warning("connect() failed: %s", strerror(errno));
      p = p->ai_next;
      socket_close();
      continue;
    }
    p->ai_next = 0;
    if( getnameinfo(p->ai_addr, p->ai_addrlen, zHost, sizeof(zHost),
                    0, 0, NI_NUMERICHOST)==0 ){
      g.zIpAddr = mprintf("%s", zHost);
    }else{
      fossil_fatal("cannot find numeric host IP address");
    }
    break;
  }
  if( p==0 ){
    socket_set_errmsg("cannot create a socket");
    return 1;
  }
#if !defined(_WIN32)
  signal(SIGPIPE, SIG_IGN);

Changes to src/url.c.

99
100
101
102
103
104
105


106



107





108
109
110
111
112
113
114
      }else{
        zLogin = mprintf("%t@", g.urlUser);
      }
      for(j=i+1; (c=zUrl[j])!=0 && c!='/' && c!=':'; j++){}
      g.urlName = mprintf("%.*s", j-i-1, &zUrl[i+1]);
      i = j;
    }else{


      for(i=iStart; (c=zUrl[i])!=0 && c!='/' && c!=':'; i++){}



      g.urlName = mprintf("%.*s", i-iStart, &zUrl[iStart]);





      zLogin = mprintf("");
    }
    url_tolower(g.urlName);
    if( c==':' ){
      g.urlPort = 0;
      i++;
      while( (c = zUrl[i])!=0 && fossil_isdigit(c) ){







>
>
|
>
>
>

>
>
>
>
>







99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
      }else{
        zLogin = mprintf("%t@", g.urlUser);
      }
      for(j=i+1; (c=zUrl[j])!=0 && c!='/' && c!=':'; j++){}
      g.urlName = mprintf("%.*s", j-i-1, &zUrl[i+1]);
      i = j;
    }else{
      int inSquare = 0;
      int n;
      for(i=iStart; (c=zUrl[i])!=0 && c!='/' && (inSquare || c!=':'); i++){
        if( c=='[' ) inSquare = 1;
        if( c==']' ) inSquare = 0;
      }
      g.urlName = mprintf("%.*s", i-iStart, &zUrl[iStart]);
      n = strlen(g.urlName);
      if( g.urlName[0]=='[' && n>2 && g.urlName[n-1]==']' ){
        g.urlName++;
        g.urlName[n-2] = 0;
      }
      zLogin = mprintf("");
    }
    url_tolower(g.urlName);
    if( c==':' ){
      g.urlPort = 0;
      i++;
      while( (c = zUrl[i])!=0 && fossil_isdigit(c) ){