including tftp based shell and sockets from different project
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* @file etherCommon.cpp
|
||||
* @author Gustice
|
||||
* @brief Helper Functions for Ethernet usage
|
||||
*
|
||||
* @copyright Copyright (c) 2024
|
||||
*/
|
||||
|
||||
#include "etherCommon.hpp"
|
||||
#include <cassert>
|
||||
|
||||
IpAdr::IpAdr(std::string ipStr, uint16_t port)
|
||||
: IpAdr(ipaddr_addr(ipStr.c_str()), port) {
|
||||
}
|
||||
|
||||
IpAdr::IpAdr(uint32_t ip, uint16_t port) {
|
||||
struct sockaddr_in *ipV4 = (struct sockaddr_in *)&addrStore;
|
||||
ipV4->sin_len = sizeof(sockaddr_in);
|
||||
ipV4->sin_addr.s_addr = ip;
|
||||
ipV4->sin_family = AF_INET;
|
||||
ipV4->sin_port = htons(port);
|
||||
}
|
||||
|
||||
IpAdr::IpAdr(uint16_t port) {
|
||||
struct sockaddr_in *ipV4 = (struct sockaddr_in *)&addrStore;
|
||||
ipV4->sin_len = sizeof(sockaddr_in);
|
||||
ipV4->sin_addr.s_addr = INADDR_ANY;
|
||||
ipV4->sin_family = AF_INET;
|
||||
ipV4->sin_port = htons(port);
|
||||
}
|
||||
|
||||
IpAdr::IpAdr(sockaddr_in ipV4data) {
|
||||
struct sockaddr_storage *store = (struct sockaddr_storage *)&ipV4data;
|
||||
assert(ipV4data.sin_family == AF_INET);
|
||||
addrStore = *store;
|
||||
}
|
||||
|
||||
|
||||
IpAdrV6::IpAdrV6(std::string ipStr, uint16_t port) {
|
||||
struct sockaddr_in6 *ipV6 = (struct sockaddr_in6 *)&addrStore;
|
||||
ipV6->sin6_len = sizeof(sockaddr_in6);
|
||||
inet6_aton(ipStr.c_str(), &ipV6->sin6_addr);
|
||||
ipV6->sin6_family = AF_INET6;
|
||||
ipV6->sin6_port = htons(port);
|
||||
}
|
||||
|
||||
IpAdrV6::IpAdrV6(in6_addr ip, uint16_t port) {
|
||||
struct sockaddr_in6 *ipV6 = (struct sockaddr_in6 *)&addrStore;
|
||||
ipV6->sin6_len = sizeof(sockaddr_in6);
|
||||
memcpy(&ip, &ipV6->sin6_addr, sizeof(in6_addr));
|
||||
ipV6->sin6_family = AF_INET6;
|
||||
ipV6->sin6_port = htons(port);
|
||||
}
|
||||
|
||||
IpAdrV6::IpAdrV6(uint16_t port) {
|
||||
struct sockaddr_in6 *ipV6 = (struct sockaddr_in6 *)&addrStore;
|
||||
ipV6->sin6_len = sizeof(sockaddr_in6);
|
||||
// ip6_addr_set_any()
|
||||
bzero(&ipV6->sin6_addr.un, sizeof(ipV6->sin6_addr.un));
|
||||
ipV6->sin6_family = AF_INET6;
|
||||
ipV6->sin6_port = htons(port);
|
||||
}
|
||||
|
||||
IpAdrV6::IpAdrV6(sockaddr_in6 ipV6data) {
|
||||
struct sockaddr_storage *store = (struct sockaddr_storage *)&ipV6data;
|
||||
assert(ipV6data.sin6_family == AF_INET);
|
||||
addrStore = *store;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* @file tcpSockets.cpp
|
||||
* @author Gustice
|
||||
* @brief Function frames for handling sockets
|
||||
*
|
||||
* @copyright Copyright (c) 2024
|
||||
*/
|
||||
|
||||
#include "tcpSockets.hpp"
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @file udpSockets.cpp
|
||||
* @author Gustice
|
||||
* @brief Function frames for handling sockets
|
||||
*
|
||||
* @copyright Copyright (c) 2024
|
||||
*/
|
||||
|
||||
#include "udpSockets.hpp"
|
||||
|
||||
UdpSocket * Syslog::_Socket;
|
||||
Syslog::Facility Syslog::_Facility;
|
||||
std::string Syslog::_HostName;
|
||||
std::string Syslog::_AppName;
|
||||
IpAdr Syslog::_Target(INADDR_ANY, 0);
|
||||
|
||||
void Syslog::SyslogTask() {
|
||||
ESP_LOGI("SysLog", "Starting Syslog Task");
|
||||
try {
|
||||
while (true) {
|
||||
IpAdr ip(INADDR_ANY, SyslogPort);
|
||||
UdpSocket socket(ip);
|
||||
_Socket = &socket;
|
||||
socket.bindTo();
|
||||
|
||||
while (socket.isActive()) {
|
||||
(void)socket.read();
|
||||
// ignore all incomming data
|
||||
}
|
||||
}
|
||||
_Socket = nullptr;
|
||||
} catch (const std::exception &e) {
|
||||
ESP_LOGE("SysLog", "%s", e.what());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user