Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
5.2 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. //
  6. // Localization library and MessageIds.
  7. //
  8. #include <nls.h>
  9. #include <winnlsp.h>
  10. #include "localmsg.h"
  11. int
  12. filematch(
  13. char *pszfile,
  14. char **ppszpat,
  15. int cpat,
  16. int fsubdirs
  17. );
  18. typedef struct token_tmp {
  19. char *v4;
  20. char *v6;
  21. char *both;
  22. } token_t;
  23. token_t token[] = {
  24. { "AF_INET", "AF_INET6", NULL },
  25. { "PF_INET", "PF_INET6", NULL },
  26. { "in_addr", "in6_addr", NULL },
  27. { "IN_ADDR", "IN6_ADDR", NULL },
  28. { "PIN_ADDR", "PIN6_ADDR", NULL },
  29. { "LPIN_ADDR", "LPIN6_ADDR", NULL },
  30. { "IPAddr", NULL, "SOCKADDR_STORAGE" },
  31. { "sockaddr_in", "sockaddr_in6", "sockaddr_storage" },
  32. { "SOCKADDR_IN", "SOCKADDR_IN6", "SOCKADDR_STORAGE" },
  33. { "PSOCKADDR_IN", "PSOCKADDR_IN6", "PSOCKADDR_STORAGE" },
  34. { "LPSOCKADDR_IN", "LPSOCKADDR_IN6", "LPSOCKADDR_STORAGE" },
  35. { "INADDR_ANY", "in6addr_any", "getaddrinfo with nodename=NULL and AI_PASSIVE" },
  36. { "INADDR_LOOPBACK", "in6addr_loopback", NULL },
  37. { "IPPROTO_IP", "IPPROTO_IPV6", NULL },
  38. { "IP_MULTICAST_IF", "IPV6_MULTICAST_IF", NULL },
  39. { "IP_MULTICAST_TTL", "IPV6_MULTICAST_HOPS","SIO_MULTICAST_SCOPE" },
  40. { "IP_MULTICAST_LOOP", "IPV6_MULTICAST_LOOP","SIO_MULTIPOINT_LOOPBACK" },
  41. { "IP_ADD_MEMBERSHIP", "IPV6_JOIN_GROUP", "WSAJoinLeaf" },
  42. { "IP_DROP_MEMBERSHIP","IPV6_LEAVE_GROUP", NULL },
  43. { "ip_mreq", "ipv6_mreq", NULL },
  44. { "gethostbyname", NULL, "getaddrinfo" },
  45. { "hostent", NULL, "addrinfo" },
  46. { "HOSTENT", NULL, "ADDRINFO" },
  47. { "PHOSTENT", NULL, "LPADDRINFO" },
  48. { "LPHOSTENT", NULL, "LPADDRINFO" },
  49. { "inet_addr", NULL, "WSAStringToAddress or getaddrinfo with AI_NUMERICHOST"},
  50. { "gethostbyaddr", NULL, "getnameinfo" },
  51. { "inet_ntoa", NULL, "WSAAddressToString or getnameinfo with NI_NUMERICHOST"},
  52. { "IN_MULTICAST", "IN6_IS_ADDR_MULTICAST", NULL },
  53. { "IN_CLASSD", "IN6_IS_ADDR_MULTICAST", NULL },
  54. { "IP_TTL", "IPV6_UNICAST_HOPS", NULL },
  55. { "IN_CLASSA", NULL, NULL },
  56. { "IN_CLASSB", NULL, NULL },
  57. { "IN_CLASSC", NULL, NULL },
  58. { "INADDR_BROADCAST", NULL, NULL },
  59. { "WSAAsyncGetHostByAddr", NULL, "getnameinfo" },
  60. { "WSAAsyncGetHostByName", NULL, "getaddrinfo" },
  61. { NULL, NULL, NULL },
  62. };
  63. void
  64. process_line(filename, lineno, str)
  65. char *filename;
  66. int lineno;
  67. char *str;
  68. {
  69. int i, len;
  70. char *p;
  71. for (i=0; token[i].v4 != NULL; i++) {
  72. p = strstr(str, token[i].v4);
  73. if (p == NULL)
  74. continue;
  75. if (p>str && (isalnum(p[-1]) || p[-1] == '_'))
  76. continue; /* not the start of a token */
  77. len = strlen(token[i].v4);
  78. if (isalnum(p[len]) || p[len] == '_')
  79. continue; /* not the end of a token */
  80. NlsPutMsg(STDOUT, CHECKV4_MESSAGE_0, filename, lineno, token[i].v4);
  81. // printf("%s(%d) : %s : ", filename, lineno, token[i].v4);
  82. if (token[i].both) {
  83. NlsPutMsg(STDOUT, CHECKV4_MESSAGE_1, token[i].both);
  84. // printf("use %s instead", token[i].both);
  85. }
  86. if (token[i].v6) {
  87. if (token[i].both)
  88. NlsPutMsg(STDOUT, CHECKV4_MESSAGE_2);
  89. // printf(", or ");
  90. NlsPutMsg(STDOUT, CHECKV4_MESSAGE_3, token[i].v6);
  91. // printf("use %s in addition for IPv6 support", token[i].v6);
  92. }
  93. if (!token[i].both && !token[i].v6) {
  94. NlsPutMsg(STDOUT, CHECKV4_MESSAGE_4);
  95. // printf("valid for IPv4-only");
  96. }
  97. NlsPutMsg(STDOUT, CHECKV4_MESSAGE_5);
  98. // printf("\n");
  99. }
  100. }
  101. void
  102. process_file(filename)
  103. char *filename;
  104. {
  105. FILE *fp;
  106. char buff[1024];
  107. int lineno;
  108. fp = fopen(filename, "r");
  109. if (fp == NULL) {
  110. NlsPutMsg(STDOUT, CHECKV4_MESSAGE_6, filename);
  111. // printf("%s: cannot open file\n", filename);
  112. return;
  113. }
  114. lineno = 0;
  115. while (fgets(buff, sizeof(buff), fp)) {
  116. lineno++;
  117. process_line(filename, lineno, buff);
  118. }
  119. fclose(fp);
  120. }
  121. int
  122. __cdecl
  123. main(argc, argv)
  124. int argc;
  125. char **argv;
  126. {
  127. int i;
  128. int recurse = 0;
  129. char szfile[MAX_PATH];
  130. //
  131. // This will ensure the correct language message is displayed when
  132. // NlsPutMsg is called.
  133. //
  134. SetThreadUILanguage(0);
  135. argc--;
  136. argv++;
  137. if (argc>0) {
  138. if (!_stricmp(argv[0], "/s")) {
  139. recurse = 1;
  140. argc--;
  141. argv++;
  142. } else if (!_stricmp(argv[0], "/?")) {
  143. NlsPutMsg(STDOUT, CHECKV4_USAGE);
  144. return 1;
  145. }
  146. }
  147. if (argc < 1) {
  148. NlsPutMsg(STDOUT, CHECKV4_MESSAGE_7);
  149. return 1;
  150. }
  151. while (filematch(szfile,argv,argc,recurse) >= 0) {
  152. process_file(szfile);
  153. }
  154. return 0;
  155. }