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 7987953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:17:47+00:00 2026-06-04T12:17:47+00:00

I have written a traceroute program written on OS X. I am trying to

  • 0

I have written a traceroute program written on OS X.
I am trying to port it to GNU/Linux.

[@osx]
>> sudo bin/traceroute www.google.com

Warning: www.google.com has multiple addresses; using 173.194.69.99
...

To make it compile on GNU/Linux, I added _GNU_SOURCE feature test macro.

[@ubuntu]
>> sudo bin/traceroute www.google.com

error setting socket options: Invalid argument

The issue is at:

 85     send_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 86     if(send_socket == -1){
 87        fprintf(stderr, "\ncannot create send socket");
 88        freeaddrinfo(dest_addrinfo_collection);
 89        return EXIT_FAILURE;
 90      }
 91     error = setsockopt(send_socket, IPPROTO_IP, IP_TTL, &ttl, sizeof(int));
 92     if(error != 0){
 93        perror("\nerror setting socket options");
 94        freeaddrinfo(dest_addrinfo_collection);
 95        return EXIT_FAILURE;
 96      }

Looks like setsockopt(...) cannot recognize IP_TTL as socket option.
However I see IP_TTL as a socket option for IPPROTO_IP level.

I am using SOCK_DGRAM as my sending socket to avoid preparing my own ICMP packet.

  • 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-06-04T12:17:48+00:00Added an answer on June 4, 2026 at 12:17 pm

    My mistake, my ttlvariable was an unsigned short.

    -    error = setsockopt(send_socket, IPPROTO_IP, IP_TTL, &ttl, sizeof(int));
    +    error = setsockopt(send_socket, IPPROTO_IP, IP_TTL, &ttl, sizeof(unsigned short));
    

    UPDATE

    In addition I had to option_len was different for different platforms.

    -    error = setsockopt(send_socket, IPPROTO_IP, IP_TTL, &ttl, sizeof(unsigned short));
    +#if defined(__APPLE__)
    +    error = setsockopt(send_socket, IPPROTO_IP, IP_TTL, &ttl, sizeof(&ttl));
    +#elif defined(__linux)
    +    error = setsockopt(send_socket, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
    +#endif
    

    UPDATE

    -  unsigned short          ttl = 1;
    +  socklen_t               ttl = 1;
    
    -#if defined(__APPLE__)
    -    error = setsockopt(send_socket, IPPROTO_IP, IP_TTL, &ttl, sizeof(&ttl));
    -#elif defined(__linux)
         error = setsockopt(send_socket, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
    -#endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written below code in htaccess RewriteRule ^([a-zA-Z_-]+).php$ http://www.domain.com/myfile.php?page=inc- $1.php [NC] I don't
I have written a program in VB6. When I compile it and send it
I have written a program that uses qhttp to get a webpage. This works
I have written a Java program which I package and run from a JAR
I have written a short python script that opens Google music in web view
i have written a program and it works with 3D coordinates (i.e. x,y,z). input
I have written a dangerous program in C++ that jumps back and forth from
I have written a script in haskell named testscript with the following code: #!/usr/bin/env
I have written a small program which uses function pointers to do some numerical
I have written a C program to get all the possible combinations of a

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.