<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Iam facing a problem in sendto()....telling invalid arguments. in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Iam-facing-a-problem-in-sendto-telling-invalid-arguments/m-p/470063#M15578</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;CODE&gt;#include &amp;lt;netinet/in.h&amp;gt;&lt;BR /&gt;#include &amp;lt;arpa/inet.h&amp;gt;&lt;BR /&gt;#include &amp;lt;net/if.h&amp;gt;&lt;BR /&gt;#include &amp;lt;netinet/ip.h&amp;gt;&lt;BR /&gt;#include &amp;lt;netinet/udp.h&amp;gt;&lt;BR /&gt;#include &amp;lt;netinet/ether.h&amp;gt;&lt;BR /&gt;#include &amp;lt;linux/if_packet.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;BR /&gt;#include &amp;lt;string.h&amp;gt;&lt;BR /&gt;#include &amp;lt;fcntl.h&amp;gt;&lt;BR /&gt;#include &amp;lt;sys/ioctl.h&amp;gt;&lt;BR /&gt;#include &amp;lt;sys/socket.h&amp;gt; //for sockets&lt;BR /&gt;#include &amp;lt;net/if.h&amp;gt;&lt;BR /&gt;#include &amp;lt;netinet/in.h&amp;gt;&lt;BR /&gt;#include &amp;lt;arpa/inet.h&amp;gt;&lt;BR /&gt;#include &amp;lt;unistd.h&amp;gt;&lt;BR /&gt;#include &amp;lt;signal.h&amp;gt;&lt;BR /&gt;#include &amp;lt;linux/if_ether.h&amp;gt; //for ETH_P_802_2&lt;BR /&gt;#include &amp;lt;linux/if_packet.h&amp;gt; //for sockaddr_ll&lt;BR /&gt;#include &amp;lt;linux/filter.h&amp;gt; &lt;BR /&gt;#include &amp;lt;sys/types.h&amp;gt; //for sendto&lt;BR /&gt;#include "stp_bpdu.h"&lt;BR /&gt;&lt;BR /&gt;struct bpdu_format&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; int bridge_id;&lt;BR /&gt;&amp;nbsp; int port_id;&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;int main ()&lt;BR /&gt;{&amp;nbsp; &lt;BR /&gt;&amp;nbsp; struct bpdu_format bpdu;&lt;BR /&gt;&amp;nbsp; struct sockaddr_in sin;&lt;BR /&gt;&amp;nbsp; struct in_addr localInterface;&lt;BR /&gt;&amp;nbsp; int fd;&lt;BR /&gt;&amp;nbsp; bpdu.bridge_id=6969;&lt;BR /&gt;&amp;nbsp; bpdu.port_id=04;&lt;BR /&gt;&amp;nbsp; fd = socket(PF_PACKET, (int)SOCK_RAW, htons(ETH_P_802_2)); /* open socket */&lt;BR /&gt;&amp;nbsp; if(fd==-1)&lt;BR /&gt;&amp;nbsp; perror("socket failed to open\n");&lt;BR /&gt;&amp;nbsp; else &lt;BR /&gt;&amp;nbsp; printf("socket successfully created\n");&lt;BR /&gt;&amp;nbsp; memset((char *) &amp;amp;sin, 0, sizeof(sin));&lt;BR /&gt;&amp;nbsp; sin.sin_family = AF_INET;&lt;BR /&gt;&amp;nbsp; sin.sin_addr.s_addr = inet_addr("239.168.140.22");&lt;BR /&gt;&amp;nbsp; localInterface.s_addr = inet_addr("192.168.15.69");&lt;BR /&gt;&amp;nbsp; if(setsockopt(fd,SOL_SOCKET, IP_MULTICAST_IF, (char *)&amp;amp;localInterface, sizeof(localInterface)) &amp;lt; 0)&lt;BR /&gt;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp; perror("Setting local interface error\n");&lt;BR /&gt;&amp;nbsp; exit(1);&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp; else&lt;BR /&gt;&amp;nbsp; printf("Setting the local interface...OK\n");&lt;BR /&gt;&amp;nbsp; if(sendto(fd,(struct bpdu *)&amp;amp;bpdu, sizeof(struct bpdu_format), 0, (struct sockaddr *)&amp;amp;sin, sizeof(sin))&amp;lt;0)&lt;BR /&gt;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp; perror("Sending message error");&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp; else&lt;BR /&gt;&amp;nbsp; printf("Sending message...OK\n");&lt;BR /&gt;&amp;nbsp; close(fd);&lt;BR /&gt;&amp;nbsp; return 0;&lt;BR /&gt;}&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;output:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;socket successfully created....&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; Setting the local interface...OK &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sending message error: Invalid argument&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 22 Apr 2016 05:56:09 GMT</pubDate>
    <dc:creator>pradeepmp</dc:creator>
    <dc:date>2016-04-22T05:56:09Z</dc:date>
    <item>
      <title>Iam facing a problem in sendto()....telling invalid arguments.</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Iam-facing-a-problem-in-sendto-telling-invalid-arguments/m-p/470063#M15578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;CODE&gt;#include &amp;lt;netinet/in.h&amp;gt;&lt;BR /&gt;#include &amp;lt;arpa/inet.h&amp;gt;&lt;BR /&gt;#include &amp;lt;net/if.h&amp;gt;&lt;BR /&gt;#include &amp;lt;netinet/ip.h&amp;gt;&lt;BR /&gt;#include &amp;lt;netinet/udp.h&amp;gt;&lt;BR /&gt;#include &amp;lt;netinet/ether.h&amp;gt;&lt;BR /&gt;#include &amp;lt;linux/if_packet.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;BR /&gt;#include &amp;lt;string.h&amp;gt;&lt;BR /&gt;#include &amp;lt;fcntl.h&amp;gt;&lt;BR /&gt;#include &amp;lt;sys/ioctl.h&amp;gt;&lt;BR /&gt;#include &amp;lt;sys/socket.h&amp;gt; //for sockets&lt;BR /&gt;#include &amp;lt;net/if.h&amp;gt;&lt;BR /&gt;#include &amp;lt;netinet/in.h&amp;gt;&lt;BR /&gt;#include &amp;lt;arpa/inet.h&amp;gt;&lt;BR /&gt;#include &amp;lt;unistd.h&amp;gt;&lt;BR /&gt;#include &amp;lt;signal.h&amp;gt;&lt;BR /&gt;#include &amp;lt;linux/if_ether.h&amp;gt; //for ETH_P_802_2&lt;BR /&gt;#include &amp;lt;linux/if_packet.h&amp;gt; //for sockaddr_ll&lt;BR /&gt;#include &amp;lt;linux/filter.h&amp;gt; &lt;BR /&gt;#include &amp;lt;sys/types.h&amp;gt; //for sendto&lt;BR /&gt;#include "stp_bpdu.h"&lt;BR /&gt;&lt;BR /&gt;struct bpdu_format&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; int bridge_id;&lt;BR /&gt;&amp;nbsp; int port_id;&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;int main ()&lt;BR /&gt;{&amp;nbsp; &lt;BR /&gt;&amp;nbsp; struct bpdu_format bpdu;&lt;BR /&gt;&amp;nbsp; struct sockaddr_in sin;&lt;BR /&gt;&amp;nbsp; struct in_addr localInterface;&lt;BR /&gt;&amp;nbsp; int fd;&lt;BR /&gt;&amp;nbsp; bpdu.bridge_id=6969;&lt;BR /&gt;&amp;nbsp; bpdu.port_id=04;&lt;BR /&gt;&amp;nbsp; fd = socket(PF_PACKET, (int)SOCK_RAW, htons(ETH_P_802_2)); /* open socket */&lt;BR /&gt;&amp;nbsp; if(fd==-1)&lt;BR /&gt;&amp;nbsp; perror("socket failed to open\n");&lt;BR /&gt;&amp;nbsp; else &lt;BR /&gt;&amp;nbsp; printf("socket successfully created\n");&lt;BR /&gt;&amp;nbsp; memset((char *) &amp;amp;sin, 0, sizeof(sin));&lt;BR /&gt;&amp;nbsp; sin.sin_family = AF_INET;&lt;BR /&gt;&amp;nbsp; sin.sin_addr.s_addr = inet_addr("239.168.140.22");&lt;BR /&gt;&amp;nbsp; localInterface.s_addr = inet_addr("192.168.15.69");&lt;BR /&gt;&amp;nbsp; if(setsockopt(fd,SOL_SOCKET, IP_MULTICAST_IF, (char *)&amp;amp;localInterface, sizeof(localInterface)) &amp;lt; 0)&lt;BR /&gt;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp; perror("Setting local interface error\n");&lt;BR /&gt;&amp;nbsp; exit(1);&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp; else&lt;BR /&gt;&amp;nbsp; printf("Setting the local interface...OK\n");&lt;BR /&gt;&amp;nbsp; if(sendto(fd,(struct bpdu *)&amp;amp;bpdu, sizeof(struct bpdu_format), 0, (struct sockaddr *)&amp;amp;sin, sizeof(sin))&amp;lt;0)&lt;BR /&gt;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp; perror("Sending message error");&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp; else&lt;BR /&gt;&amp;nbsp; printf("Sending message...OK\n");&lt;BR /&gt;&amp;nbsp; close(fd);&lt;BR /&gt;&amp;nbsp; return 0;&lt;BR /&gt;}&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;output:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;socket successfully created....&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; Setting the local interface...OK &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sending message error: Invalid argument&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Apr 2016 05:56:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Iam-facing-a-problem-in-sendto-telling-invalid-arguments/m-p/470063#M15578</guid>
      <dc:creator>pradeepmp</dc:creator>
      <dc:date>2016-04-22T05:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Iam facing a problem in sendto()....telling invalid arguments.</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Iam-facing-a-problem-in-sendto-telling-invalid-arguments/m-p/470064#M15579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt; I think you need to check the input parameters of sendto function.&lt;/P&gt;&lt;P&gt;I guess ,&amp;nbsp; you need to check the socket type, one socket type is PF_PACKET, the other is AF_INET,&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;fd = socket(PF_PACKET, (int)SOCK_RAW, htons(ETH_P_802_2))&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;sin.sin_family = AF_INET;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Apr 2016 05:47:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Iam-facing-a-problem-in-sendto-telling-invalid-arguments/m-p/470064#M15579</guid>
      <dc:creator>danielchen</dc:creator>
      <dc:date>2016-04-25T05:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: Iam facing a problem in sendto()....telling invalid arguments.</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Iam-facing-a-problem-in-sendto-telling-invalid-arguments/m-p/470065#M15580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Pradeep,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please see the attached client and server examples. You can check here how to create and use sockets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Carlos&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Apr 2016 21:22:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Iam-facing-a-problem-in-sendto-telling-invalid-arguments/m-p/470065#M15580</guid>
      <dc:creator>Carlos_Musich</dc:creator>
      <dc:date>2016-04-26T21:22:25Z</dc:date>
    </item>
  </channel>
</rss>

