/usr/share/doc/liblowpan-dev/examples/test3.c is in liblowpan-dev 0.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | /*
* Linux IEEE 802.15.4 userspace tools
*
* Copyright (C) 2008, 2009 Siemens AG
*
* Written-by: Dmitry Eremin-Solenikov
* Written-by: Sergey Lapin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <linux/sockios.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include "ieee802154.h"
int main(int argc, char **argv) {
int ret;
struct sockaddr_ieee802154 sa = {};
struct ifreq req = {};
char buf[] = {0x01, 0x80, 0xa5, 0x5a};
int sd = socket(PF_IEEE802154, SOCK_DGRAM, 0);
if (sd < 0) {
perror("socket");
return 1;
}
strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE);
ret = ioctl(sd, SIOCGIFHWADDR, &req);
if (ret < 0)
perror("ioctl: SIOCGIFHWADDR");
sa.family = AF_IEEE802154;
sa.addr.addr_type = IEEE802154_ADDR_LONG;
sa.addr.pan_id = 0xffff;
memcpy(&sa.addr.hwaddr, req.ifr_hwaddr.sa_data, sizeof(sa.addr.hwaddr));
ret = bind(sd, (struct sockaddr*)&sa, sizeof(sa));
if (ret < 0)
perror("bind");
ret = connect(sd, (struct sockaddr*)&sa, sizeof(sa));
if (ret < 0)
perror("connect");
ret = send(sd, buf, sizeof(buf), 0);
if (ret < 0)
perror("send");
ret = recv(sd, buf, sizeof(buf), 0);
if (ret < 0)
perror("recv");
ret = shutdown(sd, SHUT_RDWR);
if (ret < 0)
perror("shutdown");
ret = close(sd);
if (ret < 0)
perror("close");
return 0;
}
|