Since I don't typically have access to a convenient stdio I use the
following to log data. It uses the standard syslog port, and builds the
udp header up from lwip structures, and sends it out netif_default.
//Do a low level system log, useful for debugging issues with the stack
extern "C" netif *netif_default;
void sys_log(char *str) {
if(!netif_default) {
return;
}
//Must use a buffer that the driver can access, and do 1 time
initiaization
//of protocol headers
//Build a MAC/IP/UDP header
static eth_hdr *eth;
static ip_hdr *ip;
static udp_hdr *udp;
static char* driver_buf=0;
if(!driver_buf) {
driver_buf = (char*)memp_malloc(MEMP_PBUF_POOL);
eth = (eth_hdr*)driver_buf;
ip = (ip_hdr*)(driver_buf + sizeof(eth_hdr));
udp = (udp_hdr*)(((char*)ip) + sizeof(ip_hdr));
//Ethernet
eth->dest.addr[0]
= eth->dest.addr[1]
= eth->dest.addr[2]
= eth->dest.addr[3]
= eth->dest.addr[4]
= eth->dest.addr[5]
= 0xff;
memcpy(ð->src, netif_default->hwaddr, sizeof(eth->src));
eth->type = htons(ETHTYPE_IP);
//IP
IPH_VHLTOS_SET(ip, 4, IP_HLEN/4, 0);
IPH_ID_SET(ip, 0);
IPH_OFFSET_SET(ip, 0);
IPH_TTL_SET(ip, 20);
IPH_PROTO_SET(ip, IP_PROTO_UDP);
ip_addr dest;
dest.addr=0xffffffff;
ip_addr_set(&(ip->dest), &dest);
ip_addr_set(&(ip->src), &(netif_default->ip_addr));
IPH_CHKSUM_SET(ip, 0);
//UDP
udp->dest = udp->src = htons(514);
udp->chksum = 0;
}
int str_len = strlen(str);
//Fix up IP header
IPH_LEN(ip) = sizeof(ip_hdr) + sizeof(udp_hdr) + str_len;
IPH_CHKSUM_SET(ip, 0);
IPH_CHKSUM_SET(ip, inet_chksum(ip, IP_HLEN));
//UDP payload length
udp->len = htons(str_len + sizeof(udp_hdr));
//append payload
strncpy((char*)( ((char*)udp) + sizeof(udp_hdr)), str, str_len);
CLegacyDevice *legacyDevice = (CLegacyDevice*)netif_default->state;
legacyDevice->send(driver_buf, str_len + sizeof(udp_hdr) +
sizeof(ip_hdr) + sizeof(eth_hdr));
}
________________________________
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Gary Olson
Sent: Monday, August 18, 2008 10:02 AM
To: [email protected]
Subject: [lwip-users] Build Simple packet and send out using UDP
Hi,
Thank you Kieran for the help last week with my question on capturing
multiple ports using UDP.
I implemented the advice I received and it worked correctly. I would
now like to learn how I
Can create a simple short packet and send this packet to a PC. The
reason I need to do this
Is that I want to throttle the PC Bandwidth. I want to tell the PC to
stop send the board
Packets when the board cannot handle a packet. Or to restart the PC to
begin sending
Packets again.
By the way if anyone is interested I created a thread in Xilinx Forums
page about my multiple port
Problem at :
http://forums.xilinx.com/xlnx/board/message?board.id=EDK&thread.id=4539
Thank You,
Gary Olson
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users