#include #include #include #include #include #include #include int main(int argc, char *argv[]) { struct sockaddr_l2 addr; int s = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); int opt, n; struct l2cap_options opts; char buf[1024]; int mtu = atoi(argv[2]); if (0 > s) { perror("socket"); return -1; } opt = sizeof(struct l2cap_options); opts.imtu = L2CAP_DEFAULT_MTU; opts.omtu = mtu; if (0 > setsockopt(s, SOL_L2CAP, L2CAP_OPTIONS, &opts, opt)) { perror("setsockopt(l2cap)"); close(s); return -1; } addr.l2_psm = htobs(0x1001); addr.l2_family = AF_BLUETOOTH; baswap(&addr.l2_bdaddr, strtoba(argv[1])); if (0 > connect(s, (struct sockaddr *)&addr, sizeof(addr))) { perror("connect"); return -1; } if (0 > getsockopt(s, SOL_L2CAP, L2CAP_OPTIONS, &opts, &opt)) { perror("getsockopt"); return -1; } printf("imtu=%d omtu=%d\n", opts.imtu, opts.omtu); n = sizeof(buf); if (mtu == 0) n = opts.omtu; else if (n > mtu) n = mtu; n = write(s, buf, n); if (0 > n) { perror("write"); return -1; } printf("wrote %d bytes\n", n); close(s); return 0; }