Return-Path: Message-ID: From: Albert Huang To: bluez-users@lists.sourceforge.net Subject: Re: [Bluez-users] RFCOMM Socket Question In-Reply-To: <4E28CEA517A795438B120F62D182A8C9236CD8@I2KM11-UKBR.domain1.systemhost.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_26780_31251066.1129305443080" References: <4E28CEA517A795438B120F62D182A8C9236CD8@I2KM11-UKBR.domain1.systemhost.net> Sender: bluez-users-admin@lists.sourceforge.net Errors-To: bluez-users-admin@lists.sourceforge.net Reply-To: bluez-users@lists.sourceforge.net List-Unsubscribe: , List-Id: BlueZ users List-Post: List-Help: List-Subscribe: , List-Archive: Date: Fri, 14 Oct 2005 11:57:23 -0400 ------=_Part_26780_31251066.1129305443080 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline http://people.csail.mit.edu/albert/bluez-intro/x499.html#bzi-dynamic-port-n= umbers -albert On 10/14/05, graeme.n.brown@bt.com 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 =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 h= ere > ? 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); > > 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 > Bluez-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/bluez-users > ------=_Part_26780_31251066.1129305443080 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline http://people.csail.mit.edu/albert/bluez-intro/x499.html= #bzi-dynamic-port-numbers

-albert

On 10/14/05, graeme.n.brown@bt.= com <graeme.n.brown@bt.= com > 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 d= o I set the

/* RFCOMM socket address */
struct sockaddr_rc {
        sa_family_t  &nbs= p;  rc_family;
        bdad= dr_t        rc_bdaddr;
 &nb= sp;      uint8_t     = ;    rc_channel;
};


sockaddr_rc.rc_channel to = do this before I call bind ?

E.g.

    &nb= sp;   int listenfd, cliSocket ;
        sockaddr_rc addr, raddr= ;
        socklen_t optlen;
=
        listenfd =3D socket(PF_= BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
     &= nbsp;  if (listenfd < 0) {
     &n= bsp;    printf(Can't create socket: %s (%d)\n", st= rerror(errno), errno);
          exit(1);        }

   = ;     /* Bind to local address */
  &= nbsp;     addr.rc_family =3D AF_BLUETOOTH;
&nbs= p;       bacpy(&addr.rc_bdaddr, BDAD= DR_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);<= br>           close(liste= nfd);
           exit(1);        }

  &nbs= p;     memset(&raddr, 0, sizeof(raddr));
&n= bsp;       optlen =3D sizeof(raddr);
=         cliSocket =3D accept(listen= fd, (struct sockaddr *) &raddr, &optlen);

   =      if (cliSocket < 0) {
            = ; printf(buff, "Accept failed: %s (%d)\n", strerror(errno), errno);=
            = ; close(listenfd) ;
        &nbs= p;    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
Bluez-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/list= info/bluez-users

------=_Part_26780_31251066.1129305443080-- ------------------------------------------------------- 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 Bluez-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bluez-users