Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda