Linux bluetooth development
 help / color / mirror / Atom feed
* [Bluez-users] sendto give invalid argument
@ 2006-01-13 23:15 Verber Seti
  2006-01-13 23:32 ` P. Durante
  0 siblings, 1 reply; 2+ messages in thread
From: Verber Seti @ 2006-01-13 23:15 UTC (permalink / raw)
  To: bluez-users

[-- Attachment #1: Type: text/plain, Size: 1985 bytes --]

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/

[-- Attachment #2: Type: text/html, Size: 2732 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Bluez-users] sendto give invalid argument
  2006-01-13 23:15 [Bluez-users] sendto give invalid argument Verber Seti
@ 2006-01-13 23:32 ` P. Durante
  0 siblings, 0 replies; 2+ messages in thread
From: P. Durante @ 2006-01-13 23:32 UTC (permalink / raw)
  To: bluez-users

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-01-13 23:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-13 23:15 [Bluez-users] sendto give invalid argument Verber Seti
2006-01-13 23:32 ` P. Durante

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox