ProtocolFamilyMapper.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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-28
  7. *
  8. * */
  9. #include <ls_std/os/specification.hpp>
  10. #include <ls_std/network/core/ProtocolFamilyMapper.hpp>
  11. #include <ls_std/core/exception/IllegalArgumentException.hpp>
  12. #if LS_STD_UNIX_PLATFORM
  13. #include <sys/socket.h>
  14. #endif
  15. ls::std::network::ProtocolFamilyMapper::ProtocolFamilyMapper() : ls::std::core::Class("ProtocolFamilyMapper")
  16. {}
  17. ls::std::network::ConvertedProtocolFamily ls::std::network::ProtocolFamilyMapper::from(const ls::std::network::ProtocolFamilyType &_protocolFamilyType)
  18. {
  19. #if LS_STD_UNIX_PLATFORM
  20. return ls::std::network::ProtocolFamilyMapper::_toUnixProtocolFamily(_protocolFamilyType);
  21. #endif
  22. }
  23. #if LS_STD_UNIX_PLATFORM
  24. ls::std::network::ConvertedProtocolFamily ls::std::network::ProtocolFamilyMapper::_toUnixProtocolFamily(const ls::std::network::ProtocolFamilyType &_protocolFamilyType)
  25. {
  26. ls::std::network::ConvertedProtocolFamily convertedProtocolFamily{};
  27. switch(_protocolFamilyType)
  28. {
  29. case ls::std::network::ProtocolFamilyType::LS_STD_PROTOCOL_FAMILY_TYPE_IPV4:
  30. {
  31. convertedProtocolFamily.unixDomain = AF_INET;
  32. } break;
  33. case ls::std::network::ProtocolFamilyType::LS_STD_PROTOCOL_FAMILY_TYPE_NOT_INITIALIZED:
  34. {
  35. throw ls::std::core::IllegalArgumentException{};
  36. }
  37. }
  38. return convertedProtocolFamily;
  39. }
  40. #endif