LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-15-2008, 10:23 AM   #1
revolt_
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Rep: Reputation: 0
Unhappy hello there! i need a bit of help


(sry for bad en)

i wana extact only a specific parts of a buffer that i recive from a socket conection.
i have allready socket conected to the server when i do this:

sprintf(buffer, "GET %sindex.php?username=root&password=ok HTTP/1.1\r\n"
"Host: %s\r\n"
"User-Agent: revolt\r\n"
"Keep-Alive: 300\r\n"
"Connection: keep-alive\r\n" "\r\n",username,inet_ntoa(t_in));

i recive a response from the server:

HTTP/1.1 302 Found
Date: Tue, 15 Jul 2008 14:53:29 GMT
Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.2 with Suhosin-Patch
X-Powered-By: PHP/5.2.4-2ubuntu5.2
Set-Cookie:
etc ....
Location: **//x.x.x.x/index.php?lang=en-utf-8&convcharset=iso-8859-1&collation_connection=utf8_unicode_ci&token=071a0fb26339b8123384b96d1310dd50
etc ...

**i leave the http cuze this forum doesnt detect the link

so from that buffer that i recived i wana extract the cookie info the location link to write other buffer and then log in on the web...


the response of the server i save it on buffer buff then i copy it to other buffer to extract the info (it is cuze i need extrac some info and if i use the same buff buffer it is broke when i use strtok() on it)

strcpy(dinamico, buff);

so the problem is when i try to extract the pice of info from that buffer
for example i am using:

char *pma_mcrypt_iv ;
char cry[256]; //enoug space for the pointer space

if(pma_mcrypt_iv = strstr(dinamico,"pma_mcrypt_iv=")){
pma_mcrypt_iv = strtok(pma_mcrypt_iv,";");
printf("%s\n",pma_mcrypt_iv);
// it prints ok:
// pma_mcrypt_iv=3gpe5PkvUso%3D
// that means the info was extracted
strcpy(cry,pma_mcrypt_iv);
// then copy it to a char array
}
the is the way to extract 10 cokkie info thati used ... then
after i check in printf that all info are printed ok on the pointers

then i think is done so in build the new response to the server

sprintf(response,"GET /index.php?%s HTTP/1.1\r\n"
"Connection: close"
"Host: %s",link,...);
etc ...

then i print the buffer to see if everithin its ok

but

GET /index.php?%s HTTP/1.1
it wuold be
GET /index.php?1token=071a0fb26339b8123384b96d1310dd50 HTTP/1.1


but


HTTP/1.1token=071a0fb26339b8123384b96d1310dd50

doesnt show correctly
some happends whit the char array that is a copy of the pointer

and of course when i send the response to the server it respond me whit
<title>501 Method Not Implemented</title>
=(


i think is the way, iam using to extrac the info, cuze of course buffers before of this all work ok


so somebody see a err ?
somebody can explainme or paste some code of how to extract info from a buffer an save it into a array?
i there a way to fill a sprintf() whit pointers ?


thnx guys =)

Last edited by revolt_; 07-15-2008 at 11:47 AM.
 
Old 07-15-2008, 10:50 AM   #2
revolt_
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Original Poster
Rep: Reputation: 0
if(ptr = strstr(dinamico,"token=")){
ptr = strtok(ptr,"\n");



i think this the porblem
i can do a strtok whit a pointer?
and then asing it to the same pointer?

i shows ok the info extracted but when i use sprintf()

the buffer isnt filled ok

Last edited by revolt_; 07-15-2008 at 11:48 AM.
 
Old 07-15-2008, 11:26 AM   #3
revolt_
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Original Poster
Rep: Reputation: 0
[4bytes]HTTP/1.1[rest of the string]=f87963771c3eed90bad6dc57c8290c66

sizeof ptr 4
sizeof link 1024

the ptr pointer has 4 bytes is the
space on the formed string
its cuze it wont copy all string

and when i copy the pointer to the char array it copyes equal
so the result its a malformed string

printf("GET %s HTTP/1.1\n",link);
printf("sizeof ptr %d\n",sizeof(ptr));
printf("sizeof link %d\n",sizeof(link));



is there anyway to convert a pointer into a string in c ?
strcpy(string,pointer); doesnt work...

i am tryn whit calloc or malloc

Last edited by revolt_; 07-15-2008 at 11:27 AM. Reason: ok
 
Old 07-15-2008, 11:43 AM   #4
revolt_
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Original Poster
Rep: Reputation: 0
is there a way, to copy all the content of a pointer into a char array ?
or a better way to find a word into a buffer and then save it into a array ?


i used this:

char *pma_mcrypt_iv;
char link[256];

// search the fisrts aparition of pma_mcrypt_iv= on the buffer dinamico
// then asing it to a pma_mcrypt_iv
// then to pma_mcrypt_iv we use strtok() to boke the buffer into tokens
// and use ; how key so the of this i have the correct string

Set-Cookie: pma_mcrypt_iv=V8527D496HM%3D; expires=Thu, 14-Aug-2008 16:36:12 GMT; httponly


if(pma_mcrypt_iv = strstr(dinamico,"pma_mcrypt_iv=")){
pma_mcrypt_iv = strtok(pma_mcrypt_iv,";");
printf("%s\n",pma_mcrypt_iv);
strcpy(cry,pma_mcrypt_iv);
}

pma_mcrypt_iv=V8527D496HM%3D
after this if()

then i wana copy it into a char array to use it into a sprintf()

but ... copy only 4 bytes to the array
and when try to build a buffer whit sprintf() it isnt correct

[4bytes of the pointer](HTTP/1.1)-->text on the sprintf()[rest of the string of the char]=f87963771c3eed90bad6dc57c8290c66


any suguest or ideas ?

Last edited by revolt_; 07-15-2008 at 11:45 AM.
 
Old 07-15-2008, 04:27 PM   #5
revolt_
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Original Poster
Rep: Reputation: 0
come on, nobody can help me?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
64 bit cpu-64 bit Ubuntu-are there 32 bit app issues? sofasurfer Ubuntu 7 04-09-2014 02:02 PM
64-bit or 32-bit Application on 64-bit Linux jjana123 Linux - General 4 05-06-2008 05:27 PM
Triple Boot Suse 10.3 32 bit, suse alpha 11.0 64 bit and Windows XP (32 Bit) 1kyle SUSE / openSUSE 1 02-28-2008 10:25 AM
Integrated 16-bit Sound Blaster Pro compatible audio 24-bit DAC jelgavchik Linux - Hardware 1 11-16-2006 05:31 PM
32 bit or 64 bit install - is 32 bit easier for a newbie? dms05 Linux - Newbie 3 05-19-2006 03:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration