Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

342
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda