invalid arguments in sendto()!!!!

Discussion in 'Programming/Scripts' started by pradeep m p, Apr 22, 2016.

  1. pradeep m p

    pradeep m p 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

    please help me in solving this issue
     

Share This Page