本篇翻译的bind()函数,我参考的国外网站是:

bind

朋友们可以自由转载我对英文的中文翻译,但是对于“作者注:”的描述,转载时请注明出处和作者,否则视为侵权。

下面是翻译的正文,由于水平有限,有些翻译的不好,有些未能翻译出,恳请读者指出与见谅。

NAME

bind - bind a name to a socket

bind一个名字到一个套接字上。

SYNOPSIS

#include <sys/socket.h>

int bind(int socket, const struct sockaddr*address,

socklen_t address_len);

DESCRIPTION

The bind() function assigns an address toan unnamed socket. Sockets created with socket() function are initiallyunnamed; they are identified only by their address family.

bind()函数将一个地址分配给一个未命名的套接字。使用socket()函数创建的那些套接字初始化是没有命名的,它们只有通过地址族才能被识别。

The function takes the following arguments:

函数的参数如下:

socket

Specifies the file descriptor of the socketto be bound.

socket参数:指定了需要绑定的套接字的文件描述符。

作者注:

socket参数是一个文件描述符,是socket()函数的返回值。

address

Points to a sockaddr structure containingthe address to be bound to the socket. The length and format of the addressdepend on the address family of the socket.

Address参数:指向一个sockaddr结构体,这个结构体中包含着要绑定到套接字的地址。地址的长度和格式依赖于套接字支持的地址族。

作者注:

1.套接字作为系统的一个文件,进程要通过这个文件来通信,因此就要使用这个文件。要使用这个文件,得先要绑定这个文件,才能用这个文件。

2.struct sockaddr结构体如下,摘自

include/linux/socket.h

struct sockaddr

{

unsignedshort sa_family; /* address family, AF_xxx */

char sa_data[14]; /* 14 bytes of protocol address */

};

3. 给sa_data赋值时,需要注意网络字节序的问题。

关于网络字节序的介绍,可以看百度百科上的介绍:

网络字节序_百度百科

address_len

Specifies the length of the sockaddrstructure pointed to by the address argument.

address_len参数:指定了sockaddr结构体的长度。参数address指向了这个sockaddr结构体。

The socket in use may require the processto have appropriate privileges to use the bind() function.

被使用的套接字也许会要求进程有合适的权限来使用bind()函数。

RETURNVALUE

Upon successful completion, bind() returns0. Otherwise, -1 is returned and errno is set to indicate the error.

一旦bind()函数成功执行,函数会返回0.否则的话就返回-1,而且errno也被设置用来解释是什么错误。

ERRORS

The bind() function will fail if:

bind()函数会因为下列原因而失败:

[EADDRINUSE]

The specified address is already in use.

指定的address参数已经被使用了。

[EADDRNOTAVAIL]

The specified address is not available fromthe local machine.

指定的地址在本地机器上不能使用。

[EAFNOSUPPORT]

The specified address is not a validaddress for the address family of the specified socket.

指定的地址对于指定的套接字的地址族来说,是一个无效的地址。

[EBADF]

The socket argument is not a valid filedescriptor.

socket参数本身就不是一个有效的文件描述符。

[EFAULT}

The address argument can not be accessed.

无法访问address参数。

[EINVAL]

The socket is already bound to an address,and the protocol does not support binding to a new address; or the socket hasbeen shut down.

参数socket已经跟另外的地址绑定了,而且协议不支持再绑定一个新的地址。或者参数socket已经被关闭了。

[ENOTSOCK]

The socket argument does not refer to asocket.

socket参数没有引用到一个套接字。

作者注:

意思是说,bind()函数的socket参数虽然有一个值,也就是一个文件描述符,但是此描述符对应的socket文件没有了。

[EOPNOTSUPP]

The socket type of the specified socketdoes not support binding to an address.

参数socket的类型不支持绑定到一个地址。

作者注:

bind()函数一定会失败的原因,无外乎就是地址不对了,地址错了,地址不能用了,socket文件描述符不能用了。

