Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / linux / rfcomm.c
blobdbda1f5b8833b18e438a1d153afb8e817193c34f
1 #include <stdint.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <sys/types.h>
5 #include <sys/socket.h>
6 #include "../../memcheck.h"
8 /* user space headers might not be there, define things ourselves. */
9 typedef struct {
10 uint8_t b[6];
11 } __attribute__((packed)) vui_bdaddr_t;
13 struct vui_sockaddr_rc {
14 sa_family_t rc_family;
15 vui_bdaddr_t rc_bdaddr;
16 uint8_t rc_channel;
19 #define VUI_AF_BLUETOOTH 31
20 #define VUI_BTPROTO_RFCOMM 3
22 #define VUI_BDADDR_ANY (&(vui_bdaddr_t) {{0, 0, 0, 0, 0, 0}})
24 int
25 main (int argc, char **argv)
27 int nSocket;
29 nSocket = socket(VUI_AF_BLUETOOTH, SOCK_STREAM, VUI_BTPROTO_RFCOMM);
31 if (nSocket < 0)
33 // Not supported, nothing to test...
34 return 1;
37 struct vui_sockaddr_rc aAddr;
39 // Store correct values in aAddr but marking it undefined
40 // so as to generate errors. We need to have deterministic
41 // undefined values to have a reproducible test.
42 aAddr.rc_family = VUI_AF_BLUETOOTH;
43 aAddr.rc_bdaddr = *VUI_BDADDR_ANY;
44 aAddr.rc_channel = 5;
45 VALGRIND_MAKE_MEM_UNDEFINED(&aAddr, sizeof(aAddr));
46 // We re-assign below each piece one by one, so as to
47 // have the piece marked initialised.
50 // Ignore return values.
52 // Everything uninit (family, ...)
53 bind(nSocket, (struct sockaddr *) &aAddr, sizeof(aAddr));
55 // Same but with an unknown family (we hope :)
56 aAddr.rc_family = 12345;
57 // (reset everything to uninit)
58 VALGRIND_MAKE_MEM_UNDEFINED(&aAddr, sizeof(aAddr));
59 bind(nSocket, (struct sockaddr *) &aAddr, sizeof(aAddr));
61 aAddr.rc_family = VUI_AF_BLUETOOTH;
62 // uninit bdaddr and channel.
63 bind(nSocket, (struct sockaddr *) &aAddr, sizeof(aAddr));
65 aAddr.rc_bdaddr = *VUI_BDADDR_ANY;
66 // uninit channel.
67 bind(nSocket, (struct sockaddr *) &aAddr, sizeof(aAddr));
69 aAddr.rc_channel = 5;
70 // Everything correctly init.
71 bind(nSocket, (struct sockaddr *) &aAddr, sizeof(aAddr));
73 return 0;