2024-05-14 18:34:20 +07:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2024-05-14 20:44:39 +07:00
|
|
|
#define PORT 8080
|
|
|
|
|
2024-05-14 18:34:20 +07:00
|
|
|
int main() {
|
|
|
|
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if(sockfd == -1) {
|
|
|
|
perror("webserve (socket)");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
printf("socket created successfully\n");
|
|
|
|
|
2024-05-14 20:44:39 +07:00
|
|
|
struct sockaddr_in host_addr;
|
|
|
|
int host_addrlen = sizeof(host_addr);
|
|
|
|
|
|
|
|
host_addr.sin_family = AF_INET;
|
|
|
|
host_addr.sin_port = htons(PORT);
|
|
|
|
host_addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
|
|
|
|
|
|
if(bind(sockfd, (struct sockaddr *)&host_addr, host_addrlen) != 0) {
|
|
|
|
perror("webserver (bind)");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
printf("socket successfully bound to address\n");
|
|
|
|
|
2024-05-14 18:34:20 +07:00
|
|
|
return 0;
|
|
|
|
}
|