Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
I am questioning how this code compiled even though struct iwreq does not have ifr_name as a member

I wrote very simple code using struct iwreq. Also, I expected this will be error. But it is compiled and works.

I looked inside linux/wireless.h which has the definition of struct iwreq. And the iwreq does not ifr_name as a member.

Would someone can give me an idea? Here is the simple code.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <linux/wireless.h>

int main(void)
{
   char *intf = "eth0";
   struct iwreq iwr;

   strncpy(iwr.ifr_name, intf, sizeof(iwr.ifr_name));

   printf("main : intf = %s, iwr.ifr_name = %s\n", intf, iwr.ifr_name);
   return 0;
}
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

wireless.h includes if.h, and inside if.h you can find:

#define ifr_name    ifr_ifrn.ifrn_name  /* interface name   */

So the code is translated to:

strncpy(iwr.ifr_ifrn.ifrn_name, intf, sizeof(iwr.ifr_ifrn.ifrn_name));
over 4 years ago · Santiago Trujillo Report

0

/usr/include/linux/wireless.h includes linux/if.h:

#include <linux/if.h>           /* for IFNAMSIZ and co... */

And in /usr/include/linux/if.h there is:

#define ifr_name    ifr_ifrn.ifrn_name  /* interface name   */
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!