473,508 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

invalid arguments in sendto()!!!!

1 New Member
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <netinet/ether.h>
#include <linux/if_packet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/socket.h> //for sockets
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <signal.h>
#include <linux/if_ether.h> //for ETH_P_802_2
#include <linux/if_packet.h> //for sockaddr_ll
#include <linux/filter.h>
#include <sys/types.h> //for sendto
#include "stp_bpdu.h"

struct bpdu_format
{
int bridge_id;
int port_id;
};

int main ()
{
struct bpdu_format bpdu;
struct sockaddr_in sin;
struct in_addr localInterface;
int fd;
bpdu.bridge_id=6969;
bpdu.port_id=04;
fd = socket(PF_PACKET, (int)SOCK_RAW, htons(ETH_P_802_2)); /* open socket */
if(fd==-1)
perror("socket failed to open\n");
else
printf("socket successfully created\n");
memset((char *) &sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr("239.168.140.22");
localInterface.s_addr = inet_addr("192.168.15.69");
if(setsockopt(fd,SOL_SOCKET, IP_MULTICAST_IF, (char *)&localInterface, sizeof(localInterface)) < 0)
{
perror("Setting local interface error\n");
exit(1);
}
else
printf("Setting the local interface...OK\n");
if(sendto(fd,(struct bpdu *)&bpdu, sizeof(struct bpdu_format), 0, (struct sockaddr *)&sin, sizeof(sin))<0)
{
perror("Sending message error");
}
else
printf("Sending message...OK\n");
close(fd);
return 0;
}


output:
socket successfully created....
Setting the local interface...OK
Sending message error: Invalid argument
Apr 26 '16 #1
1 1888
weaknessforcats
9,208 Recognized Expert Moderator Expert
This is a runtime error. Have you debugged into sendto() to see where the error occurs?

The compiler is happy with the code but sendto() isn't.

Presumably you are using debug libraries.
Apr 27 '16 #2

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

Similar topics

0
1384
by: J.V. | last post by:
I want to make localhost on my browser a sendto destination, so I can right click on an ASP or PHP file, choose sendto, then localhost and have a browser open up with the ASP file running in it. ...
1
2469
by: Chua Wen Ching | last post by:
Okay i stuck with something. This is more to c# rather than Directx! Just want to clarify it first. Right now, i am using a game engine which provide a function to get buffer for my input. ...
4
7284
by: B.r.K.o.N.j.A. | last post by:
I've been having trouble with sendto function (I open a socket, bind it to eth0, recvfrom works fine but when I execute following line I get sendto(): invalid argument) if(sendto(sokit, buf,...
4
12464
by: Just | last post by:
Hi everybody I was wondering if it is possible to use SendTo to send a whole IP package including header to another IP than specified in the package. Say I have a complete package and in it...
2
2035
by: melanieab | last post by:
Hi, I kind of got thrown into C# without any real programming experience, so I know this is probably an easy question, but it's driving me crazy. In my Tabs class, as I'm leaving a tabpage, I'm...
0
1193
by: j-in-uk | last post by:
According to research, I should convert to ToString() on my aspx but that does not seem to work in this case. Any ideas? CS1502: The best overloaded method match for...
7
8237
by: ataanis | last post by:
I'm currently using the function: sendto(sockfd, message, strlen(message), 0,&client_addr, addr_size) to sending a message back to a client, and I was wondering if there was a way of sending a...
2
3135
by: Christof Nordiek | last post by:
Hi all, I'm building an application, that should be started from the SendTo Menu. My Setup-Project puts a link into the SendTo Menu. But this works only for the User running the Setup. Even if...
0
1065
by: | last post by:
hello I write a little program, that receive as parameters some filepaths and use them. The program will be "put" into SendTo menu and be available from RightClick->SendTo menu. The problem...
4
2592
by: BlueJ | last post by:
My program is to send data using socket.. but I got the error message: "sendto(msg) points to uninitialised byte(s) " This is my source code 1. key_list = emalloc(BUFSIZE - sizeof(Key) -...
0
7229
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7129
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7333
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,...
0
7502
tracyyun
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...
1
5057
isladogs
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...
0
4716
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...
0
3208
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...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.