By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,813 Members | 2,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,813 IT Pros & Developers. It's quick & easy.

invalid arguments in sendto()!!!!

P: 1
#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;
fd = socket(PF_PACKET, (int)SOCK_RAW, htons(ETH_P_802_2)); /* open socket */
perror("socket failed to open\n");
printf("socket successfully created\n");
memset((char *) &sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr("");
localInterface.s_addr = inet_addr("");
if(setsockopt(fd,SOL_SOCKET, IP_MULTICAST_IF, (char *)&localInterface, sizeof(localInterface)) < 0)
perror("Setting local interface error\n");
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");
printf("Sending message...OK\n");
return 0;

socket successfully created....
Setting the local interface...OK
Sending message error: Invalid argument
Apr 26 '16 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,197
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

Post your reply

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