~ubuntu-branches/ubuntu/lucid/curl/lucid-201101212007

« back to all changes in this revision

Viewing changes to lib/inet_ntop.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-02-08 11:20:41 UTC
  • mto: (3.1.1 lenny) (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: james.westby@ubuntu.com-20080208112041-hed7sb5r6ghmjf8v
Tags: upstream-7.18.0
ImportĀ upstreamĀ versionĀ 7.18.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
#else
80
80
  const char *addr = inet_ntoa(*(struct in_addr*)src);
81
81
 
82
 
  if (strlen(addr) >= size)
 
82
  if(strlen(addr) >= size)
83
83
  {
84
84
    SET_ERRNO(ENOSPC);
85
85
    return (NULL);
125
125
 
126
126
  for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
127
127
  {
128
 
    if (words[i] == 0)
 
128
    if(words[i] == 0)
129
129
    {
130
 
      if (cur.base == -1)
 
130
      if(cur.base == -1)
131
131
        cur.base = i, cur.len = 1;
132
132
      else
133
133
        cur.len++;
134
134
    }
135
 
    else if (cur.base != -1)
 
135
    else if(cur.base != -1)
136
136
    {
137
 
      if (best.base == -1 || cur.len > best.len)
 
137
      if(best.base == -1 || cur.len > best.len)
138
138
         best = cur;
139
139
      cur.base = -1;
140
140
    }
141
141
  }
142
 
  if ((cur.base != -1) && (best.base == -1 || cur.len > best.len))
 
142
  if((cur.base != -1) && (best.base == -1 || cur.len > best.len))
143
143
     best = cur;
144
 
  if (best.base != -1 && best.len < 2)
 
144
  if(best.base != -1 && best.len < 2)
145
145
     best.base = -1;
146
146
 
147
147
  /* Format the result.
151
151
  {
152
152
    /* Are we inside the best run of 0x00's?
153
153
     */
154
 
    if (best.base != -1 && i >= best.base && i < (best.base + best.len))
 
154
    if(best.base != -1 && i >= best.base && i < (best.base + best.len))
155
155
    {
156
 
      if (i == best.base)
 
156
      if(i == best.base)
157
157
         *tp++ = ':';
158
158
      continue;
159
159
    }
160
160
 
161
161
    /* Are we following an initial run of 0x00s or any real hex?
162
162
     */
163
 
    if (i != 0)
 
163
    if(i != 0)
164
164
       *tp++ = ':';
165
165
 
166
166
    /* Is this address an encapsulated IPv4?
167
167
     */
168
 
    if (i == 6 && best.base == 0 &&
 
168
    if(i == 6 && best.base == 0 &&
169
169
        (best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
170
170
    {
171
 
      if (!inet_ntop4(src+12, tp, sizeof(tmp) - (tp - tmp)))
 
171
      if(!inet_ntop4(src+12, tp, sizeof(tmp) - (tp - tmp)))
172
172
      {
173
173
        SET_ERRNO(ENOSPC);
174
174
        return (NULL);
181
181
 
182
182
  /* Was it a trailing run of 0x00's?
183
183
   */
184
 
  if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ))
 
184
  if(best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ))
185
185
     *tp++ = ':';
186
186
  *tp++ = '\0';
187
187
 
188
188
  /* Check for overflow, copy, and we're done.
189
189
   */
190
 
  if ((size_t)(tp - tmp) > size)
 
190
  if((size_t)(tp - tmp) > size)
191
191
  {
192
192
    SET_ERRNO(ENOSPC);
193
193
    return (NULL);