Files
42_SIDE_exam_06_miniserv/mini_serv.c
2023-02-06 18:43:40 +01:00

88 lines
1.6 KiB
C

//#include <errno.h>
//#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
// accept
// atoi
// bind
// bzero
// calloc
// close
// exit
// free
// listen
// malloc
// memset
// realloc
// recv
// select
// send
// socket
// sprintf
// strcat
// strcpy
// strlen
// strstr
// write
void putstr(int fd, char *str) {
write(fd, str, strlen(str));
}
void error(char *str, int code) {
putstr(2, str);
exit(code);
}
int main(int ac, char **av) {
int port;
int sockfd;
// int connfd;
// int len;
struct sockaddr_in servaddr;
// struct cli;
if (ac < 1)
error("Wrong number of arguments\n", 1);
port = atoi(av[1]);
if (port == -1)
error("Fatal error\n", 1);
// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
error("socket creation failed...\n", 0);
else
putstr(1, "Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(2130706433); //127.0.0.1
servaddr.sin_port = htons(8081);
// // Binding newly created socket to given IP and verification
// if ((bind(sockfd, (const struct sockaddr *)&servaddr, sizeof(servaddr))) != 0) {
// printf("socket bind failed...\n");
// exit(0);
// }
// else
// printf("Socket successfully binded..\n");
// if (listen(sockfd, 10) != 0) {
// printf("cannot listen\n");
// exit(0);
// }
// len = sizeof(cli);
// connfd = accept(sockfd, (struct sockaddr *)&cli, &len);
// if (connfd < 0) {
// printf("server acccept failed...\n");
// exit(0);
// }
// else
// printf("server acccept the client...\n");
}