OSDN Git Service

external/ppp 2.4.3
[android-x86/external-ppp.git] / pppd / plugins / pppoatm / misc.c
1 /* misc.c - Miscellaneous library functions */
2
3 /* Written 1997-2000 by Werner Almesberger, EPFL-ICA/ICA */
4
5 #if HAVE_CONFIG_H
6 #include <config.h>
7 #endif
8
9 #include <stdint.h>
10 #include <stdarg.h>
11 #include <string.h>
12 #include <sys/socket.h>
13 #include <sys/ioctl.h>
14 #include <netinet/in.h> /* for htons */
15
16 #include <atm.h>
17 #include <atmsap.h>
18
19
20 int __atmlib_fetch(const char **pos,...)
21 {
22     const char *value;
23     int ref_len,best_len,len;
24     int i,best;
25     va_list ap;
26
27     va_start(ap,pos);
28     ref_len = strlen(*pos);
29     best_len = 0;
30     best = -1;
31     for (i = 0; (value = va_arg(ap,const char *)); i++) {
32         len = strlen(value);
33         if (*value != '!' && len <= ref_len && len > best_len &&
34           !strncasecmp(*pos,value,len)) {
35             best = i;
36             best_len = len;
37         }
38     }
39     va_end(ap);
40     if (best > -1) (*pos) += best_len;
41     return best;
42 }
43
44
45 void atm_tcpip_port_mapping(char *vs_id,uint8_t protocol,uint16_t port)
46 {
47     memcpy(vs_id,ATM_FORUM_OUI "\x01",4);
48     vs_id[4] = protocol; /* e.g. IP_TCP or IP_UDP; from netinet/protocols.h */
49     vs_id[5] = (htons(port) >> 8) & 255;
50     vs_id[6] = htons(port) & 255;
51 }