LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-05-2004, 05:46 AM   #1
jylhar
LQ Newbie
 
Registered: Oct 2003
Posts: 1

Rep: Reputation: 0
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 */
...
********************************************************************
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDP packets dont seem to go out! linuxspartan Linux - Networking 2 11-06-2004 09:55 PM
udp packets m00t00 Programming 1 11-04-2004 09:20 PM
encapsulating TCP packets in UDP packets... yoshi95 Programming 3 06-03-2004 02:53 PM
How to receive UDP and ICMP packets, by one UDP socket(PMTUD) myself_rajat Linux - Networking 0 05-28-2004 05:43 AM
Only receiving UDP packets, no TCP erevlehdeux Linux - Networking 1 04-23-2004 07:36 PM


All times are GMT -5. The time now is 09:38 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration