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. -
#define PORT 6515
-
-
int main(int argc, char *argv[])
-
{
-
int sockfd;
-
char buf[30];
-
struct sockaddr_in sendaddr;
-
struct sockaddr_in recvaddr;
-
int numbytes;
-
socklen_t addr_len;
-
int broadcast=1;
-
int reuse=1;
-
-
if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
-
perror("socket");
-
exit(1);
-
}
-
if ((setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
-
&reuse, sizeof reuse)) == -1) {
-
perror("setsockopt - SO_SOCKET ");
-
exit(1);
-
}
-
if ((setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST,
-
&broadcast, sizeof broadcast)) == -1) {
-
perror("setsockopt - SO_SOCKET ");
-
exit(1);
-
}
-
printf("Socket created\n");
-
memset(&recvaddr, 0, sizeof recvaddr);
-
recvaddr.sin_family = AF_INET;
-
recvaddr.sin_port = htons(PORT);
-
recvaddr.sin_addr.s_addr = INADDR_ANY;
-
if (bind(sockfd, (struct sockaddr*)&recvaddr, sizeof recvaddr) == -1) {
-
perror("bind");
-
exit(1);
-
}
-
for (;;) {
-
int n;
-
fd_set set;
-
struct timeval time_500ms = { 0, 500*1000 };
-
FD_ZERO(&set);
-
FD_SET(sockfd, &set);
-
-
n = select(sockfd+1, &set, NULL, NULL, &time_500ms);
-
if (n < 0) {
-
perror("select");
-
break;
-
}
-
else if (n == 0) {
-
printf("sleep(5)\n");
-
sleep(5);
-
}
-
else if (!FD_ISSET(sockfd, &set)) {
-
perror("FD_ISSET");
-
break;
-
}
-
else {
-
addr_len = sizeof sendaddr;
-
if ((numbytes = recvfrom(sockfd, buf, sizeof buf, 0,
-
(struct sockaddr *)&sendaddr, &addr_len)) > 0)
-
{
-
time_t now = time(NULL);
-
printf("recvfrom: '%.*s' at %s\n", numbytes, buf, ctime(&now));
-
}
-
else
-
perror("recvfrom");
-
}
-
}
-
close(sockfd);
-
return 0;
-
}
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 -
if ((setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST,
-
&broadcast, sizeof broadcast)) == -1) {
-
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!
Sign in to post your reply or Sign up for a free account.
Similar topics |
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:
|
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
|
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...
|
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:
|
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
| |
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);
|
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.
|
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
|
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...
|
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...
|
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...
| |
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |