从C中从HTTP标头中提取数据
我想使用C从HTTP标头中提取一些数据来执行一些检查。这是我用来提取数据的代码。在这里,我只是想检查sec-websocket-key
是否为13。
我已经使用libpcap将PCAP文件读为命令行参数。
const u_char *payload;
payload = packet+total_headers_size
const u_char *token;
token = strtok(payload, "\r\n\r\n");
while (token)
{
printf("Current token: %s\n", token);
const u_char *buff;
sprintf(buff,"%s",token);
/*if(strcmp(token,"HTTP/1.1 101 Switching Protocols")==0)
{
printf("Protocol switched\n");
}*/
if(strcmp(buff,"Sec-WebSocket-Version: 13")==0)
{
printf("Correct Version\n");
}
//printf("%d\n",sec);
token = strtok(NULL, "\n");
}
变量有效载荷
包含HTTP标头请求,并且我基于\ r \ n \ r \ r \ n
将标头拆分,但是我没有得到所需的输出。 total_headers_size
是以太网标头LEN,IP标头LEN和TCP标头LEN的总和。
I want to extract some data from an HTTP header using C to perform some checks. This is the code that I am using to extract the data. Here I am just trying to check whether the Sec-WebSocket-Key
is 13 or not.
I have used libpcap to read the pcap file as a command line argument.
const u_char *payload;
payload = packet+total_headers_size
const u_char *token;
token = strtok(payload, "\r\n\r\n");
while (token)
{
printf("Current token: %s\n", token);
const u_char *buff;
sprintf(buff,"%s",token);
/*if(strcmp(token,"HTTP/1.1 101 Switching Protocols")==0)
{
printf("Protocol switched\n");
}*/
if(strcmp(buff,"Sec-WebSocket-Version: 13")==0)
{
printf("Correct Version\n");
}
//printf("%d\n",sec);
token = strtok(NULL, "\n");
}
The variable payload
contains the HTTP header request and I have split the header based on \r\n\r\n
, but I am not getting the desired output. Total_headers_size
is the sum of the Ethernet header len, IP header len, and TCP header len.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论