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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:43:41+00:00 2026-06-08T03:43:41+00:00

I’m trying to create a program that will be able create and send tcp

  • 0

I’m trying to create a program that will be able create and send tcp packages, but keep getting these errors when compiling.

error: expected identifier or ‘(’ before ‘,’ token

and

error: ‘sin’ undeclared (first use in this function)
error: ‘din’ undeclared (first use in this function)

Now I’m sure these are the result of something really obvious, but I’ve stared myself blind on this piece of code and can’t get my head around it. The function is as follows:

int send_tcp()
        {
            int sock, one = 1;
            char buffer[PCKT_LEN];
            struct sockaddr_in, sin, din;
            const int *val = &one;

            sock = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
            if (sock < 0)
                {
                    printf("\nError: socket()\n\n");
                    exit (-1);
                }
            else
                    printf ("\nsocket() - Using SOCK_RAW and TCP protocol is OK.\n\n");

            /* Size of the headers */           
            struct ipheader *ip = (struct ipheader *) buffer;
            struct tcpheader *tcp = (struct tcpheader *) (buffer + sizeof (struct ipheader));
            memset (buffer, 0, PCKT_LEN);

            /* IP attributes */
            ip->iph_ihl = 5;
            ip->iph_ver = 4;
            ip->iph_tos = 16;
            ip->iph_len = sizeof(struct ipheader) + sizeof(struct tcpheader);
            ip->iph_id = htons(54321);
            ip->iph_offset = 0;
            ip->iph_ttl = 64;
            ip->iph_protocol = 6;
            ip->iph_chksum = 0; 

            ip->iph_sourceip = sip;
            ip->iph_destip = dip;

            /* TCP attributes */
            tcp->tcph_sourceport = sport;
            tcp->tcph_destport = dport;

            tcp->tcph_seqnum = htonl(1);
            tcp->tcph_acknum = 0;
            tcp->tcph_offset = 5;
            tcp->tcph_syn = 1;
            tcp->tcph_ack = 0;
            tcp->tcph_win = htons(32767);
            tcp->tcph_chksum = 0; 
            tcp->tcph_urgptr = 0;

            ip->iph_chksum = checksum ((unsigned short *) buffer, (sizeof (struct ipheader )+ sizeof (struct tcpheader)));

            /* Address family */ 
            sin.sin_family = AF_INET;
            din.sin_family = AF_INET;

            /* Source port */
            sin.sin_port = sport;
            din.sin_port = dport;

            /* Source IP */
            sin.sin_addr.s_addr = sip;
            din.sin_addr.s_addr = dip;      

            /* Tell the Kernel we're building our own packet */
            if ((setsockopt(sock, IPPROTO_IP, IP_HDRINCL, (char *)&one, sizeof (one))) < 0)
                {
                    printf("\nError: Can't set socketoptions\n\n");
                    return (-1);
                }

            /* Send */
            if (sendto(sock, buffer, ip->iph_len, 0, (struct sockaddr *)&sin, sizeof(sin)) < 0)
                {
                    printf("\nError: Can't send packet\n\n");
                    return (-1);
                }

            else
                    printf("Packet sent to %s", dip); 

            close(sock);
        }           

I was under the impression that:

struct sockaddr_in, sin, din;

would be sufficient, but it’s obiously not. This is also the line the expected identifier error message points to. What am I missing?

  • 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-08T03:43:42+00:00Added an answer on June 8, 2026 at 3:43 am

    Remove the first comma

     struct sockaddr_in, sin, din;
                       ^
                       ^
    

    sockaddr_in is the name of a struct so I am assuming with the above line you are trying to declare two variables of type sockadddr_in called sin and din. If so you need to remove that comma as a variable name is expected afterstruct sockaddr_in. What you have done is the same as trying the following:

     int, a,b;
    

    which would also not compile as immediately after the typename int the compiler expects a variable name.

    Remove that comma and you should no longer get your compilation error.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.