Hi, On 02/07/2012 02:01 PM, Xin Gu wrote:
On 06/02/12 19:44, Diego Biurrun wrote:@@ -866,7 +1074,7 @@ * @param signum signal the signal hipd received from OS */ -static void hip_close(int signum) +static void hipd_close(int signum) { @@ -928,8 +1136,8 @@ /* Register signal handlers */ - signal(SIGINT, hip_close); - signal(SIGTERM, hip_close); + signal(SIGINT, hipd_close); + signal(SIGTERM, hipd_close); signal(SIGCHLD, sig_chld);Push that separately.Could you explain more here? I didn't get your point.
I believe Diego meant that this should be pushed directly to trunk.
+int hip_bind(int fd, const struct sockaddr *address, socklen_t address_len) +{ + int err = 0; + struct hip_fd_info *fd_info; + struct sockaddr_storage laddr; + socklen_t laddr_len = sizeof(laddr); + uint16_t request_port; + + fd_info = hip_socket_get_info(fd); + HIP_IFEL(!fd_info, -1, "Fd %d is not a hip socket, exiting.\n", fd); + + request_port = get_port_from_saddr(address); + if ((err = bind(fd, address, address_len)) == 0) { + if (request_port == 0) { + HIP_IFEL(getsockname(fd, (struct sockaddr *)&laddr,&laddr_len), + -1, "getsockname() failed\n"); + request_port = get_port_from_saddr((struct sockaddr *)&laddr); + } + fd_info->bound_port = ntohs(request_port); + } else { + HIP_PERROR("bind error:"); + } + + HIP_DEBUG("bind to port %d\n", fd_info->bound_port); + +out_err: + return err; +}HIP_IFEL abuse, more belowAs a new developer, I am not sure what kind of usage will be defined as an abuse. Basically I use HIP_IFEL as a shortcut for code like below: if (func()) { HIP_ERROR("msg"); return -1; } In current code base I can also find similar usage. In HACKING doc there is a sample for malloc(). Probably I am wrong, could you also explain how to use this macro properly? Thanks.
unless the HIP_IFEL is used for memory deallocation, it should not be used as a direct "return" is sufficient. Sorry that I forgot mention about this.
P.S. Please remember to cc the launchpad bug id.