bind to specific address

This commit is contained in:
Jay Sorg
2010-10-19 21:23:13 -07:00
parent bb7898419f
commit 1e8b5ea2cd
5 changed files with 45 additions and 7 deletions
+18
View File
@@ -450,6 +450,24 @@ g_tcp_local_bind(int sck, char* port)
#endif
}
/*****************************************************************************/
/* returns error, zero is good */
int APP_CC
g_tcp_bind_address(int sck, char* port, const char* address)
{
struct sockaddr_in s;
memset(&s, 0, sizeof(struct sockaddr_in));
s.sin_family = AF_INET;
s.sin_port = htons((tui16)atoi(port));
s.sin_addr.s_addr = INADDR_ANY;
if (inet_aton(address, &s.sin_addr) < 0)
{
return -1; /* bad address */
}
return bind(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
}
/*****************************************************************************/
/* returns error, zero is good */
int APP_CC