Friday, 29 August 2014

1.first scan from previous program get the baddr
2.replace it and  also replace the file name and get connected
3.send data
4.yahoooooooooooo

*gcc -o client_blue client_blue.c -lbluetooth


#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/socket.h>
#include<bluetooth/bluetooth.h>
#include<bluetooth/rfcomm.h>
#include<bluetooth/hci.h>
#include<bluetooth/hci_lib.h>
#include <sys/sendfile.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

//sssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);


int main (int argc , char * * argv )
{
struct sockaddr_rc addr={0} ;

int s,status;
ssize_t bytes_send ;
char dest[18] = "D4:5D:42:91:EE:0A" ;
int fd=open("/home/sourav/Desktop/images_7.jpeg",O_RDONLY);
if(fd<0)
perror ("open:");

size_t count=1528    ;

s = socket (AF_BLUETOOTH, SOCK_STREAM,BTPROTO_RFCOMM) ;
addr.rc_family=AF_BLUETOOTH;
addr.rc_channel=1;
str2ba(dest,&addr.rc_bdaddr) ;
status = connect (s,( struct sockaddr * )&addr,sizeof (addr)) ;
if(status<0)
 perror ("connect");
else
  printf("connected \n");

bytes_send=sendfile(s,fd,NULL,count);
if(bytes_send<0)
  perror("sendfile:");
else
printf("bytes send : %d \n",bytes_send);

close(fd);
close(s) ;
return 0 ;
}

No comments:

Post a Comment