112 lines
3.3 KiB
Plaintext
112 lines
3.3 KiB
Plaintext
https://pubs.opengroup.org/onlinepubs/007908799/xns/socket.html
|
|
|
|
https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/lwip.html#bsd-sockets-api
|
|
|
|
setsockopt()
|
|
SO_REUSEADDR
|
|
SO_BROADCAST
|
|
SO_NO_CHECK ?
|
|
|
|
|
|
/* Socket protocol types (TCP/UDP/RAW) */
|
|
SOCK_RAW 3
|
|
|
|
struct raw_pcb * raw_new (u8_t proto);
|
|
err_t raw_connect (struct raw_pcb *pcb, const ip_addr_t *ipaddr);
|
|
void raw_disconnect (struct raw_pcb *pcb);
|
|
err_t raw_bind (struct raw_pcb *pcb, const ip_addr_t *ipaddr);
|
|
err_t raw_sendto (struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr);
|
|
err_t raw_send (struct raw_pcb *pcb, struct pbuf *p);\
|
|
void raw_recv (struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg);
|
|
|
|
|
|
|
|
int addr_family = AF_INET;
|
|
int ip_protocol = 0;
|
|
|
|
https://lwip.fandom.com/wiki/Netconn_send
|
|
|
|
|
|
|
|
|
|
// socket(addr type (v6/v4) (AF_INET/AF_INET6),
|
|
// proto type (SOCK_STREAM (tcp)/SOCK_DGRAM (udp)/SOCK_RAW (raw)),
|
|
// ip protocol (IPPROTO_IP/IPPROTO_IPV6));
|
|
|
|
#include <string.h>
|
|
#include <sys/param.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "freertos/event_groups.h"
|
|
#include "esp_system.h"
|
|
#include "esp_event.h"
|
|
#include "esp_log.h"
|
|
#include "nvs_flash.h"
|
|
#include "esp_netif.h"
|
|
#include "protocol_examples_common.h"
|
|
|
|
#include "lwip/err.h"
|
|
#include "lwip/sockets.h"
|
|
#include "lwip/sys.h"
|
|
#include <lwip/netdb.h>
|
|
|
|
#define HOST_IP_ADDR "10.0.0.255"
|
|
#define PORT CONFIG_EXAMPLE_PORT 4444 // placeholder
|
|
|
|
int err;
|
|
int errno;
|
|
int sockfd;
|
|
|
|
static const char *payload = "Message from ESP32 ";
|
|
static const char* TAG = "PrincessPiError";
|
|
|
|
struct sockaddr_in dest_addr;
|
|
dest_addr.sin_addr.s_addr = inet_addr(HOST_IP_ADDR);
|
|
dest_addr.sin_family = AF_INET;
|
|
dest_addr.sin_port = htons(PORT);
|
|
int opt = 1;
|
|
|
|
// https://pubs.opengroup.org/onlinepubs/007908799/xns/socket.html
|
|
// https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/lwip.html#bsd-sockets-api
|
|
if(sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_IP) < 0) {
|
|
ESP_LOGE(TAG, "%d", errno);
|
|
}
|
|
|
|
setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt));
|
|
setsockopt(sockfd, SOL_SOCKET, SO_ERROR, &err, &optlen);
|
|
|
|
if(err < 0) {
|
|
ESP_LOGE(TAG, "%d", err);
|
|
}
|
|
|
|
// sendto(sockefd, payloadf, strlen(payload), 0, IP_ADDR_BROADCAST, sizeof(IP_ADDR_BROADCAST));
|
|
sendto(sockfd, payload, strlen(payload), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
|
|
|
|
// setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
|
/*
|
|
|
|
#define TNetConn struct netconn *
|
|
#define TNetBuf struct netbuf *
|
|
|
|
TNetConn netConn = netconn_new(NETCONN_RAW);
|
|
|
|
struct TIpAddr xIp;
|
|
xIp.addr = 10.0.0.1;
|
|
|
|
TNetBuf xNetBuf = netbuf_new();
|
|
xBuf = netbuf_alloc(xNetBuf, 0x100);
|
|
netconn_sendto(netConn, xBuf, IP_ADDR_BROADCAST, 4444);
|
|
|
|
//Pointer xBuf = mem_malloc(0x100); // Pointer type? huh I'm too high for this
|
|
|
|
// netbuf_alloc (newNetBuf, 0x100);
|
|
// memset(xBuf, 0xAA, 0x100);
|
|
// xBuf = "\x00\x00\xFF" // raw payload. need memcpy?
|
|
|
|
|
|
//netbuf_ref()
|
|
// netconn_sendto(connection, payload, dst ip, port)
|
|
// netconn_sendto(newNetconn, xBuf, xIP, );
|
|
// netconn_sendto(newNetconn, &newNetbuff);
|
|
|
|
*/ |