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

  • Home
  • SEARCH
  • 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 110509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:14:17+00:00 2026-05-11T02:14:17+00:00

Ok, so I’m trying to get some UDP code working and I’m barely green

  • 0

Ok, so I’m trying to get some UDP code working and I’m barely green when it comes to network programming using C. I’m using the sample file from here

Basically I’m just listening for incoming UDP packets on a given port and then I want to send some data back the same way. Below is the relevant part.

At this point the socket is set up and bound to a port of choice and awaits incoming packets:

printf('GSProxy: waiting to recvfrom...\n');  addr_len = (socklen_t) sizeof their_addr; if ((numbytes = recvfrom(sockfd, buf, MAXBUFLEN-1 , 0,     (struct sockaddr *)&their_addr, &addr_len)) == -1) { // argument 6 gives a warning but is correct int     perror('recvfrom');     exit(1); }  printf('GSProxy: got packet from %s\n',  inet_ntop(their_addr.ss_family,      get_in_addr((struct sockaddr *)&their_addr), s, sizeof s)); printf('GSProxy: packet is %d bytes long\n', numbytes); buf[numbytes] = '\0'; printf('GSProxy: packet contains \'%s\'\n', buf);  char retmsg[] = 'Hello!'; if ((numbytes = sendto(sockfd, retmsg, 7, 0,      (struct sockaddr *) &their_addr, &addr_len)) == -1) {     perror('GSPProxy: sendto');     exit(1); }  printf('GSProxy: Sent %i bytes.\n', numbytes); 

I just want to send the ‘Hello!’ string right back to the sender.

This fails with Error ‘GSPProxy: sendto: File name too long‘. Which is the [ENAMETOOLONG] error code, as far is I can tell.

But… what the ** does it mean? What file? What is too long?

Is it that I can’t reuse the socket to send data back, or have I just made another newb mistake?

Best regards,

  • 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. 2026-05-11T02:14:18+00:00Added an answer on May 11, 2026 at 2:14 am

    You should not be passing the address of the socket structure length to sendto() – it requires the actual length (i.e., 'addr_len', not '&addr_len').

    The reason you pass the address of the length to recvfrom() is that it is changed by that function if the real address happens to be shorter.

    In other words, replace:

    if ((numbytes = sendto (sockfd, retmsg, 7, 0,     (struct sockaddr *) &their_addr, &addr_len)) == -1) { 

    with:

    if ((numbytes = sendto (sockfd, retmsg, 7, 0,     (struct sockaddr *) &their_addr, addr_len)) == -1) { 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 138k
  • Answers 138k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Now that you've posted GDB output, it's clear exactly what… May 12, 2026 at 7:33 am
  • Editorial Team
    Editorial Team added an answer In other words, if I have a number that I… May 12, 2026 at 7:33 am
  • Editorial Team
    Editorial Team added an answer Trailing space is specified to be handled in a special… May 12, 2026 at 7:33 am

Related Questions

Ok, so I demo'd Refactor Pro and Resharper, I'm more comfortable with Resharper so
Ok, so I just ran into the following problem that raised an eyebrow. For
Ok, so I have an nHibernate ICriteria that returns an object. I want to
Ok, so I'm building bread crumbs and depending on the value of the breadcrumb
OK, so I couldn't really think of an apropos title that summarizes this. The

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.