SocketAddressMapper.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2022-11-18
  6. * Changed: 2022-12-09
  7. *
  8. * */
  9. #include <ls_std/network/socket/SocketAddressMapper.hpp>
  10. #include <ls_std/network/core/ConvertedProtocolFamily.hpp>
  11. #include <ls_std/network/core/ProtocolFamilyMapper.hpp>
  12. #if defined(unix) || defined(__APPLE__)
  13. #include <netinet/in.h>
  14. #include <arpa/inet.h>
  15. #endif
  16. ls::std::network::SocketAddressMapper::SocketAddressMapper() : ls::std::core::Class("SocketAddressMapper")
  17. {}
  18. ls::std::network::ConvertedSocketAddress ls::std::network::SocketAddressMapper::from(const ls::std::network::SocketAddressMapperParameter &_parameter)
  19. {
  20. ls::std::network::ConvertedSocketAddress convertedSocketAddress{};
  21. #if defined(unix) || defined(__APPLE__)
  22. convertedSocketAddress.socketAddressUnix = ls::std::network::SocketAddressMapper::_toSockAddressUnix(_parameter);
  23. #endif
  24. return convertedSocketAddress;
  25. }
  26. #if defined(unix) || defined(__APPLE__)
  27. ::sockaddr_in ls::std::network::SocketAddressMapper::_toSockAddressUnix(const ls::std::network::SocketAddressMapperParameter &_parameter)
  28. {
  29. ::sockaddr_in socketAddressUnix{};
  30. socketAddressUnix.sin_port = ::htons(_parameter.socketAddress.port);
  31. ls::std::network::ConvertedProtocolFamily convertedProtocolFamily = ls::std::network::ProtocolFamilyMapper::from(_parameter.protocolFamilyType);
  32. socketAddressUnix.sin_family = convertedProtocolFamily.unixDomain;
  33. ::inet_aton(_parameter.socketAddress.ipAddress.c_str(), &socketAddressUnix.sin_addr);
  34. return socketAddressUnix;
  35. }
  36. #endif