process descriptor table

Dag-Erling Smørgrav des at des.no
Wed May 24 02:31:02 PDT 2006


"Artem Kazakov" <kazakov at gmail.com> writes:
> The problem is that at some point a socket() function is called. And
> it returns descriptor = 1, which is a standart ouput.

socket() will not return 1 unless you previously closed descriptor 1,
either directly with close(1) or indirectly with fclose(stdout).

You probably did something like this:

    if (sd = socket(AF_INET, SOCK_STREAM, 0) != -1) {
        /* foo */
    }

which assigns either 1 or 0 to sd depending on whether socket()
returned -1.  You need to parenthesize the assignment:

    if ((sd = socket(AF_INET, SOCK_STREAM, 0)) != -1) {
        /* foo */
    }

You also need to check the return value from either bind() or
connect() (they should have failed and set errno to ENOTSOCK), and
enable compiler warnings (gcc should have warned you about the dodgy
assignment / comparison).

DES
-- 
Dag-Erling Smørgrav - des at des.no


More information about the freebsd-hackers mailing list