473,796 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UDP Broadcast Issue

2 New Member
Hi,

I have a problem in receiving UDP broadcast data. We have a simple application which listens for the UDP broadcast data from the external servers. We can receive the UDP broadcast data from one of the servers. For the other external server, our program does not receive any data in the sockets, but we can see the broadcast data in tcpdump capture.

Is there any possible reason on why our sockets cannot receive the UDP broadcast, but the data can be seen in the capture?

I have given our sample application code below. Please help.

Thanks,
Ravi.

Expand|Select|Wrap|Line Numbers
  1. #define PORT 6515
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5. int sockfd;
  6. char buf[30];
  7. struct sockaddr_in sendaddr;
  8. struct sockaddr_in recvaddr;
  9. int numbytes;
  10. socklen_t addr_len;
  11. int broadcast=1;
  12. int reuse=1;
  13.  
  14. if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
  15. perror("socket");
  16. exit(1);
  17. }
  18. if ((setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
  19. &reuse, sizeof reuse)) == -1) {
  20. perror("setsockopt - SO_SOCKET ");
  21. exit(1);
  22. }
  23. if ((setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST,
  24. &broadcast, sizeof broadcast)) == -1) {
  25. perror("setsockopt - SO_SOCKET ");
  26. exit(1);
  27. }
  28. printf("Socket created\n");
  29. memset(&recvaddr, 0, sizeof recvaddr);
  30. recvaddr.sin_family = AF_INET;
  31. recvaddr.sin_port = htons(PORT);
  32. recvaddr.sin_addr.s_addr = INADDR_ANY;
  33. if (bind(sockfd, (struct sockaddr*)&recvaddr, sizeof recvaddr) == -1) {
  34. perror("bind");
  35. exit(1);
  36. }
  37. for (;;) {
  38. int n;
  39. fd_set set;
  40. struct timeval time_500ms = { 0, 500*1000 };
  41. FD_ZERO(&set);
  42. FD_SET(sockfd, &set);
  43.  
  44. n = select(sockfd+1, &set, NULL, NULL, &time_500ms);
  45. if (n < 0) {
  46. perror("select");
  47. break;
  48. }
  49. else if (n == 0) {
  50. printf("sleep(5)\n");
  51. sleep(5);
  52. }
  53. else if (!FD_ISSET(sockfd, &set)) {
  54. perror("FD_ISSET");
  55. break;
  56. }
  57. else {
  58. addr_len = sizeof sendaddr;
  59. if ((numbytes = recvfrom(sockfd, buf, sizeof buf, 0,
  60. (struct sockaddr *)&sendaddr, &addr_len)) > 0)
  61. {
  62. time_t now = time(NULL);
  63. printf("recvfrom: '%.*s' at %s\n", numbytes, buf, ctime(&now));
  64. }
  65. else
  66. perror("recvfrom");
  67. }
  68. }
  69. close(sockfd);
  70. return 0;
  71. }
Feb 4 '09 #1
1 7619
horace1
1,510 Recognized Expert Top Contributor
If you are using Winsock the fourth paramter to setsockopt() should be a char* and boradcast is an int
Expand|Select|Wrap|Line Numbers
  1. if ((setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST,
  2.     &broadcast, sizeof broadcast)) == -1) {
  3.  
see
http://msdn.microsoft.com/en-us/libr...76(VS.85).aspx

however, the open group specify the fourth parameter are a void* - depends on the system you are using

otherwise nothing obvious!
Feb 5 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3795
by: Ed L. | last post by:
I'm trying to load plperl to experiment with it in 7.3.4 with perl v5.8.0. I've basically tried the following: configure --with-perl, then initdb, then start postmaster, then createlang plplerl template1 No matter what I try, I keep getting this error:
12
1485
by: mike | last post by:
I have set up a FK as follows ALTER TABLE lk_sub_con ADD FOREIGN KEY (type) REFERENCES lk_sort_of_contact(type_code); However when I do this INSERT INTO lk_sort_of_contact (type_code) VALUES ('1') (ie: a NULL into the FK) it works
16
1947
by: D. Stimits | last post by:
A non-profit organization is interested in a new data application that would use a SQL storage system. I'm interested to know how non-profit companies that are not selling products are considered for licensing. Can they use PostgreSQL just like anyone else or do non-profits qualify as commercial use and need to consider other licensing? D. Stimits, stimits AT comcast DOT net ---------------------------(end of...
1
1768
by: Shelby Cain | last post by:
When I enable log_statement_stats AND log_parser_stats in my postgresql.conf file and attempt the start the service I receive the following error: "Could not start the PostgreSQL Database SErver 8.0-beta1 service on Local Computer. The service did not return an error." Attempting to start the server manually using the following commandline:
16
4301
by: Greg Donald | last post by:
Converting some MySQL code to work with Postgres here. I have this query: SELECT tasks.task_id, (tasks.task_duration * tasks.task_duration_type / count(user_tasks.task_id)) as hours_allocated FROM tasks LEFT JOIN user_tasks
2
6599
by: Gunnar_Frenzel | last post by:
Hello, this might be an easy question, but I don't have any handy solution at hand. I have an application that is supposed to send UDP broadcast. So far so easy, I did: Socket sockSendBroadcast = null; IPEndPoint ipeSendBroadcast = null; ipeSendBroadcast = new IPEndPoint(IPAddress.Broadcast, iSomePort);
10
4303
by: shsandeep | last post by:
The ETL application loaded around 3000 rows in 14 seconds in a Development database while it took 2 hours to load in a UAT database. UAT db is partitioned. Dev db is not partitioned. the application looks for existing rows in the table...if they already exist then it updates otherwise inserts them. The table is pretty large, around 6.5 million rows.
2
6551
by: OBones | last post by:
Hi all, I'm currently trying to receive replies to a UDP broadcast that I sent and I can't get it to work. I know the datagrams are sent as I see them with WireShark, but my C# code does not see them. Here is how I intended things to work: Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); try
0
2519
by: raviskar | last post by:
Hi, I have a problem in receiving UDP broadcast data. We have a simple application which listens for the UDP broadcast data from the external servers. We can receive the UDP broadcast data from one of the servers. For the other external server, our program does not receive any data in the sockets, but we can see the broadcast data in tcpdump capture. Is there any possible reason on why our sockets cannot receive the UDP broadcast, but the...
0
10461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9057
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.