-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
66 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,42 @@ | ||
#include <hxcpp.h> | ||
#include "NetUtils.h" | ||
#include "../LibuvUtils.h" | ||
#include <memory> | ||
|
||
namespace hx::asys::libuv::net | ||
sockaddr_in hx::asys::libuv::net::sockaddr_from_int(const int ip) | ||
{ | ||
sockaddr_in sockaddr_from_int(const int ip) | ||
{ | ||
auto addr = sockaddr_in(); | ||
addr.sin_family = AF_INET; | ||
auto addr = sockaddr_in(); | ||
addr.sin_family = AF_INET; | ||
|
||
std::memcpy(&addr.sin_addr, &ip, sizeof(int)); | ||
std::memcpy(&addr.sin_addr, &ip, sizeof(int)); | ||
|
||
return addr; | ||
} | ||
return addr; | ||
} | ||
|
||
sockaddr_in6 hx::asys::libuv::net::sockaddr_from_data(const Array<uint8_t> ip) | ||
{ | ||
auto addr = sockaddr_in6(); | ||
addr.sin6_family = AF_INET6; | ||
|
||
std::memcpy(&addr.sin6_addr, ip->getBase(), ip->size()); | ||
|
||
return addr; | ||
} | ||
|
||
sockaddr_in6 sockaddr_from_data(const Array<uint8_t> ip) | ||
{ | ||
auto addr = sockaddr_in6(); | ||
addr.sin6_family = AF_INET6; | ||
hx::EnumBase hx::asys::libuv::net::ip_from_sockaddr(sockaddr_in* addr) | ||
{ | ||
auto ip = 0; | ||
|
||
std::memcpy(&ip, &addr->sin_addr, sizeof(IN_ADDR)); | ||
|
||
return hx::asys::libuv::create(HX_CSTRING("INET"), 0, 1)->_hx_init(0, ip); | ||
} | ||
|
||
hx::EnumBase hx::asys::libuv::net::ip_from_sockaddr(sockaddr_in6* addr) | ||
{ | ||
auto bytes = new Array_obj<uint8_t>(0, 0); | ||
|
||
std::memcpy(&addr.sin6_addr, ip->getBase(), ip->size()); | ||
bytes->memcpy(0, reinterpret_cast<uint8_t*>(&addr->sin6_addr), sizeof(IN6_ADDR)); | ||
|
||
return addr; | ||
} | ||
return hx::asys::libuv::create(HX_CSTRING("INET6"), 1, 1)->_hx_init(0, bytes); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters