Can I bind a file descriptor returned by open call to a socket?
I am trying to do something like,
filefd = open("path",O_RDWR);
...
bind (filefd, (struct sockaddr *) &servaddr, sizeof(servaddr));
connfd = accept (filefd, (struct sockaddr *) &cliaddr, &clilen);
Why does the accept call return -1?
From an applications point of view, the difference is how you create and use the descriptor. Some system-calls can take any kind of descriptor, while others require a specific type of descriptor.
In your case the bind call would have returned -1 too, if you checked for the error. When a system-call returns -1 you should check errno to see what went wrong. You can use strerror to get a printable string of the error, or perror to print it directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With