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

340
Visualizações
how can perror and errno show different results (Linux)?

I am calling bind() on a socket, and the call is failing owing to "Address in use". I am fairly confident that's the failure, anyway - the socket has been left open by a previous instance of the app that crashed. Specifically, bind() returns a negative value. However, errno reads zero on the function's return. Bizarrely, perror(), however, generates "Address in use".

Under what conditions can errno and perror() disagree on the value of the error code? I understand that the errno system is thread-safe (there are other threads running in the meantime). I am on Linux 3.14.43.

if (bind(s, (struct sockaddr *)&server, sizeof(server)) < 0)
{
    printf("\nerrno %i %s\n", errno, strerror(errno));
    perror("PERROR");

    //  raise error
    __ERROR("failed bind socket");
}

The above code generates this output:

errno 0 Success
PERROR: Address already in use
**** ERROR **** failed bind socket

Perhaps I have misunderstood the relationship between errno, strerror(), and perror()?

over 4 years ago · Santiago Trujillo
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