当前位置: 技术问答>linux和unix
linux bind()问题
来源: 互联网 发布时间:2016-07-14
本文导语: 在linux下我用bind()函数总是出错,提示:地址已在使用,每次都这样,加了setsockopt也不好使,为什么阿。下面是我的代码 int sin_len; int socket_info; long save_file_flags; int bind_rc; int recv_rc; int flag = 1; int flag_len =...
在linux下我用bind()函数总是出错,提示:地址已在使用,每次都这样,加了setsockopt也不好使,为什么阿。下面是我的代码
int sin_len;
int socket_info;
long save_file_flags;
int bind_rc;
int recv_rc;
int flag = 1;
int flag_len = sizeof(int);
struct sockaddr_in sin;
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(12345);
sin_len = sizeof(struct sockaddr_in);
socket_info = socket(AF_INET, SOCK_DGRAM,0);
if(socket_info == -1){
perror("socket call failed");
}
if(setsockopt(socket_info, SOL_SOCKET, SO_REUSEADDR, (const char *)&flag, flag_len)
int sin_len;
int socket_info;
long save_file_flags;
int bind_rc;
int recv_rc;
int flag = 1;
int flag_len = sizeof(int);
struct sockaddr_in sin;
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(12345);
sin_len = sizeof(struct sockaddr_in);
socket_info = socket(AF_INET, SOCK_DGRAM,0);
if(socket_info == -1){
perror("socket call failed");
}
if(setsockopt(socket_info, SOL_SOCKET, SO_REUSEADDR, (const char *)&flag, flag_len)