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

« back to all changes in this revision

Viewing changes to lib/inet_pton.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:
108
108
  octets = 0;
109
109
  tp = tmp;
110
110
  *tp = 0;
111
 
  while ((ch = *src++) != '\0') {
 
111
  while((ch = *src++) != '\0') {
112
112
    const char *pch;
113
113
 
114
 
    if ((pch = strchr(digits, ch)) != NULL) {
 
114
    if((pch = strchr(digits, ch)) != NULL) {
115
115
      unsigned int val = *tp * 10 + (unsigned int)(pch - digits);
116
116
 
117
 
      if (val > 255)
 
117
      if(val > 255)
118
118
        return (0);
119
119
      *tp = (unsigned char)val;
120
 
      if (! saw_digit) {
121
 
        if (++octets > 4)
 
120
      if(! saw_digit) {
 
121
        if(++octets > 4)
122
122
          return (0);
123
123
        saw_digit = 1;
124
124
      }
125
 
    } else if (ch == '.' && saw_digit) {
126
 
      if (octets == 4)
 
125
    }
 
126
    else if(ch == '.' && saw_digit) {
 
127
      if(octets == 4)
127
128
        return (0);
128
129
      *++tp = 0;
129
130
      saw_digit = 0;
130
 
    } else
 
131
    }
 
132
    else
131
133
      return (0);
132
134
  }
133
 
  if (octets < 4)
 
135
  if(octets < 4)
134
136
    return (0);
135
137
  /* bcopy(tmp, dst, INADDRSZ); */
136
138
  memcpy(dst, tmp, INADDRSZ);
165
167
  endp = tp + IN6ADDRSZ;
166
168
  colonp = NULL;
167
169
  /* Leading :: requires some special handling. */
168
 
  if (*src == ':')
169
 
    if (*++src != ':')
 
170
  if(*src == ':')
 
171
    if(*++src != ':')
170
172
      return (0);
171
173
  curtok = src;
172
174
  saw_xdigit = 0;
173
175
  val = 0;
174
 
  while ((ch = *src++) != '\0') {
 
176
  while((ch = *src++) != '\0') {
175
177
    const char *pch;
176
178
 
177
 
    if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
 
179
    if((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
178
180
      pch = strchr((xdigits = xdigits_u), ch);
179
 
    if (pch != NULL) {
 
181
    if(pch != NULL) {
180
182
      val <<= 4;
181
183
      val |= (pch - xdigits);
182
 
      if (val > 0xffff)
 
184
      if(val > 0xffff)
183
185
        return (0);
184
186
      saw_xdigit = 1;
185
187
      continue;
186
188
    }
187
 
    if (ch == ':') {
 
189
    if(ch == ':') {
188
190
      curtok = src;
189
 
      if (!saw_xdigit) {
190
 
        if (colonp)
 
191
      if(!saw_xdigit) {
 
192
        if(colonp)
191
193
          return (0);
192
194
        colonp = tp;
193
195
        continue;
194
196
      }
195
 
      if (tp + INT16SZ > endp)
 
197
      if(tp + INT16SZ > endp)
196
198
        return (0);
197
199
      *tp++ = (unsigned char) (val >> 8) & 0xff;
198
200
      *tp++ = (unsigned char) val & 0xff;
200
202
      val = 0;
201
203
      continue;
202
204
    }
203
 
    if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
 
205
    if(ch == '.' && ((tp + INADDRSZ) <= endp) &&
204
206
        inet_pton4(curtok, tp) > 0) {
205
207
      tp += INADDRSZ;
206
208
      saw_xdigit = 0;
208
210
    }
209
211
    return (0);
210
212
  }
211
 
  if (saw_xdigit) {
212
 
    if (tp + INT16SZ > endp)
 
213
  if(saw_xdigit) {
 
214
    if(tp + INT16SZ > endp)
213
215
      return (0);
214
216
    *tp++ = (unsigned char) (val >> 8) & 0xff;
215
217
    *tp++ = (unsigned char) val & 0xff;
216
218
  }
217
 
  if (colonp != NULL) {
 
219
  if(colonp != NULL) {
218
220
    /*
219
221
     * Since some memmove()'s erroneously fail to handle
220
222
     * overlapping regions, we'll do the shift by hand.
228
230
    }
229
231
    tp = endp;
230
232
  }
231
 
  if (tp != endp)
 
233
  if(tp != endp)
232
234
    return (0);
233
235
  /* bcopy(tmp, dst, IN6ADDRSZ); */
234
236
  memcpy(dst, tmp, IN6ADDRSZ);