libcommon: socket: extend make_sock() prototype
This patch extends the make_sock() prototype so you can fully set
the fields priv_nr and data of the bsc_fd structure.
This is the first step to get rid of the internal make_sock()
implementation that ipaccess-proxy uses.
This patch includes a minor cleanup to pass INADDR_ANY instead
of zero, if you do not want to bind the socket to one specific
address.
diff --git a/openbsc/src/libcommon/socket.c b/openbsc/src/libcommon/socket.c
index 42d7b48..5ca7ec9 100644
--- a/openbsc/src/libcommon/socket.c
+++ b/openbsc/src/libcommon/socket.c
@@ -40,8 +40,9 @@
#include <openbsc/gsm_data.h>
#include <osmocom/core/talloc.h>
-int make_sock(struct bsc_fd *bfd, int proto, u_int32_t ip, u_int16_t port,
- int (*cb)(struct bsc_fd *fd, unsigned int what))
+int make_sock(struct bsc_fd *bfd, int proto,
+ u_int32_t ip, u_int16_t port, int priv_nr,
+ int (*cb)(struct bsc_fd *fd, unsigned int what), void *data)
{
struct sockaddr_in addr;
int ret, on = 1;
@@ -64,7 +65,8 @@
bfd->fd = socket(AF_INET, type, proto);
bfd->cb = cb;
bfd->when = BSC_FD_READ;
- //bfd->data = line;
+ bfd->data = data;
+ bfd->priv_nr = priv_nr;
if (bfd->fd < 0) {
LOGP(DINP, LOGL_ERROR, "could not create socket.\n");
@@ -74,7 +76,7 @@
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
- if (ip)
+ if (ip != INADDR_ANY)
addr.sin_addr.s_addr = htonl(ip);
else
addr.sin_addr.s_addr = INADDR_ANY;