You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.0 KiB
42 lines
1.0 KiB
#include "proxy.h" |
|
|
|
void proxy_startListener(unsigned int port){ |
|
// https://www.geeksforgeeks.org/socket-programming-cc/ |
|
int server_fd, new_socket; |
|
struct sockaddr_in address; |
|
int opt = 1; |
|
int addrlen = sizeof(address); |
|
char line[1024] = {0}; |
|
|
|
// Creating socket file descriptor |
|
if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0) { |
|
perror("socket failed"); |
|
return ; |
|
} |
|
|
|
address.sin_family = AF_INET; |
|
address.sin_addr.s_addr = htonl(INADDR_ANY); |
|
address.sin_port = htons( port ); |
|
|
|
// Forcefully attaching socket to the port 8080 |
|
if (bind(server_fd, (struct sockaddr *)&address, sizeof(address))<0) { |
|
perror("bind failed"); |
|
return ; |
|
} |
|
|
|
if (listen(server_fd, 3) < 0) { |
|
perror("listen"); |
|
return ; |
|
} |
|
while ( true ){ |
|
printf("Listening\n"); |
|
if ((new_socket = accept(server_fd, (struct sockaddr *)&address, |
|
(socklen_t*)&addrlen))<0) { |
|
perror("accept"); |
|
return ; |
|
} |
|
|
|
Request *request = newRequestFromSocket(new_socket); |
|
} |
|
|
|
}
|
|
|