Return-Path:
Message-ID:
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="_acdb1c71-1ce9-413d-874d-b647266eb24a_"
From: "Verber Seti"
To:
Subject: [Bluez-users] sendto give invalid argument
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, 13 Jan 2006 18:15:42 -0500
--_acdb1c71-1ce9-413d-874d-b647266eb24a_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hello, I'm new to using Bluez. I need to create a simple program to send te=
xt over a specific type of port (SOCK_DGRAM, BTPROTO_L2CAP). The code compi=
les fine, but when I run it i get the following error (from then sendto fun=
ction). 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 #in=
clude #include #include #include #in=
clude #include #include #include #include "l2cap_msg_send.h" int fd; =
int send_msg(){ /* SETTING UP SOCKET */ struct sockaddr_l2 addr; unsigne=
d int psm =3D 0x1001; fd =3D socket(AF_BLUETOOTH, SOCK_DGRAM, BTPROT=
O_L2CAP); if (fd =3D=3D -1) { fprintf(stderr, "Could not open soc=
ket: %s\n", strerror(errno)); exit(1); } addr.l2_family =3D AF_BLUET=
OOTH; bacpy(&addr.l2_bdaddr, BDADDR_ANY); addr.l2_psm =3D htobs(ps=
m); 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_a=
ddr[18] =3D "00:0A:3A:53:1C:42"; struct sockaddr_l2 recipient; re=
cipient.l2_family =3D AF_BLUETOOTH; str2ba(recv_addr,&(recipient.l2_bdad=
dr)); recipient.l2_psm =3D htobs(psm); char message[] =3D "57 123=
189"; /* END: SET UP MSG */ /* SEND MSG */ int ret; socklen_t len;=
len=3Dsizeof(recipient.l2_bdaddr); size_t msg_len; msg_len=3Dsizeof(messa=
ge); ret =3D sendto(fd, &message, msg_len,0, (struct sockaddr *) &recip=
ient, len); printf("%d\n",ret); if( ret < 0 ) fprintf(stderr,"Send Fa=
iled: %s\n",strerror(errno)); /* END: SEND MSG */ // close(fd); retur=
n 0;}
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/=
--_acdb1c71-1ce9-413d-874d-b647266eb24a_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
=0A=
=0A=
=0A=
=0A=
Hello,
I'm new to using Bluez. I need to create a si=
mple 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 erro=
r (from then sendto function).
Send Failed: Invalid argument<=
/P>
What might the problem be? My code is shown below. Thank-you =
so much for any help that you can offer.
,verber
#inclu=
de <stdio.h>
#include <stdlib.h>
#include <errno=
.h>
#include <string.h>
#include <bluetooth=
/bluetooth.h>
#include <bluetooth/l2cap.h>
#include &l=
t;bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include "l2cap_msg_send.h"
int fd;
=
int send_msg()
{
/* SETTING UP SOCKET */
struct sock=
addr_l2 addr;
unsigned int psm =3D 0x1001;
f=
d =3D socket(AF_BLUETOOTH, SOCK_DGRAM, BTPROTO_L2CAP);
if (fd =3D=
=3D -1) {
fprintf(stderr, "Could not open socket: %s\n&q=
uot;, strerror(errno));
exit(1);
}
addr.l2_fami=
ly =3D AF_BLUETOOTH;
bacpy(&addr.l2_bdaddr, BDADDR_ANY);
<=
P> addr.l2_psm =3D htobs(psm);
if (bind(fd, (struct=
sockaddr *) &addr, sizeof(addr)) < 0) {
fprintf(stder=
r, "Could not bind socket: %s\n", strerror(errno));
exit(=
1);
}
/* END: SETTING UP SOCKET*/
=
/* SET UP MSG */
char recv_addr[18] =3D "00:0A:3A:53:1C:42&q=
uot;;
struct sockaddr_l2 recipient;
recipien=
t.l2_family =3D AF_BLUETOOTH;
str2ba(recv_addr,&(recipient.l2=
_bdaddr));
recipient.l2_psm =3D htobs(psm);
=
char message[] =3D "57 123 189";
/* END: SET UP MSG */<=
/P>
/* SEND MSG */
int ret;
socklen_t l=
en;
len=3Dsizeof(recipient.l2_bdaddr);
size_t msg_len=
;
msg_len=3Dsizeof(message);
ret =3D sendto(fd, &a=
mp;message, msg_len,0, (struct sockaddr *) &recipient, len);
=
printf("%d\n",ret);
if( ret < 0 ) fprintf(stderr,&qu=
ot;Send Failed: %s\n",strerror(errno));
/* END: SEND MSG */
=
// close(fd);
return 0;
}
Expr=
ess yourself instantly with MSN Messenger! MSN Messenger=
=0A=
=
--_acdb1c71-1ce9-413d-874d-b647266eb24a_--
-------------------------------------------------------
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
Bluez-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-users