Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5969569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:14:58+00:00 2026-05-22T20:14:58+00:00

I have a code which receives packets from the Ethernet and sends it via

  • 0

I have a code which receives packets from the Ethernet and sends it via wireless network. This works on a wireless box which uses OpenWrt. The code is written below. It gives me the following error at runtime. Based on the printf statements I feel the error is somewhere on this syntax, but I cant figure out whats wrong.

Probable region of error:

  if(sendto(b_sock, buf, sizeof(v2vmessage), 0, (struct sockaddr *)&tx_addr, sizeof(tx_addr)) < 0)

Error:

Receving packets
Packets received
Sending packet started
Variables initialized
Send test
./dsrc_dsrc: can't resolve symbol 'sendto' in lib './dsrc_dsrc'.

Code:

#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <netdb.h>
#include <stdio.h>

#include <fcntl.h>
#include <string.h>
#include <sys/time.h>
#include <arpa/inet.h>  /* for sockaddr_in */

#define BROADCAST_IP "192.168.255.255"
#define BROADCAST_PORT 4545

struct v2vmessage
{
  ...
  ...
};

int b_sock=-1;

void init_socket()
{
  unsigned short b_port = BROADCAST_PORT;
  struct sockaddr_in b_addr;
  int broadcastPermission;
  char* rx_ip = BROADCAST_IP;

  if ((b_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
    perror("socket() failed");

  /* Set socket to allow broadcast */
  broadcastPermission = 1;
  if (setsockopt(b_sock, SOL_SOCKET, SO_BROADCAST, (void *) &broadcastPermission, sizeof(broadcastPermission)) < 0)
    perror("setsockopt() failed");

  int opts;
  opts = fcntl(b_sock,F_GETFL);
  if(opts < 0)
    perror("fcntl get failed");

  opts = (opts | O_NONBLOCK);
  if(fcntl(b_sock,F_SETFL,opts) < 0)
    perror("fcntl set failed");

  memset(&b_addr, 0, sizeof(b_addr));   /* Zero out structure */
  b_addr.sin_family = AF_INET;                 /* Internet address family */
  b_addr.sin_addr.s_addr = inet_addr(rx_ip);/* Broadcast IP address */
  b_addr.sin_port = htons(b_port);         /* Broadcast port */

  if (bind(b_sock, (struct sockaddr *) &b_addr, sizeof(b_addr)) < 0)
    perror("rx bind() failed");
}


void send_thread_body(v2vmessage *buf)
{
  printf("Sending packet started\n");
  char *tx_ip = BROADCAST_IP;
  unsigned short tx_port = BROADCAST_PORT;
  struct sockaddr_in tx_addr;

  printf("Variables initialized\n");

  memset(&tx_addr, 0, sizeof(tx_addr));   /* Zero out structure */
  tx_addr.sin_family = AF_INET;                 /* Internet address family */
  tx_addr.sin_addr.s_addr = inet_addr(tx_ip);/* Broadcast IP address */
  tx_addr.sin_port = htons(tx_port);         /* Broadcast port */

  printf("Send test\n");

  if(sendto(b_sock, buf, sizeof(v2vmessage), 0, (struct sockaddr *)&tx_addr, sizeof(tx_addr)) < 0)
    perror("tx sent diff num bytes than expected");
}

int main(int argc, char *argv[])
{
  init_socket();
  {
    int sock, length, n,p;
    socklen_t fromlen;
    struct sockaddr_in server;
    struct sockaddr_in from;

    if (argc < 2)
    {
      fprintf(stderr, "ERROR, no port provided\n");
      exit(0);
    }

    sock=socket(AF_INET, SOCK_DGRAM, 0);
    if (sock < 0)
      perror("Opening socket");
    length = sizeof(server);
    bzero(&server,length);
    server.sin_family=AF_INET;
    server.sin_addr.s_addr=INADDR_ANY;
    server.sin_port=htons(atoi(argv[1]));
    if (bind(sock,(struct sockaddr *)&server,length)<0) 
      perror("binding");
    fromlen = sizeof(struct sockaddr_in);
    v2vmessage *buf;

    while (1)
    {
      printf("Receving packets\n");
      n = recvfrom(sock,buf,sizeof(v2vmessage),0,(struct sockaddr *)&from,&fromlen);
      if (n < 0)
        perror("recvfrom");
      printf("Packets received\n");
      send_thread_body(buf);
      printf("Packets sent\n");
    }
  }
  return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:14:58+00:00Added an answer on May 22, 2026 at 8:14 pm

    In the main(), replace v2vmessage* buf by v2vmessage buf and in the following while(1), replace the buf by &buf to solve the problem. Since, no memory was allocated to the pointer, hence it gave an error at runtime.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C\C++ code that receives a structure over the network, from this
I have a code which transmits messages (broadcasts) continuously on wireless network and also
I have added some code which compiles cleanly and have just received this Windows
I have some code which collects points (consed integers) from a loop which looks
I have some code which I am making available via RMI. If my program
I have some code which I did not originally create that uses _beginthreadex and
I have some code, which was written couple of years ago and works only
I have a Linux C++ application which receives sequenced UDP packets. Because of the
I have a program which transmits(broadcasts) and receives UDP packets simultaneously using pthreads. What
I have have some code which adds new cells to a table and fills

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.