2006-01-13 23:15:42

by Verber Seti

[permalink] [raw]
Subject: [Bluez-users] sendto give invalid argument

Hello, I'm new to using Bluez. I need to create a simple program to send text over a specific type of port (SOCK_DGRAM, BTPROTO_L2CAP). The code compiles fine, but when I run it i get the following error (from then sendto function). Send Failed: Invalid argument What might the problem be? My code is shown below. Thank-you so much for any help that you can offer.,verber #include <stdio.h>#include <stdlib.h>#include <errno.h>#include <string.h> #include <bluetooth/bluetooth.h>#include <bluetooth/l2cap.h>#include <bluetooth/hci.h>#include <bluetooth/hci_lib.h> #include "l2cap_msg_send.h" int fd; int send_msg(){ /* SETTING UP SOCKET */ struct sockaddr_l2 addr; unsigned int psm = 0x1001; fd = socket(AF_BLUETOOTH, SOCK_DGRAM, BTPROTO_L2CAP); if (fd == -1) { fprintf(stderr, "Could not open socket: %s\n", strerror(errno)); exit(1); } addr.l2_family = AF_BLUETOOTH; bacpy(&addr.l2_bdaddr, BDADDR_ANY); addr.l2_psm = htobs(psm); if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { fprintf(stderr, "Could not bind socket: %s\n", strerror(errno)); exit(1); } /* END: SETTING UP SOCKET*/ /* SET UP MSG */ char recv_addr[18] = "00:0A:3A:53:1C:42"; struct sockaddr_l2 recipient; recipient.l2_family = AF_BLUETOOTH; str2ba(recv_addr,&(recipient.l2_bdaddr)); recipient.l2_psm = htobs(psm); char message[] = "57 123 189"; /* END: SET UP MSG */ /* SEND MSG */ int ret; socklen_t len; len=sizeof(recipient.l2_bdaddr); size_t msg_len; msg_len=sizeof(message); ret = sendto(fd, &message, msg_len,0, (struct sockaddr *) &recipient, len); printf("%d\n",ret); if( ret < 0 ) fprintf(stderr,"Send Failed: %s\n",strerror(errno)); /* END: SEND MSG */ // close(fd); return 0;}
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


2006-01-13 23:32:07

by P. Durante

[permalink] [raw]
Subject: Re: [Bluez-users] sendto give invalid argument

I didn't look very carefully at your code, but the first thing I
noticed is how you create the socket, I wrote a C++ wrapper over bluez
a while ago and it has a class for L2Cap connections, the constructor
goes this way:

L2CapSocket::L2CapSocket()
:=09Socket( PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP )
{}

and it worked great for me, so maybe you should pass different
parameters to the socket(...); call.

regards,
Paul


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

2006-01-14 00:23:21

by Verber Seti

[permalink] [raw]
Subject: RE: Re: [Bluez-users] sendto give invalid argument

Thanks for the help Paul,
?
Unfortunately, for reasons outside the scope of this email I am restricted to using
SOCK_DGRAM only for this program instead of?SOCK_SEQPACKET or any other values.
?
Thanks again,
verber



> From: [email protected]> To: [email protected]> Subject: Re: [Bluez-users] sendto give invalid argument> Date: Sat, 14 Jan 2006 00:32:07 +0100> > I didn't look very carefully at your code, but the first thing I> noticed is how you create the socket, I wrote a C++ wrapper over bluez> a while ago and it has a class for L2Cap connections, the constructor> goes this way:> > L2CapSocket::L2CapSocket()> : Socket( PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP )> {}> > and it worked great for me, so maybe you should pass different> parameters to the socket(...); call.> > regards,> Paul> > > -------------------------------------------------------> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files> for problems? Stop! Download the new AJAX search engine that makes> searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!> http://ads.osdn.com/?ad_idv37&alloc_id865&op=ick> _______________________________________________> Bluez-users mailing list> [email protected]> https://lists.sourceforge.net/lists/listinfo/bluez-users
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/