errno 48 on bind() call
I am trying to open a socket connection on a Mac OS laptop to receive data from a process on another (Linux) machine.
I am using the code sequence shown below (slightly edited), which works when both machines are Linux (so I am not showing the other end).
The code is being compiled with gcc on the Mac--no errors or warnings.
The code fails at the bind() call and my error handling code says the system error (errno variable) is 48. There is no perror command on the Mac, but the Linux perror says this error number means "Link number out of range". I cannot find any information on this system error. I am sure that the variable "nrp1" in the code
is equal to 10003, the port I am trying to use here, which the other system understands and which is "unassigned" in /etc/services. Also, the variable fd->URF.SOCK.isfd contains the standard integer file descriptor returned by the socket() call earlier in the code, which is this:
fd->URF.SOCK.isfd = socket(PR_INET, SOCK_STREAM, 0) (and is known to return a nonzero file descriptor).
Any suggestions?
----Relevant code fragment----
struct sockaddr_in initaddr; |
int iru = 1; | /* To allow fast reuse */ | |
if (setsockopt(fd->URF.SOCK.isfd, SOL_SOCKET, SO_REUSEADDR, | ||
&iru, sizeof(iru)) < 0) { kexit = 8; goto ERROR98; } |
memset((char *)&initaddr, 0, sizeof(struct sockaddr_in)); | |
initaddr.sin_family = AF_INET; | |
if (nrp1 <= 0) { kexit = 4; goto ERROR98; } | |
initaddr.sin_port = htons(nrp1); | |
/* Expt added 03/30/16, GNR - INADDR_ANY is 0 on Linux */ | |
initaddr.sin_addr.s_addr = htonl(INADDR_ANY); | |
if (bind(fd->URF.SOCK.isfd, (struct sockaddr *)&initaddr, | |
sizeof(initaddr)) < 0) | |
{ kexit = 5; goto ERROR98ME; } |
Thanks, gnreeke
MacBook Pro, OS X El Capitan (10.11.3)