Sponsored Content
Top Forums Programming Need help regarding HTTP parsing Post 302340727 by rakesh_01 on Tuesday 4th of August 2009 09:01:34 AM
Old 08-04-2009
Need help regarding HTTP parsing

Hi..

I've got a program that can connects to a remote server and displays some garbage value and closes the connection.

The code goes like this

Code:
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>


int main(int argc,char argv[])
{
int connectres,bytes,i=0,sock,len;
struct sockaddr_in connto;

struct hostent *server;
char source[2048];
char buffer[256];
char *outmsg="GET  / HTTP/1.1";
sock=socket(AF_INET,SOCK_STREAM,0);
connto.sin_family=AF_INET;
connto.sin_port=htons(80);
connto.sin_addr.s_addr=inet_addr("74.125.67.100");

if(connectres=connect(sock,(struct sockaddr*)&connto,sizeof(struct sockaddr))==-1)
{
perror("unable to connect");
return -3;
}

printf("connection successful \n");
len=strlen(outmsg);
bytes=send(sock,outmsg,len,0);
printf("bytes sent are %d \n",bytes);

bzero(buffer,256);

do
{
i=recv(sock,buffer,sizeof(buffer),0);
printf("still recieving data \n");
strcat(source,buffer);
printf("%s",source);
bzero(buffer,256);
}while(i!=0);

//closing socket
printf("closing socket \n");

close(sock);
}

can someone pls help me out...
I've really got no clue as to wat to do????

Last edited by vino; 08-05-2009 at 03:15 AM.. Reason: Added code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

HTTP Query Request & Parsing returned XML output

I have a PERL script from which I need to make a HTTP request to Web Servlet (Essentially a URL with variables and values like &Variable1=AAAAAA&Variable2=BBBBBBBBB&Variable3=CCCCCCC). The Web servlet returns an XML result which needs to be parsed for the contents of the result within the program.... (15 Replies)
Discussion started by: jerardfjay
15 Replies

2. UNIX for Advanced & Expert Users

http

how to downloaad a web page using http server (0 Replies)
Discussion started by: krishnavel
0 Replies

3. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

4. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

5. Linux

Dynamic HTTP

hi guys, please i would like to know how to cache dynamic websites, on squid 3.1 thanks (1 Reply)
Discussion started by: zazoo
1 Replies

6. Programming

sending http url through http socket programming..

hi am senthil am developing a software to send and receive SMS using HTTP connection first of all am forming a URL and sending that URL to a remote server using my Client Program i send that url through Socket(using Send() Function) if i send more than one URL one by one using the same... (0 Replies)
Discussion started by: senkerth
0 Replies

7. Shell Programming and Scripting

sending http url through http socket programming..

hi am senthil am developing a software to send and receive SMS using HTTP connection first of all am forming a URL and sending that URL to a remote server using my Client Program i send that url through Socket(using Send() Function) if i send more than one URL one by one using the same... (4 Replies)
Discussion started by: senkerth
4 Replies

8. Shell Programming and Scripting

Parsing the http post request

Hi, I am trying to write a shell script to parse the post request data that it received to a xml file. Below is the post request data that script is receiving. -----------------------------7dd2339190c8e Content-Disposition: form-data; name="param1" 1... (2 Replies)
Discussion started by: jdp
2 Replies

9. Web Development

HTTP Headers Reference: HTTP Status-Codes

Hypertext Transfer Protocol -- HTTP/1.1 for Reference - HTTP Headers 10 Status Code Definitions Each Status-Code is described below, including a description of which method(s) it can follow and any metainformation required in the response. (1 Reply)
Discussion started by: Neo
1 Replies

10. Shell Programming and Scripting

awk script to find time difference between HTTP PUT and HTTP DELETE requests in access.log

Hi, I'm trying to write a script to determine the time gap between HTTP PUT and HTTP DELETE requests in the HTTP Servers access log. Normally client will do HTTP PUT to push content e.g. file_1.txt and 21 seconds later it will do HTTP DELETE, but sometimes the time varies causing some issues... (3 Replies)
Discussion started by: Juha
3 Replies
G15daemon Client Development()											    G15daemon Client Development()

