const addr *p_addr(peer *p) { return (&p->spec.sa); }
-/* --- @p_init@ --- *
+/* --- @p_bind@ --- *
*
* Arguments: @struct addrinfo *ailist@ = addresses to bind to
*
* Use: Initializes the peer system; creates the socket.
*/
-void p_init(struct addrinfo *ailist)
+void p_bind(struct addrinfo *ailist)
{
int fd;
int len = PKBUFSZ;
sel_initfile(&sel, &udpsock[i].sf, fd, SEL_READ, p_read, 0);
sel_addfile(&udpsock[i].sf);
T( trace(T_PEER, "peer: created %s socket", aftab[i].name); )
- if (!port) {
+ if (port)
+ udpsock[i].port = port;
+ else {
sz = sizeof(a);
if (getsockname(fd, &a.sa, &sz)) {
die(EXIT_FAILURE, "failed to read local socket address: %s",
strerror(errno));
}
- lastport = getport(&a);
+ udpsock[i].port = lastport = getport(&a);
}
}
- sym_create(&byname);
- am_create(&byaddr);
}
-/* --- @p_port@ --- *
+/* --- @p_init@ --- *
+ *
+ * Arguments: ---
*
- * Arguments: @int i@ = address family index to retrieve
+ * Returns: ---
*
- * Returns: Port number used for socket.
+ * Use: Initializes the peer system.
*/
-unsigned p_port(int i)
+void p_init(void)
{
- addr a;
- socklen_t sz = sizeof(addr);
-
- if (getsockname(udpsock[i].sf.fd, &a.sa, &sz))
- die(EXIT_FAILURE, "couldn't read port number: %s", strerror(errno));
- return (getport(&a));
+ sym_create(&byname);
+ am_create(&byaddr);
}
/* --- @p_keepalive@ --- *