18ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project/* text2atm.c - Converts textual representation of ATM address to binary 28ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project encoding */ 38ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 48ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project/* Written 1995-2000 by Werner Almesberger, EPFL-LRC/ICA */ 58ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 68ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project#if HAVE_CONFIG_H 78ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project#include <config.h> 88ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project#endif 98ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 108ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project#include <stdio.h> 118ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project#include <ctype.h> 128ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project#include <string.h> 138ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project#include <limits.h> 148ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 158ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project#include "atm.h" 168ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project#include "atmsap.h" 178ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project#include "atmres.h" 188ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 198ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 208ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Projectstatic int try_pvc(const char *text,struct sockaddr_atmpvc *addr,int flags) 218ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project{ 228ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project int part[3]; 238ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project int i; 248ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 258ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project part[0] = part[1] = part[2] = 0; 268ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project i = 0; 278ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project while (1) { 288ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!*text) return FATAL; /* empty or ends with a dot */ 298ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (i == 3) return TRY_OTHER; /* too long */ 308ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (isdigit(*text)) { 318ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (*text == '0' && isdigit(text[1])) return TRY_OTHER; 328ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project /* no leading zeroes */ 338ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project do { 348ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (part[i] > INT_MAX/10) return TRY_OTHER;/* number too big */ 358ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project part[i] = part[i]*10+*text++-'0'; 368ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 378ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project while (isdigit(*text)); 388ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project i++; 398ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!*text) break; 408ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (*text++ != '.') return TRY_OTHER; /* non-PVC character */ 418ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project continue; 428ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 438ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (*text == '*') { 448ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!(flags & T2A_WILDCARD)) return FATAL; /* not allowed */ 458ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project part[i++] = ATM_ITF_ANY; /* all *_ANY have the same value */ 468ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 478ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else { 488ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (*text != '?') return TRY_OTHER; /* invalid character */ 498ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!(flags & T2A_UNSPEC)) return FATAL; /* not allowed */ 508ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project part[i++] = ATM_VPI_UNSPEC; /* all *_UNSPEC have the same 518ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project value */ 528ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 538ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!*++text) break; 548ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (*text++ != '.') return FATAL; /* dot required */ 558ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 568ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (i < 2) return TRY_OTHER; /* no dots */ 578ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (i == 2) { 588ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project part[2] = part[1]; 598ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project part[1] = part[0]; 608ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project part[0] = 0; /* default interface */ 618ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 628ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (part[0] > SHRT_MAX || part[2] > ATM_MAX_VCI) 638ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project return TRY_OTHER; /* too big */ 648ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (part[1] > (flags & T2A_NNI ? ATM_MAX_VPI_NNI : ATM_MAX_VPI)) 658ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project return TRY_OTHER; /* too big */ 668ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (part[0] == ATM_VPI_UNSPEC) return FATAL; /* bad */ 678ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project addr->sap_family = AF_ATMPVC; 688ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project addr->sap_addr.itf = part[0]; 698ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project addr->sap_addr.vpi = part[1]; 708ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project addr->sap_addr.vci = part[2]; 718ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project return 0; 728ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project} 738ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 748ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 758ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Projectstatic int do_try_nsap(const char *text,struct sockaddr_atmsvc *addr,int flags) 768ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project{ 778ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project const char *walk; 788ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project int count,pos,dot; 798ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project int offset,len; 808ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project char value; 818ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 828ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project count = dot = 0; 838ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project for (walk = text; *walk; walk++) 848ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (isdigit(*walk)) { 858ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (count++ == 15) break; 868ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project dot = 1; 878ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 888ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else if (*text != '.') break; 898ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else if (!dot) return FATAL; /* two dots in a row */ 908ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else dot = 0; 918ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (*walk != ':') { 928ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project pos = 0; 938ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project offset = 0; 948ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 958ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else { 968ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!dot || *text == '0') return FATAL; 978ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project addr->sas_addr.prv[0] = ATM_AFI_E164; 988ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project addr->sas_addr.prv[1] = 0; 998ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project memset(addr->sas_addr.prv+1,0,8); 1008ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project for (pos = 18-count-1; *text; text++) { 1018ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (*text == '.') continue; 1028ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (*text == ':') break; 1038ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else { 1048ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (pos & 1) addr->sas_addr.prv[pos >> 1] |= *text-'0'; 1058ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else addr->sas_addr.prv[pos >> 1] = (*text-'0') << 4; 1068ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project pos++; 1078ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 1088ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 1098ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project addr->sas_addr.prv[8] |= 0xf; 1108ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project text++; 1118ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project pos++; 1128ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project offset = 72; 1138ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 1148ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project for (dot = 0; *text; text++) 1158ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (isxdigit(*text)) { 1168ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (pos == ATM_ESA_LEN*2) return TRY_OTHER; /* too long */ 1178ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project value = isdigit(*text) ? *text-'0' : (islower(*text) ? 1188ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project toupper(*text) : *text)-'A'+10; 1198ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (pos & 1) addr->sas_addr.prv[pos >> 1] |= value; 1208ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else addr->sas_addr.prv[pos >> 1] = value << 4; 1218ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project pos++; 1228ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project dot = 1; 1238ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 1248ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else 1258ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (*text == '/' && (flags & T2A_WILDCARD)) break; 1268ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else if (*text != '.') return TRY_OTHER; 1278ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else { 1288ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!dot) return FATAL; /* two dots in a row */ 1298ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project dot = 0; 1308ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 1318ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!dot) return FATAL; 1328ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (pos > 1 && !*addr->sas_addr.prv) 1338ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project return TRY_OTHER; /* no leading zeroes */ 1348ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!*text) 1358ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project return pos != ATM_ESA_LEN*2 ? TRY_OTHER : ATM_ESA_LEN*2; 1368ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project /* handle bad length */ 1378ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project len = 0; 1388ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project while (*++text) { 1398ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!isdigit(*text)) return -1; /* non-digit in length */ 1408ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (len >= pos*4) return -1; /* too long */ 1418ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project len = len*10+*text-'0'; 1428ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 1438ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (len > 7 && addr->sas_addr.prv[0] != ATM_AFI_E164) offset = 72; 1448ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (len < offset) return FATAL; 1458ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project return len > pos*4 ? TRY_OTHER : len; 1468ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project} 1478ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 1488ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 1498ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Projectstatic int try_nsap(const char *text,struct sockaddr_atmsvc *addr,int flags) 1508ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project{ 1518ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project int result; 1528ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 1538ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project result = do_try_nsap(text,addr,flags); 1548ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (result < 0) return result; 1558ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project addr->sas_family = AF_ATMSVC; 1568ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project *addr->sas_addr.pub = 0; 1578ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project return result; 1588ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project} 1598ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 1608ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 1618ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Projectstatic int try_e164(const char *text,struct sockaddr_atmsvc *addr,int flags) 1628ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project{ 1638ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project int i,dot,result; 1648ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 1658ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (*text == ':' || *text == '+') text++; 1668ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project for (i = dot = 0; *text; text++) 1678ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (isdigit(*text)) { 1688ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (i == ATM_E164_LEN) return TRY_OTHER; /* too long */ 1698ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project addr->sas_addr.pub[i++] = *text; 1708ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project dot = 1; 1718ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 1728ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else if (*text != '.') break; 1738ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else { 1748ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!dot) return TRY_OTHER; /* two dots in a row */ 1758ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project dot = 0; 1768ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 1778ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!dot) return TRY_OTHER; 1788ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project addr->sas_addr.pub[i] = 0; 1798ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project *addr->sas_addr.prv = 0; 1808ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project result = 0; 1818ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (*text) { 1828ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (*text++ != '+') return TRY_OTHER; 1838ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project else { 1848ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project result = do_try_nsap(text,addr,flags); 1858ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (result < 0) return FATAL; 1868ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 1878ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 1888ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project addr->sas_family = AF_ATMSVC; 1898ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project return result; 1908ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project} 1918ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 1928ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 1938ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Projectstatic int search(FILE *file,const char *text,struct sockaddr *addr,int length, 1948ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project int flags) 1958ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project{ 1968ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project char line[MAX_ATM_NAME_LEN+1]; 1978ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project const char *here; 1988ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project int result; 1998ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 2008ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project while (fgets(line,MAX_ATM_NAME_LEN,file)) { 2018ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!strtok(line,"\t\n ")) continue; 2028ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project while ((here = strtok(NULL,"\t\n "))) 2038ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!strcasecmp(here,text)) { 2048ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project here = strtok(line,"\t\n "); 2058ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project result = text2atm(here,addr,length,flags); 2068ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (result >= 0) return result; 2078ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 2088ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 2098ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project return TRY_OTHER; 2108ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project} 2118ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 2128ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 2138ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Projectstatic int try_name(const char *text,struct sockaddr *addr,int length, 2148ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project int flags) 2158ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project{ 2168ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project FILE *file; 2178ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project int result; 2188ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 2198ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!(file = fopen(HOSTS_ATM,"r"))) return TRY_OTHER; 2208ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project result = search(file,text,addr,length,flags); 2218ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project (void) fclose(file); 2228ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project return result; 2238ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project} 2248ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 2258ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 2268ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Projectint text2atm(const char *text,struct sockaddr *addr,int length,int flags) 2278ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project{ 2288ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project int result; 2298ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project 2308ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!*text) return -1; 2318ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!(flags & (T2A_PVC | T2A_SVC))) flags |= T2A_PVC | T2A_SVC; 2328ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (length < sizeof(struct sockaddr_atmpvc)) return -1; 2338ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (flags & T2A_PVC) { 2348ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project result = try_pvc(text,(struct sockaddr_atmpvc *) addr,flags); 2358ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (result != TRY_OTHER) return result; 2368ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 2378ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if ((flags & T2A_SVC) && length >= sizeof(struct sockaddr_atmsvc)) { 2388ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project result = try_nsap(text,(struct sockaddr_atmsvc *) addr,flags); 2398ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (result != TRY_OTHER) return result; 2408ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project result = try_e164(text,(struct sockaddr_atmsvc *) addr,flags); 2418ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (result != TRY_OTHER) return result; 2428ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project } 2438ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (!(flags & T2A_NAME)) return -1; 2448ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project result = try_name(text,addr,length,flags & ~T2A_NAME); 2458ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (result == TRY_OTHER && !(flags & T2A_LOCAL)) 2468ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project result = ans_byname(text,(struct sockaddr_atmsvc *) addr,length,flags); 2478ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project if (result != TRY_OTHER) return result; 2488ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project return -1; 2498ad0dd2a5c5f23cd210aedba72a43e48026e7436The Android Open Source Project} 250