~ubuntu-branches/ubuntu/utopic/curl/utopic-updates

« back to all changes in this revision

Viewing changes to lib/inet_ntop.c

  • Committer: Bazaar Package Importer
  • Author(s): James Page
  • Date: 2011-10-20 09:28:24 UTC
  • mfrom: (3.4.22 sid)
  • Revision ID: james.westby@ubuntu.com-20111020092824-i7kfjd5we7dh57nv
Tags: 7.21.7-3ubuntu1
* Merge from Debian testing, remaining changes:
  - Drop dependencies not in main:
    + Build-Depends: Drop stunnel and libssh2-1-dev.
    + Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.
  - Add new libcurl3-udeb package, stripped down for use during 
    installation (LP: #831496).
* Dropped changes:
  - debian/patches/timeout_bug_736216: applied upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
          ((int)((unsigned char)src[3])) & 0xff);
70
70
 
71
71
  len = strlen(tmp);
72
 
  if(len == 0 || len >= size)
73
 
  {
 
72
  if(len == 0 || len >= size) {
74
73
    SET_ERRNO(ENOSPC);
75
74
    return (NULL);
76
75
  }
105
104
   *  Find the longest run of 0x00's in src[] for :: shorthanding.
106
105
   */
107
106
  memset(words, '\0', sizeof(words));
108
 
  for (i = 0; i < IN6ADDRSZ; i++)
109
 
      words[i/2] |= (src[i] << ((1 - (i % 2)) << 3));
 
107
  for(i = 0; i < IN6ADDRSZ; i++)
 
108
    words[i/2] |= (src[i] << ((1 - (i % 2)) << 3));
110
109
 
111
110
  best.base = -1;
112
111
  cur.base  = -1;
113
112
  best.len = 0;
114
113
  cur.len = 0;
115
114
 
116
 
  for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
117
 
  {
118
 
    if(words[i] == 0)
119
 
    {
 
115
  for(i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
 
116
    if(words[i] == 0) {
120
117
      if(cur.base == -1)
121
118
        cur.base = i, cur.len = 1;
122
119
      else
123
120
        cur.len++;
124
121
    }
125
 
    else if(cur.base != -1)
126
 
    {
 
122
    else if(cur.base != -1) {
127
123
      if(best.base == -1 || cur.len > best.len)
128
 
         best = cur;
 
124
        best = cur;
129
125
      cur.base = -1;
130
126
    }
131
127
  }
132
128
  if((cur.base != -1) && (best.base == -1 || cur.len > best.len))
133
 
     best = cur;
 
129
    best = cur;
134
130
  if(best.base != -1 && best.len < 2)
135
 
     best.base = -1;
136
 
 
137
 
  /* Format the result.
138
 
   */
 
131
    best.base = -1;
 
132
  /* Format the result. */
139
133
  tp = tmp;
140
 
  for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
141
 
  {
142
 
    /* Are we inside the best run of 0x00's?
143
 
     */
144
 
    if(best.base != -1 && i >= best.base && i < (best.base + best.len))
145
 
    {
 
134
  for(i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
 
135
    /* Are we inside the best run of 0x00's? */
 
136
    if(best.base != -1 && i >= best.base && i < (best.base + best.len)) {
146
137
      if(i == best.base)
147
 
         *tp++ = ':';
 
138
        *tp++ = ':';
148
139
      continue;
149
140
    }
150
141
 
151
142
    /* Are we following an initial run of 0x00s or any real hex?
152
143
     */
153
144
    if(i != 0)
154
 
       *tp++ = ':';
 
145
      *tp++ = ':';
155
146
 
156
147
    /* Is this address an encapsulated IPv4?
157
148
     */
158
149
    if(i == 6 && best.base == 0 &&
159
 
        (best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
160
 
    {
161
 
      if(!inet_ntop4(src+12, tp, sizeof(tmp) - (tp - tmp)))
162
 
      {
 
150
        (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
 
151
      if(!inet_ntop4(src+12, tp, sizeof(tmp) - (tp - tmp))) {
163
152
        SET_ERRNO(ENOSPC);
164
153
        return (NULL);
165
154
      }
177
166
 
178
167
  /* Check for overflow, copy, and we're done.
179
168
   */
180
 
  if((size_t)(tp - tmp) > size)
181
 
  {
 
169
  if((size_t)(tp - tmp) > size) {
182
170
    SET_ERRNO(ENOSPC);
183
171
    return (NULL);
184
172
  }