|
UDP packets going nowhere
I'm trying to send and receive UDP packets between my linux machines. Problem is that my receiving end doesn't get anything. I can see with Ethereal that packets are really sent but that's it. So is there something wrong with my code or is the problem in my machines. I've tried to send to both machines and the result is always the same. Are there some port restrictions? I'm using ports 8003, 8004, 9003 and 9004. The 9000 ports are supposed to receive packets.
I'm really stuck with this so any help is greatly appreciated. Here's the critical parts of my code.
-Riikka
*************************************************************
Sending side:
static int udp_send;
static struct sockaddr_in local_send;
static struct sockaddr_in remote;
...
/* Sending socket */
udp_send = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(udp_send < 0) {
printf("UDP sending socket failed\n");
return -1; /* error */
}
local_send.sin_family = AF_INET;
local_send.sin_addr.s_addr = inet_addr(LOCAL_IP); /* 172.16.172.91 */
local_send.sin_port = htons(LOCAL_SENDING_PORT); /* 8003 */
bzero(&(local_send.sin_zero),8);
/* Binding sending socket to local address */
err = bind(udp_send, (struct sockaddr*)&local_send, sizeof(local_send));
if(err < 0) {
printf("UDP send bind failed\n");
close(udp_send);
return -1; /* error */
}
...
/* Remote server information */
remote.sin_family = AF_INET;
remote.sin_addr.s_addr = inet_addr(rem_ip_addr); /* 172.16.172.92 */
remote.sin_port = htons(rem_port); /* 9004 */
bzero(&(remote.sin_zero), 8);
...
/* Sending data to remote machine */
bytes_sent = sendto(udp_send, data, datasize, 0,
(struct sockaddr*)&remote, sizeof(remote));
if(bytes_sent < datasize) {
printf("Sending UDP packet failed\n");
return -1; /* error */
}
return 0; /* success */
*************************************************************************
Receiving end:
static int udp_recv;
static struct sockaddr_in local_recv;
...
/* receiving socket */
udp_recv = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(udp_recv < 0) {
printf("UDP receiving socket failed\n");
return -1; /* error */
}
local_recv.sin_family = AF_INET;
local_recv.sin_addr.s_addr = inet_addr(LOCAL_IP); /* 172.16.172.92 */
local_recv.sin_port = htons(local_port); /* 9004 */
bzero(&(local_recv.sin_zero),8);
/* Binding receiving socket to local address */
err = bind(udp_recv, (struct sockaddr*)&local_recv, sizeof(local_recv));
if(err < 0) {
printf("UDP recv bind failed\n");
close(udp_recv);
return -1; /* error */
}
...
int bytes_read, err, len;
struct sockaddr_in client;
len = sizeof(client);
/* This is where the receivind side jams */
bytes_read = recvfrom(udp_recv, buf, UDP_PACKET_SIZE, 0,
(struct sockaddr *) &client, &len);
/* Checking if whole UDP-packet was reveived */
...
********************************************************************
|