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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:37:18+00:00 2026-05-18T00:37:18+00:00

I am going through a piece of code for packet injector. When I tried

  • 0

I am going through a piece of code for packet injector. When I tried to compile it, It is showing the error :

IP-Packet-Injection.c:155: error: lvalue required as left operand of assignment
IP-Packet-Injection.c:156: error: lvalue required as left operand of assignment

Code for that particular part is :

unsigned char *CreateIPHeader(/* Customize this as an exercise */)
{
        struct iphdr *ip_header;

        ip_header = (struct iphdr *)malloc(sizeof(struct iphdr));

        ip_header->version = 4;
        ip_header->ihl = (sizeof(struct iphdr))/4 ;
        ip_header->tos = 0;
        ip_header->tot_len = htons(sizeof(struct iphdr));
        ip_header->id = htons(111);
        ip_header->frag_off = 0;
        ip_header->ttl = 111;
        ip_header->protocol = IPPROTO_TCP;
        ip_header->check = 0; /* We will calculate the checksum later */
      /*this is line 155 */ (in_addr_t)ip_header->saddr = inet_addr(SRC_IP);
      /*this is line 156 */ (in_addr_t)ip_header->daddr = inet_addr(DST_IP);


        /* Calculate the IP checksum now : 
           The IP Checksum is only over the IP header */

        ip_header->check = ComputeIpChecksum((unsigned char *)ip_header, ip_header->ihl*4);

        return ((unsigned char *)ip_header);

}

I have shown line 155 and 156 in the code. I can’t see any problem there. Can anybody tell me what the error can be? Thanks in advance.
Operating system : Ubuntu, compiler : GCC.

  • 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-18T00:37:19+00:00Added an answer on May 18, 2026 at 12:37 am

    The result of a cast is an rvalue, so you can’t assign to it. For a situation like this, you typically have to do something like:

    *(in_addr_t *)(&(ip_header->saddr)) = in_addr(SRC_IP);
    

    I.e., take the address, cast that to a pointer to the correct type, and dereference that pointer. Just make sure the defined type of the saddr and daddr members is something that can actually hold the address. It normally should be, but it won’t hurt to double check.

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

Sidebar

Related Questions

I was going through some code and came across a scenario where my combobox
While Going through the java tutorial on sun site, I see following piece of
I'm going through some old C#.NET code in an ASP.NET application making sure that
I was going through the source of google guice, and found an unfamiliar piece
I am studying the new Async CTP and going through some sample code, I
While going through university and from following the development of SO, I've heard a
After going through the Appendix A, C# Coding Style Conventions of the great book
I'm going through the problems on projecteuler.net to learn how to program in Erlang,
We're going through a massive migration project at the minute and trying to validate
I was going through the AWDR book on web development with ruby on rails

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.