[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] Ethernet raw frames?
From: |
Michael Anburaj |
Subject: |
[lwip-users] Ethernet raw frames? |
Date: |
Fri, 7 Feb 2003 14:01:30 -0800 (PST) |
Hi,
I tried to run Adams example code (18.1 Using the API
from lwip.pdf - which I have also appended to this
email at the end) on my MIPS hardware running UCOS-II
RTOS. I came across this issue while doing the
following:
>From the PC, through Internet explorer (ie) browsed to
this URL http://169.254.140.28/. Where
169.254.140.28 is the IP address set on the MIPS
hardware.
The program on the MIPS side gets the HTTP GET packet
& executes the following lines of code.
/* Send the header. */
netconn_write(conn, http_html_hdr,
sizeof(http_html_hdr),
NETCONN_NOCOPY);
When this line gets executed, the following things
happen (I tried to follow the code as much as
possible, so let me know if I assumed things wrongly):
tcp_enqueue() gets called at some point <from
tcpip_thread>. It creates two pbufs, seg->p & p.
seg->p is of type PBUF_RAM.
p is of type PBUF_ROM
p is chained with seg->p. pbuf_chain(seg->p, p);
seg->p carries the ACK packet with the TCP header
p carries the pointer to the constant http_html_hdr.
And no header attached to it.
Later the IP layer calls the netif->output() function
with the pbuf (p chained to seg->p). Note: the 1st
Packet, ACK is complete with its header & stuff. But
the second packet has just the raw string contained in
http_html_hdr.
When this is sent to the PC, the Internet explorer
receives the following 2 packets:
ACK packet to IPAddress 169.254.140.27 <PCs IP
address> from 169.254.140.28 <MIPS hardware>
Ethernet II frame type (I guest its a raw ethernet
frame) to MAC address 43:6f:6e:74:65:6e from
74:2d:74:79:70:65. The string carried by
http_html_hdr, Content-type: text/html\r\n\r\n" is
getting interpreted for src & dst MAC addresses, since
this string is sent all by itself as raw frame.
This is the case with indexdata also.
Please bare with me, Though I have plenty of Embedded
Real-time experience with ARM & MIPS like RISCs.. I am
a newbe when it comes to ethernet & TCP/IP protocols.
So please answer to my questions below with as much
details as possible:
Is it ok for us (lwIP) to send the http_html_hdr
info as raw ethernet frame following the ACK packet
thats complete with TCP/IP headers?
If not why is this happening? Please help me resolve
this issue.
I can also send the Ethernet capture ran on the PC
using Ethereal. Actually the UCOS-II port running on
the MIPS Atlas board was done by me & I am trying to
get lwIP working on it. This is purely an experimental
project, which I am conducting at my Home. Just for
learning stuff about TCP/IP.
Thanks,
-Mike.
/* A simple HTTP/1.0 server using the minimal API. */
#include "lwip/sys.h"
#include "lwip/api.h"
#include "consol.h"
/* This is the data for the actual web page.
Most compilers would place this in ROM. */
const static char indexdata[] =
"<html> \
<head><title>A test page</title></head> \
<body> \
This is a small test page. \
</body> \
</html>";
const static char http_html_hdr[] =
"Content-type: text/html\r\n\r\n";
/* This function processes an incomming connection. */
static void process_connection(struct netconn *conn)
{
struct netbuf *inbuf;
char *rq;
u16_t len;
int i;
/* Read data from the connection into the netbuf
inbuf.
We assume that the full request is in the netbuf. */
if((inbuf = netconn_recv(conn)) == NULL)
{
netconn_close(conn);
return;
}
netbuf_data(inbuf, (void **)&rq, &len);
/* Check if the request was an HTTP "GET /\r\n". */
if(rq[0] == 'G' && rq[1] == 'E' &&
rq[2] == 'T' && rq[3] == ' ' &&
rq[4] == '/' && rq[5] == '\r' &&
rq[6] == '\n')
{
/* Send the header. */
if(netconn_write(conn, (void *)http_html_hdr,
sizeof(http_html_hdr), NETCONN_NOCOPY) != ERR_OK)
printf("***Write1Err***\n");
/* Send the actual web page. */
if(netconn_write(conn, (void *)indexdata,
sizeof(indexdata), NETCONN_NOCOPY) != ERR_OK)
printf("***Write2Err***\n");
/* Close the connection. */
netconn_close(conn);
}
}
static void
tcpecho_thread(void *arg)
{
struct netconn *conn, *newconn;
/* Create a new TCP connection handle. */
conn = netconn_new(NETCONN_TCP);
/* Bind the connection to port 80 on any local IP
address. */
netconn_bind(conn, NULL, 80);
/* Put the connection into LISTEN state. */
netconn_listen(conn);
/* Loop forever. */
while(1)
{
/* Accept a new connection. */
newconn = netconn_accept(conn);
if(newconn != NULL)
{
/* Process the incomming connection. */
process_connection(newconn);
/* Deallocate connection handle. */
netconn_delete(newconn);
}
}
}
void tcpecho_init(void)
{
sys_thread_new(tcpecho_thread, NULL);
}
void LAPP_vInit()
{
tcpecho_init();
/* Block for ever. */
sem = sys_sem_new(0);
sys_sem_wait(sem);
}
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
- [lwip-users] Ethernet raw frames?,
Michael Anburaj <=