diff options
| author | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2008-10-06 10:23:48 -0300 | 
|---|---|---|
| committer | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2008-10-06 10:23:48 -0300 | 
| commit | 799e7de01e99fbd4ba62d567a78057d170c0b6c1 (patch) | |
| tree | e908e0aa8d3d629936cfea541fad717749308139 | |
| parent | e67f2377509cf88a1d5e3d339afe93ace97e85d5 (diff) | |
Fix *_bind helpers to call bind() before setsockopt().
| -rw-r--r-- | common/glib-helper.c | 41 | 
1 files changed, 21 insertions, 20 deletions
| diff --git a/common/glib-helper.c b/common/glib-helper.c index 330bbf72..c05ac5c5 100644 --- a/common/glib-helper.c +++ b/common/glib-helper.c @@ -808,6 +808,17 @@ static int l2cap_bind(struct io_context *io_ctxt, const char *address,  	if (io_ctxt->fd < 0)  		return -errno; +	memset(addr, 0, sizeof(*addr)); +	addr->l2_family = AF_BLUETOOTH; +	str2ba(address, &addr->l2_bdaddr); +	addr->l2_psm = htobs(psm); + +	err = bind(io_ctxt->fd, (struct sockaddr *) addr, sizeof(*addr)); +	if (err < 0) { +		close(io_ctxt->fd); +		return -errno; +	} +  	if (mtu) {  		socklen_t olen = sizeof(l2o);  		memset(&l2o, 0, olen); @@ -826,17 +837,6 @@ static int l2cap_bind(struct io_context *io_ctxt, const char *address,  		}  	} -	memset(addr, 0, sizeof(*addr)); -	addr->l2_family = AF_BLUETOOTH; -	str2ba(address, &addr->l2_bdaddr); -	addr->l2_psm = htobs(psm); - -	err = bind(io_ctxt->fd, (struct sockaddr *) addr, sizeof(*addr)); -	if (err < 0) { -		close(io_ctxt->fd); -		return -errno; -	} -  	return 0;  } @@ -898,15 +898,6 @@ static BtIOError rfcomm_bind(struct io_context *io_ctxt, const char *address,  	if (io_ctxt->fd < 0)  		return BT_IO_FAILED; -	if (flags) { -		int opt = flags; -		err = setsockopt(io_ctxt->fd, SOL_RFCOMM, RFCOMM_LM, &opt, -				sizeof(opt)); -		if (err < 0) { -			close(io_ctxt->fd); -			return BT_IO_FAILED; -		} -	}  	memset(addr, 0, sizeof(*addr));  	addr->rc_family = AF_BLUETOOTH; @@ -919,6 +910,16 @@ static BtIOError rfcomm_bind(struct io_context *io_ctxt, const char *address,  		return BT_IO_FAILED;  	} +	if (flags) { +		int opt = flags; +		err = setsockopt(io_ctxt->fd, SOL_RFCOMM, RFCOMM_LM, &opt, +				sizeof(opt)); +		if (err < 0) { +			close(io_ctxt->fd); +			return BT_IO_FAILED; +		} +	} +  	return BT_IO_SUCCESS;  } | 
