ProtocolFamilyMapper.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2022-11-16
  6. * Changed: 2022-12-09
  7. *
  8. * */
  9. #include <ls_std/network/core/ProtocolFamilyMapper.hpp>
  10. #include <ls_std/core/exception/IllegalArgumentException.hpp>
  11. #if defined(unix) || defined(__APPLE__)
  12. #include <sys/socket.h>
  13. #endif
  14. ls::std::network::ProtocolFamilyMapper::ProtocolFamilyMapper() : ls::std::core::Class("ProtocolFamilyMapper")
  15. {}
  16. ls::std::network::ConvertedProtocolFamily ls::std::network::ProtocolFamilyMapper::from(const ls::std::network::ProtocolFamilyType &_protocolFamilyType)
  17. {
  18. #if defined(unix) || defined(__APPLE__)
  19. return ls::std::network::ProtocolFamilyMapper::_toUnixProtocolFamily(_protocolFamilyType);
  20. #endif
  21. }
  22. #if defined(unix) || defined(__APPLE__)
  23. ls::std::network::ConvertedProtocolFamily ls::std::network::ProtocolFamilyMapper::_toUnixProtocolFamily(const ls::std::network::ProtocolFamilyType &_protocolFamilyType)
  24. {
  25. ls::std::network::ConvertedProtocolFamily convertedProtocolFamily{};
  26. switch(_protocolFamilyType)
  27. {
  28. case ls::std::network::ProtocolFamilyType::PROTOCOL_FAMILY_TYPE_IPV4:
  29. {
  30. convertedProtocolFamily.unixDomain = AF_INET;
  31. } break;
  32. case ls::std::network::ProtocolFamilyType::PROTOCOL_FAMILY_TYPE_NOT_INITIALIZED:
  33. {
  34. throw ls::std::core::IllegalArgumentException{};
  35. }
  36. }
  37. return convertedProtocolFamily;
  38. }
  39. #endif