Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • K kernel
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 13
    • Issues 13
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 2
    • Merge requests 2
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • erlends-os
  • kernel
  • kernel
  • Wiki
    • Abi
  • bind

Last edited by Erlend Sveen Oct 17, 2019
Page history

bind

Bind a socket to a port.

Bind is usually used by servers so that it may listen on that port and accept incoming connections. When the server replies, the packets will be sendt from the port.

Connectionless sockets may use a single socket to accept packets from any host in the network. Specify an address structure to recvfrom to get the address of the host that sendt the packet, and use the same address structure with sendto in order to reply to the same host.

Syntax

#include <sys/socket.h>

int bind (int fd, const struct sockaddr *addr, socklen_t addrlen);

Parameters

  • fd

    The file descriptor of the socket, allocated using socket.

  • addr

    Pointer to a sockaddr structure. Usually a structure specific to the socket type is used, with the sockaddr type only used for typecast reasons.

  • addrlen

    Length of the supplied address structure.

Return Value

The return value is null if successful. Otherwise, the return value is negative and errno is set:

  • EBADF

    Bad file descriptor.

  • EINVAL

    The file descriptor is not a socket.

    The addr argument is invalid.

    The length of the address structure (addrlen) is not of the expected size.

  • ENOMEM

    Out of memory.

Remarks

See the documentation for the correct socket address family (network stack) for details related to it.

Clone repository
  • abi
    • bind
    • chdir
    • close
    • closedir
    • dup2
    • exit
    • fstat
    • getcwd
    • getpgrp
    • getpid
    • gettimeofday
    • ioctl_fcntl
    • kill
    • link
    • lseek
View All Pages