Is there a difference between the way the function recvfrom and sendto use the address structure.
When i use sento it works fine, but when I try and use recvfrom with the same variables it errors out with (bad address).
Or is there a better way to receive packets from a socket that i just sent to.
Theres some of my source code. -
-
struct sockaddr_in a;
-
a.sin_family = AF_INET;
-
a.sin_addr.s_addr = htonl(INADDR_ANY);
-
a.sin_port = htons(DefaultPort);
-
int sock;
-
sock = socket(AF_INET, SOCK_DGRAM, 0);
-
-
int fBroadcast = 1;
-
int err = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, "C", 5);
-
if (err == -1) { perror("setsockopt"); exit(1); }
-
-
//Binding the address to the socket
-
err = bind(sock, (struct sockaddr *)&a, sizeof(a));
-
if (err == -1) { perror("bind"); exit(1); }
-
-
-
//Putting the ip address in the socket output address structure
-
a.sin_addr.s_addr = inet_addr(ip);
-
-
-
//Sending the information to the specified port
-
if (sendto(sock, packet, len, 0, (struct sockaddr *)&a, sizeof(a)) == -1)
-
{ perror("sendto"); exit(1); }
-
-
int rcv;
-
char buf[300];
-
-
// Recieve
-
rcv = recvfrom(sock, buf, 208, MSG_WAITALL, (struct sockaddr *)&a , sizeof(a));
-
if(rcv == -1) { perror("recvfrom"); exit(1); }
-
-
2 5606
The variable a is a struct sockaddr_in.
You typecast the address of a to a struct sockaddr*.
The only way this will work is if struct sockaddr_in and struct sockaddr have the same members and each member has the same size.
Otherwise, you can't make a struct sockaddr out of a struct sockaddr_in just by typecasting an address.
Hi kardon33, did you find out the cause of the error. I also face same problem. The sendto with similar signature is able to send out packets, but recvfrom throws bad address, any one ideas?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Wim Deprez |
last post by:
Hi group,
I am trying to port a reliable multicast framework for UNIX to Win32 and so
far so good, but I stumbled on the next problem:
in the original code, the programmers use the recvmsg() function and as far
as I know, there is no Windows-version of this function. So I guess I will
have to translate it to a recvfrom(), but that gives some problems.
First of all, in the man pages I read the following:
|
by: William |
last post by:
I have declared the following struct:
struct PropagateInfo {
string type; // "registration", "gossip", "termination"
int initiatePeerID;
};
which I used as follows:
PropagateInfo* initiatePeerInfo = new PropagateInfo;
initiatePeerInfo->type = type; // type is set to "registration"
|
by: SWJust |
last post by:
Hi... is it possible to send data from a socket to at physical address (MAC)
on f.x another PC or Router ???
I have a IP header with information about another client, and this cannot be
altered, so I want to send the whole IP package to the server / router using
OSI layer 2 (datalink), but is it possible in C#, or do i have to write a
lowlevel driver.
Thanks
/Søren
|
by: D.Frangiskatos |
last post by:
Hi,
I have been working for a few months in project that deals
raw sockets. However recently, and while trying to examine
the contents of the buffer used in recvfrom i was a bit
confused. The buffer was allocated using malloc as it can
be seen next:
do
{
..............
|
by: Shoveler |
last post by:
I'm trying to send an ARP to determine different devices on the
network. I need to see the MAC address of my devices on my LAN. With
the MAC I can determine if I need to talk to that devices. I figured
the ARP is the best we to find who is out there. I'm using C# and the
Raw SocketType. I run into the WSACancelBlockingCall problem. Here's
my code:
Socket MyPing = new Socket(AddressFamily.InterNetwork,
SocketType.Raw ,...
| |
by: Jack |
last post by:
Hi guys,
I can't figure this out.
rec = recvfrom(sdUDP, buf, BUFSIZE, 0, (struct sockaddr
*)&connectChannel, &chanSizeUDP );
while(1){
if (rec 0){
snt = sendto(sdUDP, buf, rec, 0, (struct sockaddr
*)&connectChannel, chanSizeUDP );
rec = recvfrom(sdUDP, buf, BUFSIZE, 0, (struct sockaddr
|
by: windub |
last post by:
Hi...
I would like to capture an email address from a form and send a copy
of the mail to that user. Can anyone give the correct code?
Below is the script I am using.
Thanks for your help.
<?php
|
by: Jeff |
last post by:
Hi,
Fairly new to python, messing with some socket and pcap sniffing and
have come across the following issue while trying to do a pcap_loop
(via pcapy http://oss.coresecurity.com/projects/pcapy.html). I believe
i recall seeing similar stuff using other pcap libs with python in the
past (such as pylibpcap)
in a nutshell, blocking on a read using socket.recvfrom(buf), which
strace shows me is sitting in recvfrom(2) allows ctrl-c to be...
|
by: jkvbe |
last post by:
Hi,
I get a "Bad address" error message when trying to receive an ICMP timestamp
packet using recvfrom in cygwin. The packet is OK as I see it arriving when
sniffing the network.
Any ideas what can be wrong?
Thanks,
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: 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...
| |