NAME g15daemon_client - G15Daemon Server / Client communication for g15daemon.
SYNOPSIS
#include <libg15.h> #include <g15daemon_client.h> link with -lg15daemon_client int new_g15_screen(int screentype); int g15_close_screen(int sock); int g15_send(int sock, char *buf, unsigned int len); int g15_recv(int sock, char *buf, unsigned int len); int g15_send_cmd (int sock, unsigned char command, unsigned char value); G15Daemon Server / Client communication G15Daemon uses INET sockets to talk to its clients, listening on localhost port 15550 for connection requests. Once connected, the server sends the text string "G15 daemon HELLO" to confirm to the client that it is a valid g15daemon process, creates a new screen, and waits for LCD buffers or commands to be sent from the client. Clients are able to create multiple screens simply by opening more socket connections to the server process. If the socket is closed or the client exits, all LCD buffers and the screen associated with that socket are auto- matically destroyed. Clients wishing to display on the LCD must send entire screens in the format of their choice. Currently partial screen updates (icons etc) are not supported. G15Daemon commands are sent to the daemon via the OOB (out-of-band) messagetype, replies are sent inband back to the client. int new_g15_screen(int screentype) Opens a new connection and returns a network socket for use. Creates a screen with one of the following pixel formats defined in g15dae- mon_client.h: G15_PIXELBUF: this buffer must be exactly 6880 bytes, and uses 1 byte per pixel. G15_TEXTBUF: currently ignored by the daemon. G15_WBMPBUF: this is a packed pixel buffer in WBMP format with 8 pixels per byte. Useful for perl programmers using the GD:: and G15Dae- mon.pm (see lang_bindings directory) perl modules. G15_G15RBUF: another packed pixel buffer type, also with 8 pixels/byte, and is the native libg15render format. Example of use: int screen_fd = new_g15_screen( G15_WBMPBUF ); int g15_close_screen (int screen_fd) Simply closes a socket previously opened with new_g15_screen(). The daemon will automatically clean up any buffers and remove the LCD screen from the display list. Returns 0 if successful, or errno if there was an error. Example: int retval = 0; int screen_fd = new_g15_screen( G15_WBMPBUF ); ... do processing and display here ... retval = g15_close_screen( screen_fd ); int g15_send (int sock, char *buf, unsigned int len) A simple wrapper around send() to ensure that all 'len' bytes of data is sent to the daemon. It simply uses poll() to block until the entire message is sent. Returns 0 on success, -1 if the send failed due to timeout or socket error. int g15_recv (int sock, char *buf, unsigned int len) A simple wrapper around recv() to ensure that all 'len' bytes of data are received from the daemon. It simply uses poll() to block until the entire message is received. Returns 0 on success, -1 if the recv failed due to timeout or socket error. int g15_send_cmd ( int sock, unsigned char command, unsigned char value) Sends a command to the daemon (possible commands are listed below). Returns 0 or the return value of the command on success, -1 on fail- ure. See examples for usage. G15Daemon Command Types Commands and requests to the daemon are sent via OOB data packets. Changes to the backlight and mkey state will only affect the calling client. The following commands are supported as defined in g15daemon_client.h: G15DAEMON_KEY_HANDLER Requests that all M and G key presses are sent to this client. All keys are packed into an unsigned int, and sent to the client inband when a key is pressed. G15DAEMON_MKEYLEDS Sets the M key LED state. In order to change LED state, each LED that is to be turned on is OR'd with the command byte. See libg15.h for values. For examples see the end of this document. G15DAEMON_BACKLIGHT Sets the LCD Backlight brightness. Brightness level (0|1|2) is OR'd with the command byte. For examples see the end of this docu- ment. G15DAEMON_CONTRAST Sets the LCD contrast. Contrast level (0|1|2) is OR'd with the command byte. For examples see the end of this document. G15DAEMON_GET_KEYSTATE Requests a packet containing the current keystate. The daemon will return an unsigned int containing any keys pressed. See libg15.h for details on key values, and lcdclient_test.c in the source distribution for an example. G15DAEMON_SWITCH_PRIORITIES Toggles the client's LCD screen to/from the front. Clients can check their foreground/background state with the following: G15DAEMON_IS_FOREGROUND On reciept of this command, G15Daemon will send a 1 byte packet back with the value 1 if the client is foreground, or 0 if not. G15DAEMON_IS_USER_SELECTED On reciept of this command, G15daemon will return a byte indicating if the user selected the client be foreground or background. EXAMPLES
Below is a completely nonsensical client which (poorly) demonstrates the usage of most of the commands. --- Cut here --- #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <errno.h> #include <poll.h> #include <g15daemon_client.h> #include <libg15.h> /* #define TEST_KEYHANDLER */ int main(int argc, char *argv[]) { int g15screen_fd, retval; char lcdbuffer[6880]; unsigned int keystate; char msgbuf[256]; int foo = 0; if((g15screen_fd = new_g15_screen(G15_PIXELBUF))<0){ printf("Sorry, cant connect to the G15daemon0); return 5; }else printf("Connected to g15daemon. sending image0); if(argc<2) retval = g15_send(g15screen_fd,(char*)logo_data,6880); else { memset(lcdbuffer,0,6880); memset(lcdbuffer,1,6880/2); retval = g15_send(g15screen_fd,(char*)lcdbuffer,6880); } printf("checking key status - press G1 to exit0,retval); while(1){ keystate = 0; int foo; keystate = g15_send_cmd (g15screen_fd, G15DAEMON_GET_KEYSTATE, foo); if(keystate) printf("keystate = %i0,keystate); if(keystate & G15_KEY_G1) //G1 key. See libg15.h for details on key values. break; /* G2,G3 & G4 change LCD backlight */ if(keystate & G15_KEY_G2){ retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_DARK); } if(keystate & G15_KEY_G3){ retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_MEDIUM); } if(keystate & G15_KEY_G4){ retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_BRIGHT); } /* is this client in the foreground?? */ retval = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, foo); if(retval) printf("Hey, we are in the foreground, Doc0); else printf("What dastardly wabbit put me in the background?0); retval = g15_send_cmd (g15screen_fd, G15DAEMON_IS_USER_SELECTED, foo); if(retval) printf("You wanted me in the foreground, right Doc?0); else printf("You dastardly wabbit !0); if(retval){ /* we've been backgrounded! */ sleep(2); /* remain in the background for a bit */ retval = g15_send_cmd (g15screen_fd, G15DAEMON_SWITCH_PRIORITIES, foo); sleep(2); /* switch to foreground */ retval = g15_send_cmd (g15screen_fd, G15DAEMON_SWITCH_PRIORITIES, foo); } usleep(500); #ifdef TEST_KEYHANDLER /* ok.. request that all G&M keys are passed to us.. */ retval = g15_send_cmd (g15screen_fd, G15DAEMON_KEY_HANDLER, foo); while(1){ printf("waiting on keystate0); keystate=0; retval = recv(g15screen_fd, &keystate , sizeof(keystate),0); if(keystate) printf("Recieved %i as keystate",keystate); } #endif } g15_close_screen(g15screen_fd); return 0; } -- end cutting -- G15Daemon 1.0 G15daemon Client Development()
All times are GMT -4. The time now is 06:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy