我有一個代碼,我需要創建一個L2CAP套接字,連接到一個設備並設置相同的MTU。試圖這樣做時,我收到錯誤「無效參數」。套接字被創建,綁定完成到一個bd_address並且連接也完成。setsocketoptions L2CAP_OPTIONS失敗,出現「無效參數錯誤」
sk = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_L2CAP);
if (sk < 0)
{
perror("Can't create socket");
}
/* Bind to local address */
memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
str2ba(LOCAL_DEVICE_ADDRESS, &addr.l2_bdaddr);
if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0)
{
perror("Can't bind socket");
}
/* Connect to remote device */
memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
str2ba(REMOTE_DEVICE_ADDRESS, &addr.l2_bdaddr);
if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0)
{
perror("Can't connect");
}
perror("connected");
if (getsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &opts, sizeof(opts)) < 0)
{
perror("Can't get L2CAP MTU options");
close(sk);
}
opts.imtu = 672; //this is default value
opts.omtu = 672; //tried changing this too
if (setsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &opts, sizeof(opts)) < 0)
{
perror("Can't set L2CAP MTU options");
close(sk);
}
獲取錯誤「無法設置L2CAP MTU選項:無效參數」 – dfordevy