Answers
socket bind
示例:
struct sockaddr_in addr;
int n = 1;
if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
DEBUG(LOG_ERR, "socket call failed: %s ", sys_errlist[errno]);
return -1;
}
memset(&addr;, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = ip;
if (bind(fd, (struct sockaddr *)&addr;, sizeof(struct sockaddr)) == -1) {
close(fd);
return -1;
}
NEET蕾米
answered 12 years, 5 months ago