Lines 33-39
Link Here
|
33 |
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
33 |
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
34 |
*/ |
34 |
*/ |
35 |
|
35 |
|
36 |
#define RCSID "$Id: cbcp.c,v 1.15 2003/01/17 07:23:35 fcusack Exp $" |
36 |
#define RCSID "$Id: cbcp.c,v 1.16 2004/10/28 00:15:36 paulus Exp $" |
37 |
|
37 |
|
38 |
#include <stdio.h> |
38 |
#include <stdio.h> |
39 |
#include <string.h> |
39 |
#include <string.h> |
Lines 165-171
Link Here
|
165 |
inp = inpacket; |
165 |
inp = inpacket; |
166 |
|
166 |
|
167 |
if (pktlen < CBCP_MINLEN) { |
167 |
if (pktlen < CBCP_MINLEN) { |
168 |
error("CBCP packet is too small"); |
168 |
if (debug) |
|
|
169 |
dbglog("CBCP packet is too small"); |
169 |
return; |
170 |
return; |
170 |
} |
171 |
} |
171 |
|
172 |
|
Lines 173-184
Link Here
|
173 |
GETCHAR(id, inp); |
174 |
GETCHAR(id, inp); |
174 |
GETSHORT(len, inp); |
175 |
GETSHORT(len, inp); |
175 |
|
176 |
|
176 |
#if 0 |
177 |
if (len > pktlen || len < CBCP_MINLEN) { |
177 |
if (len > pktlen) { |
178 |
if (debug) |
178 |
error("CBCP packet: invalid length"); |
179 |
dbglog("CBCP packet: invalid length %d", len); |
179 |
return; |
180 |
return; |
180 |
} |
181 |
} |
181 |
#endif |
|
|
182 |
|
182 |
|
183 |
len -= CBCP_MINLEN; |
183 |
len -= CBCP_MINLEN; |
184 |
|
184 |
|
Lines 189-199
Link Here
|
189 |
break; |
189 |
break; |
190 |
|
190 |
|
191 |
case CBCP_RESP: |
191 |
case CBCP_RESP: |
192 |
dbglog("CBCP_RESP received"); |
192 |
if (debug) |
|
|
193 |
dbglog("CBCP_RESP received"); |
193 |
break; |
194 |
break; |
194 |
|
195 |
|
195 |
case CBCP_ACK: |
196 |
case CBCP_ACK: |
196 |
if (id != us->us_id) |
197 |
if (debug && id != us->us_id) |
197 |
dbglog("id doesn't match: expected %d recv %d", |
198 |
dbglog("id doesn't match: expected %d recv %d", |
198 |
us->us_id, id); |
199 |
us->us_id, id); |
199 |
|
200 |
|
Lines 312-322
Link Here
|
312 |
|
313 |
|
313 |
address[0] = 0; |
314 |
address[0] = 0; |
314 |
|
315 |
|
315 |
while (len) { |
316 |
while (len >= 2) { |
316 |
dbglog("length: %d", len); |
317 |
dbglog("length: %d", len); |
317 |
|
318 |
|
318 |
GETCHAR(type, pckt); |
319 |
GETCHAR(type, pckt); |
319 |
GETCHAR(opt_len, pckt); |
320 |
GETCHAR(opt_len, pckt); |
|
|
321 |
if (opt_len < 2 || opt_len > len) |
322 |
break; |
320 |
|
323 |
|
321 |
if (opt_len > 2) |
324 |
if (opt_len > 2) |
322 |
GETCHAR(delay, pckt); |
325 |
GETCHAR(delay, pckt); |
Lines 348-353
Link Here
|
348 |
} |
351 |
} |
349 |
len -= opt_len; |
352 |
len -= opt_len; |
350 |
} |
353 |
} |
|
|
354 |
if (len != 0) { |
355 |
if (debug) |
356 |
dbglog("cbcp_recvreq: malformed packet (%d bytes left)", len); |
357 |
return; |
358 |
} |
351 |
|
359 |
|
352 |
cbcp_resp(us); |
360 |
cbcp_resp(us); |
353 |
} |
361 |
} |
Lines 360-365
Link Here
|
360 |
u_char buf[256]; |
368 |
u_char buf[256]; |
361 |
u_char *bufp = buf; |
369 |
u_char *bufp = buf; |
362 |
int len = 0; |
370 |
int len = 0; |
|
|
371 |
int slen; |
363 |
|
372 |
|
364 |
cb_type = us->us_allowed & us->us_type; |
373 |
cb_type = us->us_allowed & us->us_type; |
365 |
dbglog("cbcp_resp cb_type=%d", cb_type); |
374 |
dbglog("cbcp_resp cb_type=%d", cb_type); |
Lines 371-382
Link Here
|
371 |
|
380 |
|
372 |
if (cb_type & ( 1 << CB_CONF_USER ) ) { |
381 |
if (cb_type & ( 1 << CB_CONF_USER ) ) { |
373 |
dbglog("cbcp_resp CONF_USER"); |
382 |
dbglog("cbcp_resp CONF_USER"); |
|
|
383 |
slen = strlen(us->us_number); |
384 |
if (slen > 250) { |
385 |
warn("callback number truncated to 250 characters"); |
386 |
slen = 250; |
387 |
} |
374 |
PUTCHAR(CB_CONF_USER, bufp); |
388 |
PUTCHAR(CB_CONF_USER, bufp); |
375 |
len = 3 + 1 + strlen(us->us_number) + 1; |
389 |
len = 3 + 1 + slen + 1; |
376 |
PUTCHAR(len , bufp); |
390 |
PUTCHAR(len , bufp); |
377 |
PUTCHAR(5, bufp); /* delay */ |
391 |
PUTCHAR(5, bufp); /* delay */ |
378 |
PUTCHAR(1, bufp); |
392 |
PUTCHAR(1, bufp); |
379 |
BCOPY(us->us_number, bufp, strlen(us->us_number) + 1); |
393 |
BCOPY(us->us_number, bufp, slen + 1); |
380 |
cbcp_send(us, CBCP_RESP, buf, len); |
394 |
cbcp_send(us, CBCP_RESP, buf, len); |
381 |
return; |
395 |
return; |
382 |
} |
396 |
} |
Lines 438-462
Link Here
|
438 |
int opt_len; |
452 |
int opt_len; |
439 |
char address[256]; |
453 |
char address[256]; |
440 |
|
454 |
|
441 |
if (len) { |
455 |
if (len >= 2) { |
442 |
GETCHAR(type, pckt); |
456 |
GETCHAR(type, pckt); |
443 |
GETCHAR(opt_len, pckt); |
457 |
GETCHAR(opt_len, pckt); |
|
|
458 |
if (opt_len >= 2 && opt_len <= len) { |
444 |
|
459 |
|
445 |
if (opt_len > 2) |
460 |
if (opt_len > 2) |
446 |
GETCHAR(delay, pckt); |
461 |
GETCHAR(delay, pckt); |
447 |
|
462 |
|
448 |
if (opt_len > 4) { |
463 |
if (opt_len > 4) { |
449 |
GETCHAR(addr_type, pckt); |
464 |
GETCHAR(addr_type, pckt); |
450 |
memcpy(address, pckt, opt_len - 4); |
465 |
memcpy(address, pckt, opt_len - 4); |
451 |
address[opt_len - 4] = 0; |
466 |
address[opt_len - 4] = 0; |
452 |
if (address[0]) |
467 |
if (address[0]) |
453 |
dbglog("peer will call: %s", address); |
468 |
dbglog("peer will call: %s", address); |
454 |
} |
469 |
} |
455 |
if (type == CB_CONF_NO) |
470 |
if (type == CB_CONF_NO) |
456 |
return; |
471 |
return; |
457 |
} |
|
|
458 |
|
472 |
|
459 |
cbcp_up(us); |
473 |
cbcp_up(us); |
|
|
474 |
|
475 |
} else if (debug) |
476 |
dbglog("cbcp_recvack: malformed packet"); |
477 |
} |
460 |
} |
478 |
} |
461 |
|
479 |
|
462 |
/* ok peer will do callback */ |
480 |
/* ok peer will do callback */ |