-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathLibcNativeMethods.cs
More file actions
923 lines (834 loc) · 56.6 KB
/
Copy pathLibcNativeMethods.cs
File metadata and controls
923 lines (834 loc) · 56.6 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
#region License
/*
BSD 3-Clause License
Copyright (c) 2021, Derek Will
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion
using System;
using System.Net.Sockets;
using System.Runtime.InteropServices;
namespace SocketCANSharp
{
/// <summary>
/// C Standard Library Native Methods
/// </summary>
public static class LibcNativeMethods
{
/// <summary>
/// Number of the last error which indicates what went wrong. Set by system calls and some library functions when an error occurs.
/// </summary>
public static int Errno { get { return Marshal.GetLastWin32Error(); } }
/// <summary>
/// Creates a CAN socket.
/// </summary>
/// <param name="addressFamily">Address Family</param>
/// <param name="socketType">Type of socket</param>
/// <param name="protocolType">CAN Protocol Type</param>
/// <returns>Socket Handle Wrapper Instance</returns>
[DllImport("libc", EntryPoint="socket", SetLastError=true)]
public static extern SafeFileDescriptorHandle Socket(int addressFamily, SocketType socketType, SocketCanProtocolType protocolType);
/// <summary>
/// Manipulates the underlying device parameters of special files.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="request">Request Code</param>
/// <param name="arg">Integer Argument</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="ioctl", SetLastError=true)]
public static extern int Ioctl(SafeFileDescriptorHandle socketHandle, int request, ref int arg);
/// <summary>
/// Manipulates the underlying device parameters of special files.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="request">Request Code</param>
/// <param name="ifreq">Interface Request structure</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="ioctl", SetLastError=true)]
public static extern int Ioctl(SafeFileDescriptorHandle socketHandle, int request, [In][Out] Ifreq ifreq);
/// <summary>
/// Manipulates the underlying device parameters of special files.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="request">Request Code</param>
/// <param name="ifreq">Interface Request structure</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint = "ioctl", SetLastError = true)]
public static extern int Ioctl(SafeFileDescriptorHandle socketHandle, int request, [In][Out] IfreqMtu ifreq);
/// <summary>
/// Used to obtain a timeval struct with the receive timestamp of the last packet passed to the user.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="request">Request Code</param>
/// <param name="timeval">Timeval structure</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint = "ioctl", SetLastError = true)]
public static extern int Ioctl(SafeFileDescriptorHandle socketHandle, int request, [In][Out] Timeval timeval);
/// <summary>
/// Assigns the specified SocketCAN base address to the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="addr">SocketCAN base address structure</param>
/// <param name="addrSize">Size of address structure</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="bind", SetLastError=true)]
public static extern int Bind(SafeFileDescriptorHandle socketHandle, SockAddrCan addr, int addrSize);
/// <summary>
/// Assigns the specified SocketCAN ISO-TP address to the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="addr">SocketCAN ISO-TP address structure</param>
/// <param name="addrSize">Size of address structure</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="bind", SetLastError=true)]
public static extern int Bind(SafeFileDescriptorHandle socketHandle, SockAddrCanIsoTp addr, int addrSize);
/// <summary>
/// Assigns the specified SocketCAN J1939 address to the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="addr">SocketCAN J1939 address structure</param>
/// <param name="addrSize">Size of address structure</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="bind", SetLastError=true)]
public static extern int Bind(SafeFileDescriptorHandle socketHandle, SockAddrCanJ1939 addr, int addrSize);
/// <summary>
/// Establishes a connection on the socket to the specified SocketCAN base address.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="addr">SocketCAN base address structure containing the peer address</param>
/// <param name="addrSize">Size of address structure</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="connect", SetLastError=true)]
public static extern int Connect(SafeFileDescriptorHandle socketHandle, SockAddrCan addr, int addrSize);
/// <summary>
/// Establishes a connection on the socket to the specified SocketCAN base address.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="addr">SocketCAN J1939 address structure containing the peer address</param>
/// <param name="addrSize">Size of address structure</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="connect", SetLastError=true)]
public static extern int Connect(SafeFileDescriptorHandle socketHandle, SockAddrCanJ1939 addr, int addrSize);
/// <summary>
/// Write the CanFrame to the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrappper Instance</param>
/// <param name="frame">CAN Frame to write</param>
/// <param name="frameSize">Size of CAN Frame in bytes</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, ref CanFrame frame, int frameSize);
/// <summary>
/// Write the CanFdFrame to the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="frame">CAN FD Frame to write</param>
/// <param name="frameSize">Size of CAN FD Frame in bytes</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, ref CanFdFrame frame, int frameSize);
/// <summary>
/// Write the CanXlFrame to the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="frame">CAN XL Frame to write</param>
/// <param name="frameSize">Size of CAN XL Frame in bytes</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, ref CanXlFrame frame, int frameSize);
/// <summary>
/// Write the BcmCanMessage to the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">BCM Message to write</param>
/// <param name="msgSize">Size of BCM Message in bytes</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, BcmCanMessage message, int msgSize);
/// <summary>
/// Write the BcmCanFdMessage to the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">BCM Message to write</param>
/// <param name="msgSize">Size of BCM Message in bytes</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, BcmCanFdMessage message, int msgSize);
/// <summary>
/// Write the BcmCanSingleMessage to the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">Special Single Frame BCM Message to write</param>
/// <param name="msgSize">Size of BCM Message in bytes</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, BcmCanSingleMessage message, int msgSize);
/// <summary>
/// Write the BcmCanFdSingleMessage to the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">Special Single Frame BCM Message to write</param>
/// <param name="msgSize">Size of BCM Message in bytes</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, BcmCanFdSingleMessage message, int msgSize);
/// <summary>
/// Write the BcmMessageHeader to the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="header">BCM Message Header to write</param>
/// <param name="headerSize">Size of BCM Message Header in bytes</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, BcmMessageHeader header, int headerSize);
/// <summary>
/// Write the BcmCanMessage to the socket. Variant for 32-bit.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">BCM Message to write</param>
/// <param name="msgSize">Size of BCM Message in bytes</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, BcmCanMessage32 message, int msgSize);
/// <summary>
/// Write the BcmCanFdMessage to the socket. Variant for 32-bit.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">BCM Message to write</param>
/// <param name="msgSize">Size of BCM Message in bytes</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, BcmCanFdMessage32 message, int msgSize);
/// <summary>
/// Write the BcmCanSingleMessage to the socket. Variant for 32-bit.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">Special Single Frame BCM Message to write</param>
/// <param name="msgSize">Size of BCM Message in bytes</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, BcmCanSingleMessage32 message, int msgSize);
/// <summary>
/// Write the BcmCanFdSingleMessage to the socket. Variant for 32-bit.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">Special Single Frame BCM Message to write</param>
/// <param name="msgSize">Size of BCM Message in bytes</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, BcmCanFdSingleMessage32 message, int msgSize);
/// <summary>
/// Write the BcmMessageHeader to the socket. Variant for 32-bit.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="header">BCM Message Header to write</param>
/// <param name="headerSize">Size of BCM Message Header in bytes</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, BcmMessageHeader32 header, int headerSize);
/// <summary>
/// Write the byte array to the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="data">Byte Array to write</param>
/// <param name="dataSize">Size of Byte Array</param>
/// <returns>The number of bytes written on success, -1 on error</returns>
[DllImport("libc", EntryPoint="write", SetLastError=true)]
public static extern int Write(SafeFileDescriptorHandle socketHandle, byte[] data, int dataSize);
/// <summary>
/// Read a CanFrame from the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="frame">CAN Frame structure to populate</param>
/// <param name="frameSize">Size of CAN Frame structure</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint="read", SetLastError=true)]
public static extern int Read(SafeFileDescriptorHandle socketHandle, ref CanFrame frame, int frameSize);
/// <summary>
/// Read a CanFdFrame from the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="frame">CAN FD Frame structure to populate</param>
/// <param name="frameSize">Size of CAN FD Frame structure</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint="read", SetLastError=true)]
public static extern int Read(SafeFileDescriptorHandle socketHandle, ref CanFdFrame frame, int frameSize);
/// <summary>
/// Read a CanXlFrame from the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="frame">CAN XL Frame structure to populate</param>
/// <param name="frameSize">Size of CAN XL Frame structure</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint="read", SetLastError=true)]
public static extern int Read(SafeFileDescriptorHandle socketHandle, ref CanXlFrame frame, int frameSize);
/// <summary>
/// Read a BcmCanMessage from the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">BCM CAN Message structure to populate</param>
/// <param name="msgSize">Size of BCM CAN Message structure</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint="read", SetLastError=true)]
public static extern int Read(SafeFileDescriptorHandle socketHandle, [Out] BcmCanMessage message, int msgSize);
/// <summary>
/// Read a BcmGenericMessage from the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">BCM Generic Message structure to populate</param>
/// <param name="msgSize">Size of BCM Generic Message structure</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint="read", SetLastError=true)]
public static extern int Read(SafeFileDescriptorHandle socketHandle, [Out] BcmGenericMessage message, int msgSize);
/// <summary>
/// Read a BcmGenericMessage from the socket. Variant for 32-bit.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">BCM Generic Message structure to populate</param>
/// <param name="msgSize">Size of BCM Generic Message structure</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint="read", SetLastError=true)]
public static extern int Read(SafeFileDescriptorHandle socketHandle, [Out] BcmGenericMessage32 message, int msgSize);
/// <summary>
/// Read a BcmCanFdMessage from the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">BCM CAN Message structure to populate</param>
/// <param name="msgSize">Size of BCM CAN FD Message structure</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint="read", SetLastError=true)]
public static extern int Read(SafeFileDescriptorHandle socketHandle, [Out] BcmCanFdMessage message, int msgSize);
/// <summary>
/// Read a BcmCanMessage from the socket. Variant for 32-bit.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">BCM CAN Message structure to populate</param>
/// <param name="msgSize">Size of BCM CAN Message structure</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint="read", SetLastError=true)]
public static extern int Read(SafeFileDescriptorHandle socketHandle, [Out] BcmCanMessage32 message, int msgSize);
/// <summary>
/// Read a BcmCanFdMessage from the socket. Variant for 32-bit.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="message">BCM CAN Message structure to populate</param>
/// <param name="msgSize">Size of BCM CAN FD Message structure</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint="read", SetLastError=true)]
public static extern int Read(SafeFileDescriptorHandle socketHandle, [Out] BcmCanFdMessage32 message, int msgSize);
/// <summary>
/// Read a byte array from the socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="data">Byte array to populate</param>
/// <param name="dataSize">Size of byte array</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint="read", SetLastError=true)]
public static extern int Read(SafeFileDescriptorHandle socketHandle, [Out] byte[] data, int dataSize);
/// <summary>
/// Receive a CanFrame from a socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="frame">CAN Frame structure</param>
/// <param name="frameSize">Size of CAN Frame structure</param>
/// <param name="flags">Message Flags</param>
/// <param name="addr">The SocketCAN base source address</param>
/// <param name="addrSize">The size of the SocketCAN base address</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint="recvfrom", SetLastError=true)]
public static extern int RecvFrom(SafeFileDescriptorHandle socketHandle, ref CanFrame frame, int frameSize, MessageFlags flags, [Out] SockAddrCan addr, ref int addrSize);
/// <summary>
/// Receive a CanFdFrame from a socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="frame">CAN FD Frame structure</param>
/// <param name="frameSize">Size of CAN FD Frame structure</param>
/// <param name="flags">Message Flags</param>
/// <param name="addr">The SocketCAN base source address</param>
/// <param name="addrSize">The size of the SocketCAN base address</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint="recvfrom", SetLastError=true)]
public static extern int RecvFrom(SafeFileDescriptorHandle socketHandle, ref CanFdFrame frame, int frameSize, MessageFlags flags, [Out] SockAddrCan addr, ref int addrSize);
/// <summary>
/// Receive a byte array from a socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="data">Byte array</param>
/// <param name="dataSize">Size of byte array</param>
/// <param name="flags">Message Flags</param>
/// <param name="addr">The SocketCAN J1939 source address</param>
/// <param name="addrSize">The size of the SocketCAN J1939 address</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint = "recvfrom", SetLastError = true)]
public static extern int RecvFrom(SafeFileDescriptorHandle socketHandle, [Out] byte[] data, int dataSize, MessageFlags flags, [Out] SockAddrCanJ1939 addr, ref int addrSize);
/// <summary>
/// Receive a byte array on a connected socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="data">Byte array</param>
/// <param name="dataSize">Size of byte array</param>
/// <param name="flags">Message Flags</param>
/// <returns>The number of bytes read on success, -1 on error</returns>
[DllImport("libc", EntryPoint="recv", SetLastError=true)]
public static extern int Recv(SafeFileDescriptorHandle socketHandle, [Out] byte[] data, int dataSize, MessageFlags flags);
/// <summary>
/// Transmit a CanFrame to another socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="frame">CAN Frame structure</param>
/// <param name="frameSize">Size of CAN Frame structure</param>
/// <param name="flags">Message Flags</param>
/// <param name="addr">The SocketCAN base destination address</param>
/// <param name="addrSize">The size of the SocketCAN base address</param>
/// <returns>The number of bytes sent on success, -1 on error</returns>
[DllImport("libc", EntryPoint="sendto", SetLastError=true)]
public static extern int SendTo(SafeFileDescriptorHandle socketHandle, ref CanFrame frame, int frameSize, MessageFlags flags, SockAddrCan addr, int addrSize);
/// <summary>
/// Transmit a CanFdFrame to another socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="frame">CAN FD Frame structure</param>
/// <param name="frameSize">Size of CAN FD Frame structure</param>
/// <param name="flags">Message Flags</param>
/// <param name="addr">The SocketCAN base destination address</param>
/// <param name="addrSize">The size of the SocketCAN base address</param>
/// <returns>The number of bytes sent on success, -1 on error</returns>
[DllImport("libc", EntryPoint="sendto", SetLastError=true)]
public static extern int SendTo(SafeFileDescriptorHandle socketHandle, ref CanFdFrame frame, int frameSize, MessageFlags flags, SockAddrCan addr, int addrSize);
/// <summary>
/// Transmit a byte array to another socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="data">Byte array</param>
/// <param name="dataSize">Size of byte array</param>
/// <param name="flags">Message Flags</param>
/// <param name="addr">The SocketCAN J1939 destination address</param>
/// <param name="addrSize">The size of the SocketCAN J1939 address</param>
/// <returns>The number of bytes sent on success, -1 on error</returns>
[DllImport("libc", EntryPoint="sendto", SetLastError=true)]
public static extern int SendTo(SafeFileDescriptorHandle socketHandle, byte[] data, int dataSize, MessageFlags flags, SockAddrCanJ1939 addr, int addrSize);
/// <summary>
/// Transmit a byte array to another socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="data">Byte array</param>
/// <param name="dataSize">Size of byte array</param>
/// <param name="flags">Message Flags</param>
/// <returns>The number of bytes sent on success, -1 on error</returns>
[DllImport("libc", EntryPoint="send", SetLastError=true)]
public static extern int Send(SafeFileDescriptorHandle socketHandle, byte[] data, int dataSize, MessageFlags flags);
/// <summary>
/// Set the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_RAW socket handle</param>
/// <param name="socketLevel">SOL_CAN_RAW</param>
/// <param name="optionName">SOL_CAN_RAW socket option</param>
/// <param name="optionValue">Unsigned integer value</param>
/// <param name="optionValueSize">Size of unsigned interger</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="setsockopt", SetLastError=true)]
public static extern int SetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanSocketOptions optionName, ref uint optionValue, int optionValueSize);
/// <summary>
/// Get the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_RAW socket handle</param>
/// <param name="socketLevel">SOL_CAN_RAW</param>
/// <param name="optionName">SOL_CAN_RAW socket option</param>
/// <param name="optionValue">Unsigned integer value</param>
/// <param name="optionValueSize">Size of an unsigned integer</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockopt", SetLastError=true)]
public static extern int GetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanSocketOptions optionName, ref uint optionValue, ref int optionValueSize);
/// <summary>
/// Set the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_RAW socket handle</param>
/// <param name="socketLevel">SOL_CAN_RAW</param>
/// <param name="optionName">SOL_CAN_RAW socket option</param>
/// <param name="filters">Array of CAN Filters</param>
/// <param name="optionValueSize">Size of CAN Filter Array in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="setsockopt", SetLastError=true)]
public static extern int SetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanSocketOptions optionName, CanFilter[] filters, int optionValueSize);
/// <summary>
/// Get the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_RAW socket handle</param>
/// <param name="socketLevel">SOL_CAN_RAW</param>
/// <param name="optionName">SOL_CAN_RAW socket option</param>
/// <param name="filters">Array of CAN Filters</param>
/// <param name="optionValueSize">Size of CAN Filter Array in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockopt", SetLastError=true)]
public static extern int GetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanSocketOptions optionName, [In, Out] CanFilter[] filters, ref int optionValueSize);
/// <summary>
/// Set the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_RAW socket handle</param>
/// <param name="socketLevel">SOL_CAN_RAW</param>
/// <param name="optionName">SOL_CAN_RAW socket option</param>
/// <param name="optionValue">Signed Integer Value</param>
/// <param name="optionValueSize">Size of signed integer</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="setsockopt", SetLastError=true)]
public static extern int SetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanSocketOptions optionName, ref int optionValue, int optionValueSize);
/// <summary>
/// Get the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_RAW socket handle</param>
/// <param name="socketLevel">SOL_CAN_RAW</param>
/// <param name="optionName">SOL_CAN_RAW socket option</param>
/// <param name="optionValue">Signed Integer Value</param>
/// <param name="optionValueSize">Size of signed integer</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockopt", SetLastError=true)]
public static extern int GetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanSocketOptions optionName, ref int optionValue, ref int optionValueSize);
/// <summary>
/// Set the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">Socket handle</param>
/// <param name="socketLevel">SOL_SOCKET</param>
/// <param name="optionName">SOL_SOCKET socket option</param>
/// <param name="optionValue">Signed Integer Value</param>
/// <param name="optionValueSize">Size of signed integer</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="setsockopt", SetLastError=true)]
public static extern int SetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, SocketLevelOptions optionName, ref int optionValue, int optionValueSize);
/// <summary>
/// Get the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">Socket handle</param>
/// <param name="socketLevel">SOL_SOCKET</param>
/// <param name="optionName">SOL_SOCKET socket option</param>
/// <param name="optionValue">Signed Integer Value</param>
/// <param name="optionValueSize">Size of signed integer</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockopt", SetLastError=true)]
public static extern int GetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, SocketLevelOptions optionName, ref int optionValue, ref int optionValueSize);
/// <summary>
/// Set the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">Socket handle</param>
/// <param name="socketLevel">SOL_SOCKET</param>
/// <param name="optionName">SOL_SOCKET socket option</param>
/// <param name="timeval">Time interval object</param>
/// <param name="optionValueSize">Size of Time interval object in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="setsockopt", SetLastError=true)]
public static extern int SetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, SocketLevelOptions optionName, Timeval timeval, int optionValueSize);
/// <summary>
/// Get the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">Socket handle</param>
/// <param name="socketLevel">SOL_SOCKET</param>
/// <param name="optionName">SOL_SOCKET socket option</param>
/// <param name="timeval">Time interval object</param>
/// <param name="optionValueSize">Size of Time interval object in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockopt", SetLastError=true)]
public static extern int GetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, SocketLevelOptions optionName, [In, Out] Timeval timeval, ref int optionValueSize);
/// <summary>
/// Set the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_ISOTP Socket handle</param>
/// <param name="socketLevel">SOL_CAN_ISOTP</param>
/// <param name="optionName">SOL_CAN_ISOTP socket option</param>
/// <param name="optionValue">Unsigned Integer Value</param>
/// <param name="optionValueSize">Size of unsigned integer</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="setsockopt", SetLastError=true)]
public static extern int SetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanIsoTpSocketOptions optionName, ref uint optionValue, int optionValueSize);
/// <summary>
/// Get the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_ISOTP Socket handle</param>
/// <param name="socketLevel">SOL_CAN_ISOTP</param>
/// <param name="optionName">SOL_CAN_ISOTP socket option</param>
/// <param name="optionValue">Unsigned Integer Value</param>
/// <param name="optionValueSize">Size of unsigned integer</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockopt", SetLastError=true)]
public static extern int GetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanIsoTpSocketOptions optionName, ref uint optionValue, ref int optionValueSize);
/// <summary>
/// Set the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_ISOTP Socket handle</param>
/// <param name="socketLevel">SOL_CAN_ISOTP</param>
/// <param name="optionName">SOL_CAN_ISOTP socket option</param>
/// <param name="fcOptions">ISO-TP Flow Control Options object</param>
/// <param name="optionValueSize">Size of ISO-TP Flow Control Options object in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="setsockopt", SetLastError=true)]
public static extern int SetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanIsoTpSocketOptions optionName, CanIsoTpFlowControlOptions fcOptions, int optionValueSize);
/// <summary>
/// Get the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_ISOTP Socket handle</param>
/// <param name="socketLevel">SOL_CAN_ISOTP</param>
/// <param name="optionName">SOL_CAN_ISOTP socket option</param>
/// <param name="fcOptions">ISO-TP Flow Control Options object</param>
/// <param name="optionValueSize">Size of ISO-TP Flow Control Options object in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockopt", SetLastError=true)]
public static extern int GetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanIsoTpSocketOptions optionName, CanIsoTpFlowControlOptions fcOptions, ref int optionValueSize);
/// <summary>
/// Set the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_ISOTP Socket handle</param>
/// <param name="socketLevel">SOL_CAN_ISOTP</param>
/// <param name="optionName">SOL_CAN_ISOTP socket option</param>
/// <param name="llOptions">ISO-TP Link Layer Options object</param>
/// <param name="optionValueSize">Size of ISO-TP Link Layer Options object in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="setsockopt", SetLastError=true)]
public static extern int SetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanIsoTpSocketOptions optionName, CanIsoTpLinkLayerOptions llOptions, int optionValueSize);
/// <summary>
/// Get the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_ISOTP Socket handle</param>
/// <param name="socketLevel">SOL_CAN_ISOTP</param>
/// <param name="optionName">SOL_CAN_ISOTP socket option</param>
/// <param name="llOptions">ISO-TP Link Layer Options object</param>
/// <param name="optionValueSize">Size of ISO-TP Link Layer Options object in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockopt", SetLastError=true)]
public static extern int GetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanIsoTpSocketOptions optionName, CanIsoTpLinkLayerOptions llOptions, ref int optionValueSize);
/// <summary>
/// Set the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_ISOTP Socket handle</param>
/// <param name="socketLevel">SOL_CAN_ISOTP</param>
/// <param name="optionName">SOL_CAN_ISOTP socket option</param>
/// <param name="tpOptions">ISO-TP Options object</param>
/// <param name="optionValueSize">Size of ISO-TP Options object in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="setsockopt", SetLastError=true)]
public static extern int SetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanIsoTpSocketOptions optionName, CanIsoTpOptions tpOptions, int optionValueSize);
/// <summary>
/// Get the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_ISOTP Socket handle</param>
/// <param name="socketLevel">SOL_CAN_ISOTP</param>
/// <param name="optionName">SOL_CAN_ISOTP socket option</param>
/// <param name="tpOptions">ISO-TP Options object</param>
/// <param name="optionValueSize">Size of ISO-TP Options object in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockopt", SetLastError=true)]
public static extern int GetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanIsoTpSocketOptions optionName, CanIsoTpOptions tpOptions, ref int optionValueSize);
/// <summary>
/// Set the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_J1939 Socket handle</param>
/// <param name="socketLevel">SOL_CAN_J1939</param>
/// <param name="optionName">SOL_CAN_J1939 socket option</param>
/// <param name="optionValue">Signed Integer Value</param>
/// <param name="optionValueSize">Size of signed integer</param>
/// <returns>0 or 1 on success depending on option name and value, -1 on error</returns>
[DllImport("libc", EntryPoint="setsockopt", SetLastError=true)]
public static extern int SetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, J1939SocketOptions optionName, ref int optionValue, int optionValueSize);
/// <summary>
/// Get the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_J1939 Socket handle</param>
/// <param name="socketLevel">SOL_CAN_J1939</param>
/// <param name="optionName">SOL_CAN_J1939 socket option</param>
/// <param name="optionValue">Signed Integer Value</param>
/// <param name="optionValueSize">Size of signed integer</param>
/// <returns>0 or 1 on success depending on option name and value, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockopt", SetLastError=true)]
public static extern int GetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, J1939SocketOptions optionName, ref int optionValue, ref int optionValueSize);
/// <summary>
/// Set the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_J1939 Socket handle</param>
/// <param name="socketLevel">SOL_CAN_J1939</param>
/// <param name="optionName">SOL_CAN_J1939 socket option</param>
/// <param name="filters">Array of J1939 Filters</param>
/// <param name="optionValueSize">Size of array of J1939 Filters in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="setsockopt", SetLastError=true)]
public static extern int SetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, J1939SocketOptions optionName, J1939Filter[] filters, int optionValueSize);
/// <summary>
/// Get the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_J1939 Socket handle</param>
/// <param name="socketLevel">SOL_CAN_J1939</param>
/// <param name="optionName">SOL_CAN_J1939 socket option</param>
/// <param name="filters">Array of J1939 Filters</param>
/// <param name="optionValueSize">Size of array of J1939 Filters in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockopt", SetLastError=true)]
public static extern int GetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, J1939SocketOptions optionName, [In, Out] J1939Filter[] filters, ref int optionValueSize);
/// <summary>
/// Set the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">Socket handle</param>
/// <param name="socketLevel">Socket level</param>
/// <param name="optionName">Socket option</param>
/// <param name="optionValue">Pointer to option value</param>
/// <param name="optionValueSize">Size of the buffer pointed to by optionValue</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="setsockopt", SetLastError=true)]
public static extern int SetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, int optionName, IntPtr optionValue, int optionValueSize);
/// <summary>
/// Get the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">Socket handle</param>
/// <param name="socketLevel">Socket level</param>
/// <param name="optionName">Socket option</param>
/// <param name="optionValue">Pointer to option value</param>
/// <param name="optionValueSize">Size of the buffer pointed to by optionValue</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint = "getsockopt", SetLastError = true)]
public static extern int GetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, int optionName, IntPtr optionValue, ref int optionValueSize);
/// <summary>
/// Set the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_RAW socket handle</param>
/// <param name="socketLevel">SOL_CAN_RAW</param>
/// <param name="optionName">SOL_CAN_RAW socket option</param>
/// <param name="optionValue">VCID Options object</param>
/// <param name="optionValueSize">Size of VCID Options object in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="setsockopt", SetLastError=true)]
public static extern int SetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanSocketOptions optionName, CanRawVcidOptions optionValue, int optionValueSize);
/// <summary>
/// Get the socket option specified by the option name and socket level to the provided option value for the supplied socket.
/// </summary>
/// <param name="socketHandle">CAN_RAW Socket handle</param>
/// <param name="socketLevel">SOL_CAN_RAW</param>
/// <param name="optionName">SOL_CAN_RAW socket option</param>
/// <param name="optionValue">VCID Options object</param>
/// <param name="optionValueSize">Size of VCID Options object in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockopt", SetLastError=true)]
public static extern int GetSockOpt(SafeFileDescriptorHandle socketHandle, SocketLevel socketLevel, CanSocketOptions optionName, CanRawVcidOptions optionValue, ref int optionValueSize);
/// <summary>
/// Returns a pointer to an array of IfNameIndex objects. Each IfNameIndex object includes information about one of the network interfaces on the local system.
/// </summary>
/// <returns>Pointer to an array of IfNameIndex objects</returns>
[DllImport("libc", EntryPoint="if_nameindex", SetLastError=true)]
public static extern IntPtr IfNameIndex();
/// <summary>
/// Frees the dynamically allocated data structure returned by IfNameIndex().
/// </summary>
/// <param name="ptr">Pointer to an array of IfNameIndex objects</param>
[DllImport("libc", EntryPoint="if_freenameindex", SetLastError=true)]
public static extern void IfFreeNameIndex(IntPtr ptr);
/// <summary>
/// Opens an epoll file descriptor.
/// </summary>
/// <param name="size">The size argument is ignored since Linux 2.6.8, but must be greater than zero for backwards compatibility.
/// Originally, this argument was intended as a hint to the kernel as to the number of file descriptors that the caller expected to add to the epoll instance.</param>
/// <returns>On success, returns a valid file descriptor handle. On failure, returns an invalid file descriptor handle.</returns>
[DllImport("libc", EntryPoint="epoll_create", SetLastError=true)]
public static extern SafeFileDescriptorHandle EpollCreate(int size);
/// <summary>
/// Control interface used to add, modify, and delete entries from the interest list of an epoll file descriptor.
/// </summary>
/// <param name="epfd">Epoll File Descriptor.</param>
/// <param name="op">Operation to be performed.</param>
/// <param name="fd">Target file descriptor.</param>
/// <param name="evnt">Event object linked to the targeted file descriptor.</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="epoll_ctl", SetLastError=true)]
public static extern int EpollControl(SafeFileDescriptorHandle epfd, EpollOperation op, SafeFileDescriptorHandle fd, ref EpollEvent evnt);
/// <summary>
/// Waits for an I/O event on an epoll file descriptor.
/// </summary>
/// <param name="epfd">Epoll File Descriptor.</param>
/// <param name="events">A buffer that contains information from the ready lists about file descriptors in the interest list that have some event(s) available.</param>
/// <param name="maxEvents">Maximum number of events to wait for.</param>
/// <param name="timeout">The maximum number of milliseconds that the function call will block for. Set to 0 to return immediately, set to -1 to wait indefinitely.</param>
/// <returns>Returns the number of file descriptors ready for the requested I/O. Returns -1 on failure.</returns>
[DllImport("libc", EntryPoint="epoll_wait", SetLastError=true)]
public static extern int EpollWait(SafeFileDescriptorHandle epfd, [Out] EpollEvent[] events, int maxEvents, int timeout);
/// <summary>
/// Closes a file descriptor.
/// </summary>
/// <param name="fd">File descriptor to close.</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="close", SetLastError=true)]
public static extern int Close(IntPtr fd);
/// <summary>
/// Returns the current address to which the socket is bound to.
/// </summary>
/// <param name="socketHandle">Socket handle</param>
/// <param name="sockAddr">Address structure</param>
/// <param name="sockAddrLen">The size of the the socket address structure in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockname", SetLastError=true)]
public static extern int GetSockName(SafeFileDescriptorHandle socketHandle, SockAddrCan sockAddr, ref int sockAddrLen);
/// <summary>
/// Returns the current address to which the socket is bound to.
/// </summary>
/// <param name="socketHandle">Socket handle</param>
/// <param name="sockAddr">Address structure</param>
/// <param name="sockAddrLen">The size of the the socket address structure in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockname", SetLastError=true)]
public static extern int GetSockName(SafeFileDescriptorHandle socketHandle, SockAddrCanIsoTp sockAddr, ref int sockAddrLen);
/// <summary>
/// Returns the current address to which the socket is bound to.
/// </summary>
/// <param name="socketHandle">Socket handle</param>
/// <param name="sockAddr">Address structure</param>
/// <param name="sockAddrLen">The size of the the socket address structure in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getsockname", SetLastError=true)]
public static extern int GetSockName(SafeFileDescriptorHandle socketHandle, SockAddrCanJ1939 sockAddr, ref int sockAddrLen);
/// <summary>
/// Returns the address of the peer to which the socket is connected to.
/// </summary>
/// <param name="socketHandle">Socket handle</param>
/// <param name="sockAddr">Address structure</param>
/// <param name="sockAddrLen">The size of the the socket address structure in bytes</param>
/// <returns>0 on success, -1 on error</returns>
[DllImport("libc", EntryPoint="getpeername", SetLastError=true)]
public static extern int GetPeerName(SafeFileDescriptorHandle socketHandle, SockAddrCanJ1939 sockAddr, ref int sockAddrLen);
/// <summary>
/// Receive a MessageHeader from a socket.
/// </summary>
/// <param name="socketHandle">Socket Handle Wrapper Instance</param>
/// <param name="canMessage">Message Header</param>
/// <param name="flags">Message Flags</param>
/// <returns>The number of bytes received on success, -1 on error</returns>
[DllImport("libc", EntryPoint="recvmsg", SetLastError=true)]
public static extern int RecvMsg(SafeFileDescriptorHandle socketHandle, ref MessageHeader canMessage, MessageFlags flags);
/// <summary>
/// Retrieves the index of the network interface corresponding to the specified name.
/// </summary>
/// <param name="name">Interface Name</param>
/// <returns>Interface Index on success, 0 on failure</returns>
[DllImport("libc", EntryPoint="if_nametoindex", SetLastError=true)]
public static extern uint IfNameToIndex(string name);
/// <summary>
/// Retrieves the name of the network interface corresponding to the specified index.
/// </summary>
/// <param name="index">Interface Index</param>
/// <param name="namePtr">Pointer to the buffer where the Interface Name is set</param>
/// <returns>Valid IntPtr pointing to a buffer containing the Interface Name on success, IntPtr.Zero (null) on failure.</returns>
[DllImport("libc", EntryPoint="if_indextoname", SetLastError=true)]
public static extern IntPtr IfIndexToName(uint index, IntPtr namePtr);
}
}