Forum Discussion
Altera_Forum
Honored Contributor
13 years ago --- Quote Start --- I'm trying to learn more about port forwarding and concerning the code that you gave me, what is sendbuff.. It is generating an error during compilation! I am new to C programming so I would really appreciate your help.. --- Quote End --- 'sendbuff' is a variable that needs to be declared within the http.c file - something I forgot to mention in my description. Insert this code segment char sendbuff[768]; just below the two existing variable declarations in the http_find_file() function so that it looks like this: int http_find_file(http_conn* conn) { printf( "I'm at http_find_file...\n\n" ); alt_u8 filename[256]; int ret_code = 0; char sendbuff[768]; What you are doing here is reserving 768 bytes of memory that becomes the buffer that sprintf() puts the HTML formatted text string into. We use sprintf() as a convenient way to pick up the variables we want to include in the HTML text. Then the send() function pushes the string out through the socket connection to the requesting HTTP client, as in the following line: send(conn->fd,(void*)sendbuff,strlen(sendbuff),0); // send ip config html page
The conn->fd is the socket connection, sendbuff is our buffer which now contains the HTML text string, strlen(sendbuff) returns the size of the string in the buffer so send() knows when to quit, and 0 is the offset from the beginning of the buffer where we begin sending. There's nothing magical about this number 768, I just kept increasing the buffer size until it was big enough to hold my HTML code. If you want to send more HTML code than fits in this buffer, just increase its size. I have only been studying C programming for about three months, so you are not far behind. It's terribly confusing at first, but it gradually falls into place. Trying to figure out existing code that you know works is a good way to reinforce your leaning.