Advertisement

Correct Syntax?

Started by August 28, 2003 01:42 PM
0 comments, last by WebsiteWill 21 years, 5 months ago
Hello. I''m noticing something strange happening with my program. If I run netstat -an in a command window while my program is running it does show that the ports are being used by UDP but it doesn''t give a status for them and the address listed is 0. UDP 0.0.0.0:7055 *:* UDP 0.0.0.0:7050 *:* I''m pretty sure this is not correct. I''ve looked over my code and can''t see what the problem is. Can someone take a look at it? Here is the code I use to setup the socket and various items.

int iSendSocket;
struct sockaddr_in serv_send_addr;
if ((iSendSocket = socket(AF_INET, SOCK_DGRAM, 0)) == -1) 
{
	perror("send socket");
	return false;
}

serv_send_addr.sin_family = AF_INET;
serv_send_addr.sin_port = htons(iSendPort);
if (serv_send_addr.sin_addr.s_addr = 
   inet_addr(sIPAddress.c_str()) == -1)
{
	cout << inet_addr(sIPAddress.c_str());
	perror("IP Address Bad");
	return false;
}
memset(&(serv_send_addr.sin_zero), ''\0'', 8);

if (bind(iSendSocket, (struct sockaddr *)&serv_send_addr,
			  sizeof(struct sockaddr)) == -1) 
{
	perror("bind");
	return false;
}
The iSendPort is a short I pass in and sIPAddress is a string I pass in that contains my IP address. Any help would be great. Thanks, Webby
The displayed address is fine.

UDP 0.0.0.0:7055 *:*

means that you''ve got a UDP socket bound to the local address INADDR_ANY (as opposed to some particular NIC) on port 7055. UDP does allow you to call connect() so that you can use send() instead of sendto() but you haven''t done that thus you get *:*. UDP doesn''t have true connections so there''s no concept of a connection status.
-Mike

This topic is closed to new replies.

Advertisement