ca_dump_shm.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright [2021] JD.com, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. #include <stdio.h>
  18. #include "app_client_set.h"
  19. int main(int argc, char **argv)
  20. {
  21. if (argc < 2) {
  22. dump_ca_shm();
  23. } else {
  24. int bid = atoi(argv[1]);
  25. uint64_t version = 0;
  26. get_version(&version);
  27. IP_ROUTE route;
  28. int ret = get_ip_route(bid, &route);
  29. if (ret < 0) {
  30. printf("get ip route error %d\n", ret);
  31. return -1;
  32. }
  33. IP_NODE *ips =
  34. (IP_NODE *)malloc(sizeof(IP_NODE) * route.ip_num);
  35. IP_NODE *head_ips = ips;
  36. int ip_num = route.ip_num;
  37. memcpy(ips, route.ip_list, sizeof(IP_NODE) * route.ip_num);
  38. free_ip_route(&route);
  39. if (ret >= 0) {
  40. printf("bid=[%d] count=[%d] timestamp=[%lu]\n", bid,
  41. ip_num, version);
  42. int i = 0;
  43. for (; i < ip_num; ++i) {
  44. printf("bid=%dip=%sport=%dstatus=%dweight=%d\n",
  45. ips->bid, ips->ip, ips->port,
  46. ips->status, ips->weight);
  47. ips += 1;
  48. }
  49. } else {
  50. if (head_ips) {
  51. free(head_ips);
  52. head_ips = NULL;
  53. ips = NULL;
  54. }
  55. printf("can not find bid=[%d] ip list\n", bid);
  56. }
  57. if (head_ips) {
  58. free(head_ips);
  59. head_ips = NULL;
  60. ips = NULL;
  61. }
  62. }
  63. return 0;
  64. }