2005-10-14 13:36:56

by graeme.n.brown

[permalink] [raw]
Subject: [Bluez-users] RFCOMM Socket Question


Hi

If I'm trying to program in BlueZ accepting connections on an =
rfcosocket, can I specify
a port value which will allow me to accept incoming RFCOMM connections =
on any RFCOMM
channel (a wild-card channel specification) ? If so, how do I set the=20

/* RFCOMM socket address */
struct sockaddr_rc {
sa_family_t rc_family;
bdaddr_t rc_bdaddr;
uint8_t rc_channel;
};


sockaddr_rc.rc_channel to do this before I call bind ?

E.g.

int listenfd, cliSocket ;
sockaddr_rc addr, raddr ;
socklen_t optlen;

listenfd =3D socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
if (listenfd < 0) {
printf(Can't create socket: %s (%d)\n", strerror(errno), errno);
exit(1);
}

/* Bind to local address */
addr.rc_family =3D AF_BLUETOOTH;
bacpy(&addr.rc_bdaddr, BDADDR_ANY);
addr.rc_channel =3D /* XXX <-- Can I specify a wild-card RFCPMM =
Channel here ? How ? XXXX */

if (bind(listenfd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
printf( "Can't bind socket: %s (%d)\n", strerror(errno), errno);
close(listenfd);
exit(1);
}

memset(&raddr, 0, sizeof(raddr));
optlen =3D sizeof(raddr);
cliSocket =3D accept(listenfd, (struct sockaddr *) &raddr, &optlen);
=20
if (cliSocket < 0) {
printf(buff, "Accept failed: %s (%d)\n", strerror(errno), errno);
close(listenfd) ;
exit(1);
}

/** Use new connection on cliSocket ...... **/


Thanks

Graeme Brown

=09
=20
=20


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users


2005-10-14 15:57:23

by Albert Huang

[permalink] [raw]
Subject: Re: [Bluez-users] RFCOMM Socket Question

http://people.csail.mit.edu/albert/bluez-intro/x499.html#bzi-dynamic-port-numbers

-albert

On 10/14/05, [email protected] <[email protected]> wrote:
>
>
> Hi
>
> If I'm trying to program in BlueZ accepting connections on an rfcosocket,
> can I specify
> a port value which will allow me to accept incoming RFCOMM connections on
> any RFCOMM
> channel (a wild-card channel specification) ? If so, how do I set the
>
> /* RFCOMM socket address */
> struct sockaddr_rc {
> sa_family_t rc_family;
> bdaddr_t rc_bdaddr;
> uint8_t rc_channel;
> };
>
>
> sockaddr_rc.rc_channel to do this before I call bind ?
>
> E.g.
>
> int listenfd, cliSocket ;
> sockaddr_rc addr, raddr ;
> socklen_t optlen;
>
> listenfd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
> if (listenfd < 0) {
> printf(Can't create socket: %s (%d)\n", strerror(errno), errno);
> exit(1);
> }
>
> /* Bind to local address */
> addr.rc_family = AF_BLUETOOTH;
> bacpy(&addr.rc_bdaddr, BDADDR_ANY);
> addr.rc_channel = /* XXX <-- Can I specify a wild-card RFCPMM Channel here
> ? How ? XXXX */
>
> if (bind(listenfd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
> printf( "Can't bind socket: %s (%d)\n", strerror(errno), errno);
> close(listenfd);
> exit(1);
> }
>
> memset(&raddr, 0, sizeof(raddr));
> optlen = sizeof(raddr);
> cliSocket = accept(listenfd, (struct sockaddr *) &raddr, &optlen);
>
> if (cliSocket < 0) {
> printf(buff, "Accept failed: %s (%d)\n", strerror(errno), errno);
> close(listenfd) ;
> exit(1);
> }
>
> /** Use new connection on cliSocket ...... **/
>
>
> Thanks
>
> Graeme Brown
>
>
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads, discussions,
> and more. http://solutions.newsforge.com/ibmarch.tmpl
> _______________________________________________
> Bluez-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bluez-users
>


Attachments:
(No filename) (1.95 kB)
(No filename) (4.33 kB)
Download all attachments