I’m working on a C program that involves socket programming basically I’m trying to write a simple HTTP server I’m noob to this, and I’m encountering issues with binding. I’ve written the following code, but I’m getting errors during binding. I’ve checked the code and can’t seem to find the issue. Can anyone help me identify what’s wrong?
when i run the program i get this output
here is my code
#include <stdio.h>
#include <sys/socket.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#define PORT "4390"
int main(){
int status;
struct addrinfo hints, *res;
int sockfd;
memset(&hints,0, sizeof hints);
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
if((status = getaddrinfo("localhost",PORT,&hints,&res) != 0)){
fprintf(stderr,"getaddrinfo error: %sn",gai_strerror(status));
}
if((sockfd = socket(res->ai_family,res->ai_socktype,0) == -1)){
fprintf(stderr,"socket error %sn",gai_strerror(sockfd));
}
int bindstatus;
if((bindstatus = bind(sockfd,res->ai_addr,res->ai_addrlen) == -1)){
fprintf(stderr,"bind error %sn", gai_strerror(bindstatus));
}
printf("%dn",bindstatus);
return 0;
}