If the address family of the socket isAF_UNIX, then bind() will fail if:

如果套接字的地址族是AF_UNIX,那么bind()函数会由于以下原因失败:

[EACCES]

A component of the path prefix deniessearch permission, or the requested name requires writing in a directory with amode that denies write permission.

路径的前缀部分拒绝了搜索权限,或者被要求的名字要求以决绝写的模式写进一个目录。

作者注:这里不太好翻译。

[EDESTADDRREQ] or [EISDIR]

The address argument is a null pointer.

address参数是一个空指针。

[EIO]

An I/O error occurred.

一个I/O错误发生了。

[ELOOP]

Too many symbolic links were encountered intranslating the pathname in address.

作者觉得不太好翻译,大概意思是说在翻译address中的路径名时,遇到了太多的象征性的链接。

[ENAMETOOLONG]

A component of a pathname exceeded{NAME_MAX} characters, or an entire pathname exceeded {PATH_MAX} characters.

一个路径名的一部分超过了{NAME_MAX}允许的最大长度,或者一个完整的超过了{PATH_MAX}允许的最大长度。

[ENOENT]

A component of the pathname does not namean existing file or the pathname is an empty string.

路径名的部分没有命名一个已存在的文件,或者路径名是一个空的字符串。

[ENOTDIR]

A component of the path prefix of thepathname in address is not a directory.

地址中的路径名的路径前缀部分不是一个目录。

[EROFS]

The name would reside on a read-onlyfilesystem.

名字也许驻留在一个只读的文件系统中。

The bind() function may fail if:

bind()函数也许会由于以下原因失败:

[EACCES]

The specified address is protected and thecurrent user does not have permission to bind to it.

指定的地址被保护了,当前用户没有权限来绑定。

[EINVAL]

The address_len argument is not a validlength for the address family.

address_len参数的长度对地址族来说,不是一个有效长度。

[EISCONN]

The socket is already connected.

套接字已经连接了。

[ENAMETOOLONG]

Pathname resolution of a symbolic linkproduced an intermediate result whose length exceeds {PATH_MAX}.

链接的路径名解析产生了一个中间结果,这个结果的长度超过了{PATH_MAX}最大值。

[ENOBUFS]

Insufficient resources were available tocomplete the call.

没有足够的资源可用来完成调用。

[ENOSR]

There were insufficient STREAMS resourcesfor the operation to complete.

没有足够的STREAMS资源来让操作完成。

APPLICATIONUSAGE

An application program can retrieve theassigned socket name with the getsockname() function.

一个应用程序可以通过getsockname()函数来获取绑定的套接字名。

Socket编程(C语言实现):bind()函数英文翻译的更多相关文章

  1. Linux下Socket编程的端口问题( Bind error: Address already in use )

    Linux下Socket编程的端口问题( Bind error: Address already in use ) 在进行linux网络编程时,每次修改了源代码并再次编译运行时,常遇到下面的地使用错误 ...

  2. Socket编程(C语言实现):socket()函数英文翻译

    最近开始研究使用Socket API来网络编程,想着把自己的感想.感悟写下来.我发现在编程之外还有不少概念性的东西要学习.我觉得应该有以下几点吧: 1.得了解下计算机网络的基本概念,如OSI的7层模型 ...

  3. iOS Socket编程-C语言版(UDP)

    . UDP Socket编程 先讲一讲UDP编程,因为比TCP要简单多了.首先,我们需要明白UDP是用户数据报协议,英文名为User Datagram Protocol,它是面向无连接的. 注意:So ...

  4. iOS Socket编程-C语言版(TCP)

    . TCP Socket编程 TCP是面向连接的,安全可靠的传输层协议.TCP的程序基本框架设计图: TCP的程序基本框架设计图.jpg 注意:Socket通信一定有要服务端和客户端. 1.1 TCP ...

  5. socket编程:recvmsg 和 sendmsg 函数

    背景 复习 socket 编程的时候发现了以前没有留意到的 2个函数:recvmsg 和 sendmsg ref : Linux编程之recvmsg和sendmsg函数 知识 先来看看函数原型: #i ...

  6. Go 语言官方包函数中文翻译

    Go官方包函数中文翻译 *** import "strings" func Join(a []string, sep string) string Join concatenate ...

  7. Socket编程:listen()函数英文翻译

    作者:C语言达人 链接:https://zhuanlan.zhihu.com/p/24951131 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 本篇翻译的list ...

  8. socket编程时使用了inet_ntoa函数,存储到链表中的数据总是自动改变

    这和inet_ntoa的返回值有关系: 函数声明:char *inet_ntoa (struct in_addr); 返回点分十进制的字符串在静态内存中的指针. 所在头文件:<arpa/inet ...

  9. Linux C Socket 编程

    1 Socket 是什么 Socket(套接字),就是对 网络上进程通信 的 端点 的 抽象.一个 Socket 就是网络上进程通信的一端,提供了应用层进程利用网络协议交换数据的机制. 从所处的位置来 ...

