{
    "mode": "man",
    "parameter": "bindresvport",
    "section": "3",
    "url": "https://www.chedong.com/phpMan.php/man/bindresvport/3/json",
    "generated": "2026-07-05T13:37:01Z",
    "synopsis": "",
    "sections": {
        "NAME": {
            "content": "bindresvport, bindresvportsa — bind a socket to a privileged IP port\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "",
            "subsections": [
                {
                    "name": "#include <sys/types.h>",
                    "content": ""
                },
                {
                    "name": "#include <rpc/rpc.h>",
                    "content": "int\nbindresvport(int sd, struct sockaddrin *sin);\n\nint\nbindresvportsa(int sd, struct sockaddr *sa);\n"
                }
            ]
        },
        "DESCRIPTION": {
            "content": "The bindresvport() and bindresvportsa() functions are used to bind a socket descriptor to a\nprivileged IP port, that is, a port number in the range 0-1023.\n\nIf sin is a pointer to a struct sockaddrin then the appropriate fields in the structure should\nbe defined.  Note that sin->sinfamily must be initialized to the address family of the socket,\npassed by sd.  If sin->sinport is ‘0’ then an anonymous port (in the range 600-1023) will be\nchosen, and if bind(2) is successful, the sin->sinport will be updated to contain the allo‐\ncated port.\n\nIf sin is the NULL pointer, an anonymous port will be allocated (as above).  However, there is\nno way for bindresvport() to return the allocated port in this case.\n\nOnly root can bind to a privileged port; this call will fail for any other users.\n\nFunction prototype of bindresvport() is biased to AFINET socket.  The bindresvportsa() func‐\ntion acts exactly the same, with more neutral function prototype.  Note that both functions be‐\nhave exactly the same, and both support AFINET6 sockets as well as AFINET sockets.\n",
            "subsections": []
        },
        "RETURN VALUES": {
            "content": "The bindresvport() function returns the value 0 if successful; otherwise the value -1 is re‐\nturned and the global variable errno is set to indicate the error.\n",
            "subsections": []
        },
        "ERRORS": {
            "content": "[EPFNOSUPPORT]     If second argument was supplied, and address family did not match between\narguments.\n\nThe bindresvport() function may also fail and set errno for any of the errors specified for the\ncalls bind(2), getsockopt(2), or setsockopt(2).\n",
            "subsections": []
        },
        "AVAILABILITY": {
            "content": "The bindresvport() function is part of libtirpc.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "bind(2), getsockopt(2), setsockopt(2)\n\nBSD                            November 22, 1987                           BSD",
            "subsections": []
        }
    },
    "summary": "bindresvport, bindresvportsa — bind a socket to a privileged IP port",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "bind",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/bind/2/json"
        },
        {
            "name": "getsockopt",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/getsockopt/2/json"
        },
        {
            "name": "setsockopt",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/setsockopt/2/json"
        }
    ]
}