No Description

ip_packet.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include "ip_packet.h"
  2. /// \fn ip_packet::ip_packet()
  3. /// \~English
  4. /// \brief Constructor
  5. /// \~Spanish
  6. /// \brief Constructor
  7. ip_packet::ip_packet()
  8. {
  9. payload = "" ;
  10. ip_dst = ip_src = "" ;
  11. }
  12. /// \fn void ip_packet::setIPSAddress(string addr)
  13. /// \~English
  14. /// \brief Saves the source IP address in std string format.
  15. /// \param addr source IP address
  16. /// \~Spanish
  17. /// \brief Guarda la direccion IP fuente en formato de cadena de caracteres
  18. /// \param addr direccion IP fuente
  19. void ip_packet::setIPSAddress(string addr){
  20. ip_src = addr ;
  21. }
  22. /// \fn void ip_packet::setIPDAddress(string addr)
  23. /// \~English
  24. /// \brief Saves the destination IP address in std string format.
  25. /// \param addr destination IP address
  26. /// \~Spanish
  27. /// \brief Guarda la direccion IP destino en formato de cadena de caracteres
  28. /// \param addr direccion IP destino
  29. void ip_packet::setIPDAddress(string addr){
  30. ip_dst = addr ;
  31. }
  32. /// \fn void ip_packet::setIPProto(char proto)
  33. /// \~English
  34. /// \brief Saves the IP protocol to (TCP|UDP)
  35. /// \param proto protocol number (6 | 17)
  36. /// \~Spanish
  37. /// \brief Guarda el protocolo de IP a (TCP|UDP)
  38. /// \param proto numero de protocolo (6 | 17)
  39. void ip_packet::setIPProto(char proto){
  40. ip_p = proto ;
  41. }
  42. /// \fn void ip_packet::setIPSPort(unsigned short port)
  43. /// \~English
  44. /// \brief Saves the source port
  45. /// \param port source port
  46. /// \~Spanish
  47. /// \brief Guarda el puerto fuente
  48. /// \param port puerto fuente
  49. void ip_packet::setIPSPort(unsigned short port){
  50. s_port = port ;
  51. }
  52. /// \fn void ip_packet::setIPDPort(unsigned short port)
  53. /// \~English
  54. /// \brief Saves the destinaation port
  55. /// \param port destination port
  56. /// \~Spanish
  57. /// \brief Guarda el puerto destino
  58. /// \param port puerto destino
  59. void ip_packet::setIPDPort(unsigned short port){
  60. d_port = port ;
  61. }
  62. /// \fn void ip_packet::setPayload(char *pl, int len)
  63. /// \~English
  64. /// \brief Saves the payload string of bytes into a string.
  65. /// \param pl the packet payload
  66. /// \param len length of the payload
  67. /// \~Spanish
  68. /// \brief Guarda la carga del paquete de una cadena de caracteres a un string.
  69. /// \param pl la carga del paquete
  70. /// \param len el largo del paquete
  71. void ip_packet::setPayload(char *pl, int len){
  72. for(int i = 0; i < len; i++){
  73. payload += pl[i] ;
  74. }
  75. }
  76. /// \fn string ip_packet::getIPSAddress()
  77. /// \~English
  78. /// \brief Returns the source IP address
  79. /// \return the source IP address
  80. /// \~Spanish
  81. /// \brief Devuelve la dirección IP fuente
  82. /// \return la direccion IP fuente
  83. string ip_packet::getIPSAddress(){
  84. return ip_src ;
  85. }
  86. /// \fn string ip_packet::getIPDAddress()
  87. /// \~English
  88. /// \brief Returns the destination IP address
  89. /// \return the destination IP address
  90. /// \~Spanish
  91. /// \brief Devuelve la dirección IP destino
  92. /// \return la direccion IP destino
  93. string ip_packet::getIPDAddress(){
  94. return ip_dst ;
  95. }
  96. /// \fn string ip_packet::getPayload()
  97. /// \~English
  98. /// \brief Returns the IP packet payload
  99. /// \return the IP packet payload
  100. /// \~Spanish
  101. /// \brief Devuelve la carga del paquete de IP
  102. /// \return la carga del paquete de IP
  103. string ip_packet::getPayload(){
  104. return payload ;
  105. }
  106. /// \fn char ip_packet::getIPProto()
  107. /// \~English
  108. /// \brief Returns the IP protocol type
  109. /// \return the IP protocol
  110. /// \~Spanish
  111. /// \brief Devuelve el tipo de protocolo IP
  112. /// \return el protocolo IP
  113. char ip_packet::getIPProto(){
  114. return ip_p ;
  115. }
  116. /// \fn unsigned short ip_packet::getIPSPort()
  117. /// \~English
  118. /// \brief Returns the source port
  119. /// \return the source port
  120. /// \~English
  121. /// \brief Devuelve el puerto fuente
  122. /// \return el puerto fuente
  123. unsigned short ip_packet::getIPSPort(){
  124. return s_port ;
  125. }
  126. /// \fn unsigned short ip_packet::getIPDPort()
  127. /// \~English
  128. /// \brief Returns the destination port
  129. /// \return the destination port
  130. /// \~English
  131. /// \brief Devuelve el puerto destino
  132. /// \return el puerto destino
  133. unsigned short ip_packet::getIPDPort(){
  134. return d_port ;
  135. }