Remove networking functions that can be found elsewhere
This commit is contained in:
@@ -215,11 +215,11 @@ int main(int argc, char **argv)
|
|||||||
int ztServicePort = atoi(argv[5]); // Port ZT uses to send encrypted UDP packets to peers (try something like 9994)
|
int ztServicePort = atoi(argv[5]); // Port ZT uses to send encrypted UDP packets to peers (try something like 9994)
|
||||||
|
|
||||||
struct zts_sockaddr_in in4;
|
struct zts_sockaddr_in in4;
|
||||||
in4.sin_port = zts_htons(remotePort);
|
in4.sin_port = htons(remotePort);
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
in4.sin_addr.S_addr = zts_inet_addr(remoteAddr.c_str());
|
zts_inet_pton(ZTS_AF_INET, remoteAddr.c_str(), &(in4.sin_addr.S_addr));
|
||||||
#else
|
#else
|
||||||
in4.sin_addr.s_addr = zts_inet_addr(remoteAddr.c_str());
|
zts_inet_pton(ZTS_AF_INET, remoteAddr.c_str(), &(in4.sin_addr.s_addr));
|
||||||
#endif
|
#endif
|
||||||
in4.sin_family = ZTS_AF_INET;
|
in4.sin_family = ZTS_AF_INET;
|
||||||
|
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ void printPeerDetails(const char *msgStr, struct zts_peer_details *d)
|
|||||||
if (sa->sa_family == ZTS_AF_INET) {
|
if (sa->sa_family == ZTS_AF_INET) {
|
||||||
struct zts_sockaddr_in *in4 = (struct zts_sockaddr_in*)sa;
|
struct zts_sockaddr_in *in4 = (struct zts_sockaddr_in*)sa;
|
||||||
zts_inet_ntop(ZTS_AF_INET, &(in4->sin_addr), ipstr, ZTS_INET_ADDRSTRLEN);
|
zts_inet_ntop(ZTS_AF_INET, &(in4->sin_addr), ipstr, ZTS_INET_ADDRSTRLEN);
|
||||||
port = zts_ntohs(in4->sin_port);
|
port = ntohs(in4->sin_port);
|
||||||
}
|
}
|
||||||
if (sa->sa_family == ZTS_AF_INET6) {
|
if (sa->sa_family == ZTS_AF_INET6) {
|
||||||
struct zts_sockaddr_in6 *in6 = (struct zts_sockaddr_in6*)sa;
|
struct zts_sockaddr_in6 *in6 = (struct zts_sockaddr_in6*)sa;
|
||||||
|
|||||||
@@ -218,11 +218,11 @@ int main(int argc, char **argv)
|
|||||||
int ztServicePort = atoi(argv[5]); // Port ZT uses to send encrypted UDP packets to peers (try something like 9994)
|
int ztServicePort = atoi(argv[5]); // Port ZT uses to send encrypted UDP packets to peers (try something like 9994)
|
||||||
|
|
||||||
struct zts_sockaddr_in in4;
|
struct zts_sockaddr_in in4;
|
||||||
in4.sin_port = zts_htons(remotePort);
|
in4.sin_port = htons(remotePort);
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
in4.sin_addr.S_addr = zts_inet_addr(remoteAddr.c_str());
|
zts_inet_pton(ZTS_AF_INET, remoteAddr.c_str(), &(in4.sin_addr.S_addr));
|
||||||
#else
|
#else
|
||||||
in4.sin_addr.s_addr = zts_inet_addr(remoteAddr.c_str());
|
zts_inet_pton(ZTS_AF_INET, remoteAddr.c_str(), &(in4.sin_addr.s_addr));
|
||||||
#endif
|
#endif
|
||||||
in4.sin_family = ZTS_AF_INET;
|
in4.sin_family = ZTS_AF_INET;
|
||||||
|
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ int main(int argc, char **argv)
|
|||||||
int ztServicePort = atoi(argv[4]); // Port ZT uses to send encrypted UDP packets to peers (try something like 9994)
|
int ztServicePort = atoi(argv[4]); // Port ZT uses to send encrypted UDP packets to peers (try something like 9994)
|
||||||
|
|
||||||
struct zts_sockaddr_in in4, acc_in4;
|
struct zts_sockaddr_in in4, acc_in4;
|
||||||
in4.sin_port = zts_htons(serverBindPort);
|
in4.sin_port = htons(serverBindPort);
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
in4.sin_addr.S_addr = ZTS_INADDR_ANY;
|
in4.sin_addr.S_addr = ZTS_INADDR_ANY;
|
||||||
#else
|
#else
|
||||||
@@ -281,7 +281,7 @@ int main(int argc, char **argv)
|
|||||||
char ipstr[ZTS_INET_ADDRSTRLEN];
|
char ipstr[ZTS_INET_ADDRSTRLEN];
|
||||||
memset(ipstr, 0, sizeof(ipstr));
|
memset(ipstr, 0, sizeof(ipstr));
|
||||||
zts_inet_ntop(ZTS_AF_INET, &(acc_in4.sin_addr), ipstr, ZTS_INET_ADDRSTRLEN);
|
zts_inet_ntop(ZTS_AF_INET, &(acc_in4.sin_addr), ipstr, ZTS_INET_ADDRSTRLEN);
|
||||||
printf("Accepted connection from %s:%d\n", ipstr, zts_ntohs(acc_in4.sin_port));
|
printf("Accepted connection from %s:%d\n", ipstr, ntohs(acc_in4.sin_port));
|
||||||
|
|
||||||
int bytes=0;
|
int bytes=0;
|
||||||
char recvBuf[128];
|
char recvBuf[128];
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ int main(int argc, char **argv)
|
|||||||
int ztServicePort = atoi(argv[4]); // Port ZT uses to send encrypted UDP packets to peers (try something like 9994)
|
int ztServicePort = atoi(argv[4]); // Port ZT uses to send encrypted UDP packets to peers (try something like 9994)
|
||||||
|
|
||||||
struct zts_sockaddr_in in4, acc_in4;
|
struct zts_sockaddr_in in4, acc_in4;
|
||||||
in4.sin_port = zts_htons(serverBindPort);
|
in4.sin_port = htons(serverBindPort);
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
in4.sin_addr.S_addr = ZTS_INADDR_ANY;
|
in4.sin_addr.S_addr = ZTS_INADDR_ANY;
|
||||||
#else
|
#else
|
||||||
@@ -284,7 +284,7 @@ int main(int argc, char **argv)
|
|||||||
char ipstr[ZTS_INET_ADDRSTRLEN];
|
char ipstr[ZTS_INET_ADDRSTRLEN];
|
||||||
memset(ipstr, 0, sizeof(ipstr));
|
memset(ipstr, 0, sizeof(ipstr));
|
||||||
zts_inet_ntop(ZTS_AF_INET, &(acc_in4.sin_addr), ipstr, ZTS_INET_ADDRSTRLEN);
|
zts_inet_ntop(ZTS_AF_INET, &(acc_in4.sin_addr), ipstr, ZTS_INET_ADDRSTRLEN);
|
||||||
printf("Accepted connection from %s:%d\n", ipstr, zts_ntohs(acc_in4.sin_port));
|
printf("Accepted connection from %s:%d\n", ipstr, ntohs(acc_in4.sin_port));
|
||||||
|
|
||||||
printf("Reading message string from client...\n");
|
printf("Reading message string from client...\n");
|
||||||
if((bytes = zts_read(accfd, recvBuf, sizeof(recvBuf))) < 0) {
|
if((bytes = zts_read(accfd, recvBuf, sizeof(recvBuf))) < 0) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include "ZeroTierSockets.h"
|
#include "ZeroTierSockets.h"
|
||||||
#include "nbind/api.h"
|
#include "nbind/api.h"
|
||||||
@@ -130,11 +131,11 @@ void on_zts_event(void *msgPtr)
|
|||||||
zts_sockaddr_in sockaddr_in(const char *remoteAddr, const int remotePort)
|
zts_sockaddr_in sockaddr_in(const char *remoteAddr, const int remotePort)
|
||||||
{
|
{
|
||||||
struct zts_sockaddr_in in4;
|
struct zts_sockaddr_in in4;
|
||||||
in4.sin_port = zts_htons(remotePort);
|
in4.sin_port = htons(remotePort);
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
in4.sin_addr.S_addr = zts_inet_addr(remoteAddr);
|
zts_inet_pton(ZTS_AF_INET, remoteAddr.c_str(), &(in4.sin_addr.S_addr));
|
||||||
#else
|
#else
|
||||||
in4.sin_addr.s_addr = zts_inet_addr(remoteAddr);
|
zts_inet_pton(ZTS_AF_INET, remoteAddr.c_str(), &(in4.sin_addr.s_addr));
|
||||||
#endif
|
#endif
|
||||||
in4.sin_family = ZTS_AF_INET;
|
in4.sin_family = ZTS_AF_INET;
|
||||||
return in4;
|
return in4;
|
||||||
|
|||||||
@@ -297,6 +297,11 @@ extern int zts_errno;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Length of human-readable MAC address string
|
||||||
|
*/
|
||||||
|
#define ZTS_MAC_ADDRSTRLEN 18
|
||||||
|
|
||||||
#define ZTS_INET_ADDRSTRLEN 16
|
#define ZTS_INET_ADDRSTRLEN 16
|
||||||
#define ZTS_INET6_ADDRSTRLEN 46
|
#define ZTS_INET6_ADDRSTRLEN 46
|
||||||
|
|
||||||
@@ -1819,7 +1824,7 @@ struct zts_msghdr {
|
|||||||
* @param flags
|
* @param flags
|
||||||
* @return Byte count sent on success. ZTS_ERR_SOCKET, ZTS_ERR_SERVICE, ZTS_ERR_ARG on failure.
|
* @return Byte count sent on success. ZTS_ERR_SOCKET, ZTS_ERR_SERVICE, ZTS_ERR_ARG on failure.
|
||||||
*/
|
*/
|
||||||
ZTS_API ssize_t ZTCALL zts_sendmsg(int fd, const struct msghdr *msg, int flags);
|
ZTS_API ssize_t ZTCALL zts_sendmsg(int fd, const struct zts_msghdr *msg, int flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Receive data from remote host (sets zts_errno)
|
* @brief Receive data from remote host (sets zts_errno)
|
||||||
@@ -1854,7 +1859,7 @@ ZTS_API ssize_t ZTCALL zts_recvfrom(
|
|||||||
* @param flags
|
* @param flags
|
||||||
* @return Byte count received on success. ZTS_ERR_SOCKET, ZTS_ERR_SERVICE, ZTS_ERR_ARG on failure.
|
* @return Byte count received on success. ZTS_ERR_SOCKET, ZTS_ERR_SERVICE, ZTS_ERR_ARG on failure.
|
||||||
*/
|
*/
|
||||||
ZTS_API ssize_t ZTCALL zts_recvmsg(int fd, struct msghdr *msg,int flags);
|
ZTS_API ssize_t ZTCALL zts_recvmsg(int fd, struct zts_msghdr *msg,int flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Read bytes from socket onto buffer (sets zts_errno)
|
* @brief Read bytes from socket onto buffer (sets zts_errno)
|
||||||
@@ -1925,47 +1930,6 @@ ZTS_API int ZTCALL zts_add_dns_nameserver(struct zts_sockaddr *addr);
|
|||||||
*/
|
*/
|
||||||
ZTS_API int ZTCALL zts_del_dns_nameserver(struct zts_sockaddr *addr);
|
ZTS_API int ZTCALL zts_del_dns_nameserver(struct zts_sockaddr *addr);
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert an uint16_t from host to network byte order.
|
|
||||||
*
|
|
||||||
* @param n uint16_t in host byte order
|
|
||||||
* @return n in network byte order
|
|
||||||
*/
|
|
||||||
ZTS_API uint16_t ZTCALL zts_htons(uint16_t n);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert an uint32_t from host to network byte order.
|
|
||||||
*
|
|
||||||
* @param n uint32_t in host byte order
|
|
||||||
* @return n in network byte order
|
|
||||||
*/
|
|
||||||
ZTS_API uint32_t ZTCALL zts_htonl(uint32_t n);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Length of human-readable MAC address string
|
|
||||||
*/
|
|
||||||
#define ZTS_MAC_ADDRSTRLEN 18
|
|
||||||
|
|
||||||
#ifndef htonll
|
|
||||||
#define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert an uint16_t from network to host byte order.
|
|
||||||
*
|
|
||||||
* @param n uint16_t in network byte order
|
|
||||||
* @return n in host byte order
|
|
||||||
*/
|
|
||||||
ZTS_API uint16_t ZTCALL zts_ntohs(uint16_t n);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert an uint32_t from network to host byte order.
|
|
||||||
*
|
|
||||||
* @param n uint32_t in network byte order
|
|
||||||
* @return n in host byte order
|
|
||||||
*/
|
|
||||||
ZTS_API uint32_t ZTCALL zts_ntohl(uint32_t n);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert IPv4 and IPv6 address structures to human-readable text form.
|
* Convert IPv4 and IPv6 address structures to human-readable text form.
|
||||||
*
|
*
|
||||||
@@ -1987,14 +1951,6 @@ ZTS_API const char * ZTCALL zts_inet_ntop(int af, const void *src, char *dst, zt
|
|||||||
*/
|
*/
|
||||||
ZTS_API int ZTCALL zts_inet_pton(int af, const char *src, void *dst);
|
ZTS_API int ZTCALL zts_inet_pton(int af, const char *src, void *dst);
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a C-string IPv4 address to integer representation.
|
|
||||||
*
|
|
||||||
* @param cp Human-readable IPv4 string
|
|
||||||
* @return 32-bit integer representation of address
|
|
||||||
*/
|
|
||||||
ZTS_API uint32_t ZTCALL zts_inet_addr(const char *cp);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -206,12 +206,12 @@ ssize_t zts_sendto(int fd, const void *buf, size_t len, int flags,
|
|||||||
return lwip_sendto(fd, buf, len, flags, (sockaddr*)addr, addrlen);
|
return lwip_sendto(fd, buf, len, flags, (sockaddr*)addr, addrlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t zts_sendmsg(int fd, const struct msghdr *msg, int flags)
|
ssize_t zts_sendmsg(int fd, const struct zts_msghdr *msg, int flags)
|
||||||
{
|
{
|
||||||
if (!(_serviceStateFlags & ZTS_STATE_NET_SERVICE_RUNNING)) {
|
if (!(_serviceStateFlags & ZTS_STATE_NET_SERVICE_RUNNING)) {
|
||||||
return ZTS_ERR_SERVICE;
|
return ZTS_ERR_SERVICE;
|
||||||
}
|
}
|
||||||
return lwip_sendmsg(fd, msg, flags);
|
return lwip_sendmsg(fd, (const struct msghdr *)msg, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t zts_recv(int fd, void *buf, size_t len, int flags)
|
ssize_t zts_recv(int fd, void *buf, size_t len, int flags)
|
||||||
@@ -237,7 +237,7 @@ ssize_t zts_recvfrom(int fd, void *buf, size_t len, int flags,
|
|||||||
return lwip_recvfrom(fd, buf, len, flags, (sockaddr*)addr, (socklen_t*)addrlen);
|
return lwip_recvfrom(fd, buf, len, flags, (sockaddr*)addr, (socklen_t*)addrlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t zts_recvmsg(int fd, struct msghdr *msg, int flags)
|
ssize_t zts_recvmsg(int fd, struct zts_msghdr *msg, int flags)
|
||||||
{
|
{
|
||||||
if (!(_serviceStateFlags & ZTS_STATE_NET_SERVICE_RUNNING)) {
|
if (!(_serviceStateFlags & ZTS_STATE_NET_SERVICE_RUNNING)) {
|
||||||
return ZTS_ERR_SERVICE;
|
return ZTS_ERR_SERVICE;
|
||||||
@@ -245,7 +245,7 @@ ssize_t zts_recvmsg(int fd, struct msghdr *msg, int flags)
|
|||||||
if (!msg) {
|
if (!msg) {
|
||||||
return ZTS_ERR_ARG;
|
return ZTS_ERR_ARG;
|
||||||
}
|
}
|
||||||
return lwip_recvmsg(fd, msg, flags);
|
return lwip_recvmsg(fd, (struct msghdr *)msg, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t zts_read(int fd, void *buf, size_t len)
|
ssize_t zts_read(int fd, void *buf, size_t len)
|
||||||
@@ -310,26 +310,6 @@ int zts_del_dns_nameserver(struct zts_sockaddr *addr)
|
|||||||
return ZTS_ERR_SERVICE; // TODO
|
return ZTS_ERR_SERVICE; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t zts_htons(uint16_t n)
|
|
||||||
{
|
|
||||||
return lwip_htons(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t zts_htonl(uint32_t n)
|
|
||||||
{
|
|
||||||
return lwip_htonl(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t zts_ntohs(uint16_t n)
|
|
||||||
{
|
|
||||||
return lwip_htons(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t zts_ntohl(uint32_t n)
|
|
||||||
{
|
|
||||||
return lwip_htonl(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *zts_inet_ntop(int af, const void *src, char *dst,zts_socklen_t size)
|
const char *zts_inet_ntop(int af, const void *src, char *dst,zts_socklen_t size)
|
||||||
{
|
{
|
||||||
return lwip_inet_ntop(af,src,dst,size);
|
return lwip_inet_ntop(af,src,dst,size);
|
||||||
@@ -340,11 +320,6 @@ int zts_inet_pton(int af, const char *src, void *dst)
|
|||||||
return lwip_inet_pton(af,src,dst);
|
return lwip_inet_pton(af,src,dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t zts_inet_addr(const char *cp)
|
|
||||||
{
|
|
||||||
return ipaddr_addr(cp);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
// Statistics //
|
// Statistics //
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ namespace ZeroTier.Sockets
|
|||||||
sa.sin_family = (byte)Constants.AF_UNSPEC;
|
sa.sin_family = (byte)Constants.AF_UNSPEC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sa.sin_port = (short)zts_htons((ushort)remoteEndPoint.Port);
|
sa.sin_port = (short)IPAddress.HostToNetworkOrder((ushort)remoteEndPoint.Port);
|
||||||
sa.sin_addr = remoteEndPoint.Address.GetAddressBytes();
|
sa.sin_addr = remoteEndPoint.Address.GetAddressBytes();
|
||||||
sa.sin_len = (byte)addrlen; // lwIP-specific
|
sa.sin_len = (byte)addrlen; // lwIP-specific
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ namespace ZeroTier.Sockets
|
|||||||
sa.sin_family = (byte)Constants.AF_UNSPEC;
|
sa.sin_family = (byte)Constants.AF_UNSPEC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sa.sin_port = (short)zts_htons((ushort)localEndPoint.Port);
|
sa.sin_port = (short)IPAddress.HostToNetworkOrder((ushort)localEndPoint.Port);
|
||||||
sa.sin_addr = localEndPoint.Address.GetAddressBytes();
|
sa.sin_addr = localEndPoint.Address.GetAddressBytes();
|
||||||
sa.sin_len = (byte)addrlen; // lwIP-specific
|
sa.sin_len = (byte)addrlen; // lwIP-specific
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ namespace ZeroTier.Sockets
|
|||||||
in4 = (zts_sockaddr_in)Marshal.PtrToStructure(remoteAddrPtr, typeof(zts_sockaddr_in));
|
in4 = (zts_sockaddr_in)Marshal.PtrToStructure(remoteAddrPtr, typeof(zts_sockaddr_in));
|
||||||
// Convert sockaddr contents to IPEndPoint
|
// Convert sockaddr contents to IPEndPoint
|
||||||
IPAddress ipAddress = new IPAddress(in4.sin_addr);
|
IPAddress ipAddress = new IPAddress(in4.sin_addr);
|
||||||
IPEndPoint clientEndPoint = new IPEndPoint(ipAddress, zts_ntohs((ushort)in4.sin_port));
|
IPEndPoint clientEndPoint = new IPEndPoint(ipAddress, IPAddress.NetworkToHostOrder(((ushort)in4.sin_port));
|
||||||
// Create new socket by providing file descriptor returned from zts_accept call.
|
// Create new socket by providing file descriptor returned from zts_accept call.
|
||||||
Socket clientSocket = new Socket(
|
Socket clientSocket = new Socket(
|
||||||
err, _socketFamily, _socketType, _socketProtocol, _localEndPoint, clientEndPoint);
|
err, _socketFamily, _socketType, _socketProtocol, _localEndPoint, clientEndPoint);
|
||||||
@@ -598,27 +598,12 @@ namespace ZeroTier.Sockets
|
|||||||
[DllImport("libzt", EntryPoint="CSharp_zts_del_dns_nameserver")]
|
[DllImport("libzt", EntryPoint="CSharp_zts_del_dns_nameserver")]
|
||||||
static extern int zts_del_dns_nameserver(IntPtr arg1);
|
static extern int zts_del_dns_nameserver(IntPtr arg1);
|
||||||
|
|
||||||
[DllImport("libzt", EntryPoint="CSharp_zts_htons")]
|
|
||||||
static extern ushort zts_htons(ushort arg1);
|
|
||||||
|
|
||||||
[DllImport("libzt", EntryPoint="CSharp_zts_htonl")]
|
|
||||||
static extern ushort zts_htonl(ushort arg1);
|
|
||||||
|
|
||||||
[DllImport("libzt", EntryPoint="CSharp_zts_ntohs")]
|
|
||||||
static extern ushort zts_ntohs(ushort arg1);
|
|
||||||
|
|
||||||
[DllImport("libzt", EntryPoint="CSharp_zts_ntohl")]
|
|
||||||
static extern ushort zts_ntohl(ushort arg1);
|
|
||||||
|
|
||||||
[DllImport("libzt", EntryPoint="CSharp_zts_inet_ntop")]
|
[DllImport("libzt", EntryPoint="CSharp_zts_inet_ntop")]
|
||||||
static extern string zts_inet_ntop(int arg1, IntPtr arg2, string arg3, ushort arg4);
|
static extern string zts_inet_ntop(int arg1, IntPtr arg2, string arg3, ushort arg4);
|
||||||
|
|
||||||
[DllImport("libzt", EntryPoint="CSharp_zts_inet_pton")]
|
[DllImport("libzt", EntryPoint="CSharp_zts_inet_pton")]
|
||||||
static extern int zts_inet_pton(int arg1, string arg2, IntPtr arg3);
|
static extern int zts_inet_pton(int arg1, string arg2, IntPtr arg3);
|
||||||
|
|
||||||
[DllImport("libzt", EntryPoint="CSharp_zts_inet_addr")]
|
|
||||||
static extern ushort zts_inet_addr(string arg1);
|
|
||||||
|
|
||||||
[DllImport("libzt", EntryPoint="CSharp_zts_errno_get")]
|
[DllImport("libzt", EntryPoint="CSharp_zts_errno_get")]
|
||||||
static extern int zts_errno_get();
|
static extern int zts_errno_get();
|
||||||
|
|
||||||
|
|||||||
@@ -1057,53 +1057,6 @@ SWIGEXPORT int SWIGSTDCALL CSharp_zts_del_dns_nameserver(zts_sockaddr* jarg1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SWIGEXPORT unsigned short SWIGSTDCALL CSharp_zts_htons(unsigned short jarg1) {
|
|
||||||
unsigned short jresult ;
|
|
||||||
uint16_t arg1 ;
|
|
||||||
uint16_t result;
|
|
||||||
|
|
||||||
arg1 = (uint16_t)jarg1;
|
|
||||||
result = zts_htons(arg1);
|
|
||||||
jresult = result;
|
|
||||||
return jresult;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SWIGEXPORT unsigned short SWIGSTDCALL CSharp_zts_htonl(unsigned short jarg1) {
|
|
||||||
unsigned short jresult ;
|
|
||||||
uint32_t arg1 ;
|
|
||||||
uint32_t result;
|
|
||||||
|
|
||||||
arg1 = (uint32_t)jarg1;
|
|
||||||
result = zts_htonl(arg1);
|
|
||||||
jresult = result;
|
|
||||||
return jresult;
|
|
||||||
}
|
|
||||||
|
|
||||||
SWIGEXPORT unsigned short SWIGSTDCALL CSharp_zts_ntohs(unsigned short jarg1) {
|
|
||||||
unsigned short jresult ;
|
|
||||||
uint16_t arg1 ;
|
|
||||||
uint16_t result;
|
|
||||||
|
|
||||||
arg1 = (uint16_t)jarg1;
|
|
||||||
result = zts_ntohs(arg1);
|
|
||||||
jresult = result;
|
|
||||||
return jresult;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SWIGEXPORT unsigned short SWIGSTDCALL CSharp_zts_ntohl(unsigned short jarg1) {
|
|
||||||
unsigned short jresult ;
|
|
||||||
uint32_t arg1 ;
|
|
||||||
uint32_t result;
|
|
||||||
|
|
||||||
arg1 = (uint32_t)jarg1;
|
|
||||||
result = zts_ntohl(arg1);
|
|
||||||
jresult = result;
|
|
||||||
return jresult;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SWIGEXPORT char * SWIGSTDCALL CSharp_zts_inet_ntop(int jarg1, void * jarg2, char * jarg3, unsigned short jarg4) {
|
SWIGEXPORT char * SWIGSTDCALL CSharp_zts_inet_ntop(int jarg1, void * jarg2, char * jarg3, unsigned short jarg4) {
|
||||||
char * jresult ;
|
char * jresult ;
|
||||||
int arg1 ;
|
int arg1 ;
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lwip/sockets.h"
|
#include "lwip/sockets.h"
|
||||||
|
#include "lwip/inet.h"
|
||||||
|
|
||||||
#include "ZeroTierSockets.h"
|
#include "ZeroTierSockets.h"
|
||||||
|
|
||||||
#ifdef ZTS_ENABLE_PYTHON
|
#ifdef ZTS_ENABLE_PYTHON
|
||||||
@@ -55,7 +57,7 @@ static int zts_py_tuple_to_sockaddr(int family,
|
|||||||
return ZTS_ERR_ARG;
|
return ZTS_ERR_ARG;
|
||||||
}
|
}
|
||||||
addr = (struct zts_sockaddr_in*)dst_addr;
|
addr = (struct zts_sockaddr_in*)dst_addr;
|
||||||
addr->sin_addr.s_addr = zts_inet_addr(host_str);
|
zts_inet_pton(ZTS_AF_INET, host_str, &(addr->sin_addr.s_addr));
|
||||||
PyMem_Free(host_str);
|
PyMem_Free(host_str);
|
||||||
if (port < 0 || port > 0xFFFF) {
|
if (port < 0 || port > 0xFFFF) {
|
||||||
return ZTS_ERR_ARG;
|
return ZTS_ERR_ARG;
|
||||||
@@ -64,7 +66,7 @@ static int zts_py_tuple_to_sockaddr(int family,
|
|||||||
return ZTS_ERR_ARG;
|
return ZTS_ERR_ARG;
|
||||||
}
|
}
|
||||||
addr->sin_family = AF_INET;
|
addr->sin_family = AF_INET;
|
||||||
addr->sin_port = htons((short)port);
|
addr->sin_port = lwip_htons((short)port);
|
||||||
*addrlen = sizeof *addr;
|
*addrlen = sizeof *addr;
|
||||||
return ZTS_ERR_OK;
|
return ZTS_ERR_OK;
|
||||||
}
|
}
|
||||||
@@ -87,7 +89,7 @@ PyObject * zts_py_accept(int fd)
|
|||||||
t = PyTuple_New(3);
|
t = PyTuple_New(3);
|
||||||
PyTuple_SetItem(t, 0, PyLong_FromLong(err)); // New file descriptor
|
PyTuple_SetItem(t, 0, PyLong_FromLong(err)); // New file descriptor
|
||||||
PyTuple_SetItem(t, 1, PyUnicode_FromString(ipstr));
|
PyTuple_SetItem(t, 1, PyUnicode_FromString(ipstr));
|
||||||
PyTuple_SetItem(t, 2, PyLong_FromLong(zts_ntohs(addrbuf.sin_port)));
|
PyTuple_SetItem(t, 2, PyLong_FromLong(lwip_ntohs(addrbuf.sin_port)));
|
||||||
Py_INCREF(t);
|
Py_INCREF(t);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,6 +230,7 @@ ZTS_EREMOTEIO = _libzt.ZTS_EREMOTEIO
|
|||||||
ZTS_EDQUOT = _libzt.ZTS_EDQUOT
|
ZTS_EDQUOT = _libzt.ZTS_EDQUOT
|
||||||
ZTS_ENOMEDIUM = _libzt.ZTS_ENOMEDIUM
|
ZTS_ENOMEDIUM = _libzt.ZTS_ENOMEDIUM
|
||||||
ZTS_EMEDIUMTYPE = _libzt.ZTS_EMEDIUMTYPE
|
ZTS_EMEDIUMTYPE = _libzt.ZTS_EMEDIUMTYPE
|
||||||
|
ZTS_MAC_ADDRSTRLEN = _libzt.ZTS_MAC_ADDRSTRLEN
|
||||||
ZTS_INET_ADDRSTRLEN = _libzt.ZTS_INET_ADDRSTRLEN
|
ZTS_INET_ADDRSTRLEN = _libzt.ZTS_INET_ADDRSTRLEN
|
||||||
ZTS_INET6_ADDRSTRLEN = _libzt.ZTS_INET6_ADDRSTRLEN
|
ZTS_INET6_ADDRSTRLEN = _libzt.ZTS_INET6_ADDRSTRLEN
|
||||||
ZTS_SOCK_STREAM = _libzt.ZTS_SOCK_STREAM
|
ZTS_SOCK_STREAM = _libzt.ZTS_SOCK_STREAM
|
||||||
@@ -746,22 +747,10 @@ def zts_add_dns_nameserver(addr):
|
|||||||
def zts_del_dns_nameserver(addr):
|
def zts_del_dns_nameserver(addr):
|
||||||
return _libzt.zts_del_dns_nameserver(addr)
|
return _libzt.zts_del_dns_nameserver(addr)
|
||||||
|
|
||||||
def zts_htons(n):
|
|
||||||
return _libzt.zts_htons(n)
|
|
||||||
|
|
||||||
def zts_htonl(n):
|
|
||||||
return _libzt.zts_htonl(n)
|
|
||||||
ZTS_MAC_ADDRSTRLEN = _libzt.ZTS_MAC_ADDRSTRLEN
|
|
||||||
|
|
||||||
def zts_ntohs(n):
|
|
||||||
return _libzt.zts_ntohs(n)
|
|
||||||
|
|
||||||
def zts_ntohl(n):
|
|
||||||
return _libzt.zts_ntohl(n)
|
|
||||||
|
|
||||||
def zts_inet_ntop(af, src, dst, size):
|
def zts_inet_ntop(af, src, dst, size):
|
||||||
return _libzt.zts_inet_ntop(af, src, dst, size)
|
return _libzt.zts_inet_ntop(af, src, dst, size)
|
||||||
|
|
||||||
def zts_inet_pton(af, src, dst):
|
def zts_inet_pton(af, src, dst):
|
||||||
return _libzt.zts_inet_pton(af, src, dst)
|
return _libzt.zts_inet_pton(af, src, dst)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,5 @@
|
|||||||
%ignore zts_pollfd;
|
%ignore zts_pollfd;
|
||||||
%ignore zts_nfds_t;
|
%ignore zts_nfds_t;
|
||||||
%ignore zts_msghdr;
|
%ignore zts_msghdr;
|
||||||
%ignore zts_inet_addr;
|
|
||||||
|
|
||||||
%include "ZeroTierSockets.h"
|
%include "ZeroTierSockets.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user