ll_proto.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * ll_proto.c
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. *
  10. * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  11. */
  12. #include "libbb.h"
  13. #include "rt_names.h"
  14. #include "utils.h"
  15. #if defined(__GLIBC__) && __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1
  16. #include <net/ethernet.h>
  17. #else
  18. #include <linux/if_ether.h>
  19. #endif
  20. #define __PF(f,n) { ETH_P_##f, #n },
  21. static struct {
  22. int id;
  23. char *name;
  24. } llproto_names[] = {
  25. __PF(LOOP,loop)
  26. __PF(PUP,pup)
  27. #ifdef ETH_P_PUPAT
  28. __PF(PUPAT,pupat)
  29. #endif
  30. __PF(IP,ip)
  31. __PF(X25,x25)
  32. __PF(ARP,arp)
  33. __PF(BPQ,bpq)
  34. #ifdef ETH_P_IEEEPUP
  35. __PF(IEEEPUP,ieeepup)
  36. #endif
  37. #ifdef ETH_P_IEEEPUPAT
  38. __PF(IEEEPUPAT,ieeepupat)
  39. #endif
  40. __PF(DEC,dec)
  41. __PF(DNA_DL,dna_dl)
  42. __PF(DNA_RC,dna_rc)
  43. __PF(DNA_RT,dna_rt)
  44. __PF(LAT,lat)
  45. __PF(DIAG,diag)
  46. __PF(CUST,cust)
  47. __PF(SCA,sca)
  48. __PF(RARP,rarp)
  49. __PF(ATALK,atalk)
  50. __PF(AARP,aarp)
  51. __PF(IPX,ipx)
  52. __PF(IPV6,ipv6)
  53. #ifdef ETH_P_PPP_DISC
  54. __PF(PPP_DISC,ppp_disc)
  55. #endif
  56. #ifdef ETH_P_PPP_SES
  57. __PF(PPP_SES,ppp_ses)
  58. #endif
  59. #ifdef ETH_P_ATMMPOA
  60. __PF(ATMMPOA,atmmpoa)
  61. #endif
  62. #ifdef ETH_P_ATMFATE
  63. __PF(ATMFATE,atmfate)
  64. #endif
  65. __PF(802_3,802_3)
  66. __PF(AX25,ax25)
  67. __PF(ALL,all)
  68. __PF(802_2,802_2)
  69. __PF(SNAP,snap)
  70. __PF(DDCMP,ddcmp)
  71. __PF(WAN_PPP,wan_ppp)
  72. __PF(PPP_MP,ppp_mp)
  73. __PF(LOCALTALK,localtalk)
  74. __PF(PPPTALK,ppptalk)
  75. __PF(TR_802_2,tr_802_2)
  76. __PF(MOBITEX,mobitex)
  77. __PF(CONTROL,control)
  78. __PF(IRDA,irda)
  79. #ifdef ETH_P_ECONET
  80. __PF(ECONET,econet)
  81. #endif
  82. { 0x8100, "802.1Q" },
  83. { ETH_P_IP, "ipv4" },
  84. };
  85. #undef __PF
  86. const char * ll_proto_n2a(unsigned short id, char *buf, int len)
  87. {
  88. int i;
  89. id = ntohs(id);
  90. for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
  91. if (llproto_names[i].id == id)
  92. return llproto_names[i].name;
  93. }
  94. snprintf(buf, len, "[%d]", id);
  95. return buf;
  96. }
  97. int ll_proto_a2n(unsigned short *id, char *buf)
  98. {
  99. int i;
  100. for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
  101. if (strcasecmp(llproto_names[i].name, buf) == 0) {
  102. *id = htons(llproto_names[i].id);
  103. return 0;
  104. }
  105. }
  106. if (get_u16(id, buf, 0))
  107. return -1;
  108. *id = htons(*id);
  109. return 0;
  110. }