随机推荐

  1. Win8 Metro(C#)数字图像处理--2.64图像高斯滤波算法

    原文:Win8 Metro(C#)数字图像处理--2.64图像高斯滤波算法  [函数名称]   高斯平滑滤波器      GaussFilter(WriteableBitmap src,int r ...

  2. 华为虚拟机结合VMware搭建环境测试snmp

    最近在研究zabbix监控,在实际生产环节中,我们不单单是需要对linux主机进行监控还需要对网络设备防火墙等等进行监控,那么在linux主机上我们可以安装zabbix-agernt,但是在路由器交换 ...

  3. UBUNTU 16.04 + CUDA8.0 + CUDNN6.0 + OPENCV3.2 + MKL +CAFFE + tensorflow

    首先说一下自己机子的配置 CPU:Intel(R) Core(TM) i5-5600 CUP @3.20GHz *4 GPU : GTX 1060 OS : 64bit Ubuntu16.04LTS ...

  4. Java程序员的现代RPC指南(Windows版预编译好的Protoc支持C++,Java,Python三种最常用的语言,Thrift则支持几乎主流的各种语言)

    Java程序员的现代RPC指南 1.前言 1.1 RPC框架简介 最早接触RPC还是初学Java时,直接用Socket API传东西好麻烦.于是发现了JDK直接支持的RMI,然后就用得不亦乐乎,各种大 ...

  5. 《Windows via C/C++》学习笔记 —— 设备I/O之“同步的设备I/O”(系列文章)

    前面曾经讲过,设备I/O的方式有两种:同步和异步.本篇介绍一下同步设备I/O.主要涉及到两个函数:ReadFile和WriteFile. 不要被这两个函数的名称迷惑,不仅可以将这两个作用于文件,也可以 ...

  6. 如何从一张图片中裁剪一部分距形图片另存为文件(使用Canvas.CopyRect)

    如何从一张图片中裁剪一部分距形图片另存为文件? Delphi / Windows SDK/APIhttp://www.delphi2007.net/DelphiMultimedia/html/delp ...

  7. python字典的内建函数

    In [70]: test=dict(x=1,y=2,z=3) In [71]: test Out[71]: {'x': 1, 'y': 2, 'z': 3} In [72]: a=['a','b', ...

  8. HTML连载15-文本属性&颜色控制属性

    一.文本装饰的属性 1.格式:text-decoration:underline; 2.取值: (1)underline代表下划线 (2)line-through代表删除线 (3)overline代表 ...

  9. Python连载12-shutil模块

    一.shutil模块 1.函数:copy() (1)用法:复制文件0 (2)格式:copy(来源路径,目标路径) (3)返回值:返回目标路径 (4)注意:拷贝的同时可以给文件重命名 source_pa ...

  10. HTML连载8-video标签

    ​一.video标签 1.作用:播放视频 2.格式:<video src="视频地址“></video> 3.可添加的属性: (1)autoplay="au ...