In a test program I want to specify the source port of socket
connection.
The code like this. Because this is a test program, some error check
code is
omitted.
SOCKET hSocket = socket(AF_INET, SOCK_STREAM, 0);
BOOL bReuse = TRUE;
setsockopt(hSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&bReuse,
sizeof(BOOL));
sockaddr_in bindAddr = {0};
bindAddr.sin_family = AF_INET;
bindAddr.sin_addr.s_addr = INADDR_ANY;
bindAddr.sin_port = htons(7000);
int iBindRet = bind(hSocket, (LPSOCKADDR)&bindAddr,
sizeof(bindAddr));
if (iBindRet == SOCKET_ERROR) {
printf("Bind error:%d\n", GetLastError());
}
I find if my computer dial up to internet, bind will fail with error
code
WSAEACCES, otherwise bind success. What's the reason? I can't bind a
socket
to an internet address?
Thanks,
bucher
> I find if my computer dial up to internet, bind will fail with error
> code
> WSAEACCES, otherwise bind success. What's the reason? I can't bind a
> socket
> to an internet address?
Most likely, you have some kind of firewall installed and enabled.
DS