Hi, I am new around here but was hoping I may receive some guidance. I have limited experience with C as well as network programming but nevertheless I have a project in which I am trying to simulate a browser requesting a video file. Knowing that creating an HTTP server might be pretty involved so I used some sample code namely the Tiny Web server code (tiny.tar) from CS:APP2e, Bryant and O'Hallaron. When I tried running said code on an unix server. i get the following
Open_listenfd error: Permission denied
This is what the function open_listenfd does:
Code:
int open_listenfd(int port)
{
int listenfd, optval=1;
struct sockaddr_in serveraddr;
/* Create a socket descriptor */
if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
return -1;
/* Eliminates "Address already in use" error from bind. */
if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR,
(const void *)&optval , sizeof(int)) < 0)
return -1;
/* Listenfd will be an endpoint for all requests to port
on any IP address for this host */
bzero((char *) &serveraddr, sizeof(serveraddr));
serveraddr.sin_family = AF_INET;
serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
serveraddr.sin_port = htons((unsigned short)port);
if (bind(listenfd, (SA *)&serveraddr, sizeof(serveraddr)) < 0)
return -1;
/* Make it a listening socket ready to accept connection requests */
if (listen(listenfd, LISTENQ) < 0)
return -1;
return listenfd;
}
/* $end open_listenfd */
So my understanding is that open_listenfd merely opens/create a listening socket. Please let me know what might be preventing me from doing so (do I need to create my own listen socket code or if I need to use a specific port?). I just want to see how a HTTP server works and then determine how to create an HTTP GET request for a video file. Also please feel free to direct me to any resources that might help me accomplishing this endeavor.
Thanks!