¡Buenas a todos!
Tengo un problemilla con sprintf(). El problema esta en que me duplica la cadena y no coge bien las variables....
Esta es la funcion:
char * httpPacket(char *httpDatos){
char packet[65536]={""};
sprintf(packet
,"HTTP/1.1 200 OK\r\nDate: Thu, 22 Mar 2012 02:02:42 GMT\r\nContent-Type: text/html; charset-UTF-8\r\nContent-Encoding: gzip\r\nContent-Lengh: %d\r\nServer: gws\r\n\r\n%s",sizeof(httpDatos
), httpDatos
); printf("paquete: %s\n",packet
); return (char *) packet;
}
La variable httpDatos contiene codigo html...
Y el printf(packet) tiene como salida esto:
paquete: HTTP/1.1 200 OK
Date: Thu, 22 Mar 2012 02:02:42 GMT
Content-Type: text/html; charset-UTF-8
Content-Encoding: gzip
Content-Lengh: 4
Server: gws
HTTP/1.1 200 OK
Date: Thu, 22 Mar 2012 02:02:42 GMT
Content-Type: text/html; charset-UTF-8
Content-Encoding: gzip
Content-Lengh: 4
Server: gws
Cuando en realidad deberia ser asi:
paquete: HTTP/1.1 200 OK
Date: Thu, 22 Mar 2012 02:02:42 GMT
Content-Type: text/html; charset-UTF-8
Content-Encoding: gzip
Content-Lengh: 34
Server: gws
<html>
<h1>Prueba</h1>
</html>
Si os fijais, duplica la cabecera, pone mal el campo Content-Length y no muestra el codigo html...
¿Donde esta el fallo?