Generation

generate functionSun, 13 Nov 2022

get http headers from socket

#include <stdio.h> #include <string.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <ctype.h> #include <stdlib.h> #include <unistd.h> int main(int argc, const char *argv[]) { char buffer[1024] = {0}; int sockfd = 0; struct sockaddr_in server_info; int num = 0; char request[1024] = {"GET / HTTP/1.0\r\n\r\n"}; if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("socket error"); return -1; } server_info.sin_family = AF_INET; server_info.sin_addr.s_addr = inet_addr("127.0.0.1"); server_

Questions about programming?Chat with your personal AI assistant