SOEM
oshw
win32
win32/oshw.c
Go to the documentation of this file.
1
/*
2
* Licensed under the GNU General Public License version 2 with exceptions. See
3
* LICENSE file in the project root for full license information
4
*/
5
6
#include "
oshw.h
"
7
14
uint16
oshw_htons
(
uint16
host)
15
{
16
uint16
network = htons (host);
17
return
network;
18
}
19
26
uint16
oshw_ntohs
(
uint16
network)
27
{
28
uint16
host = ntohs (network);
29
return
host;
30
}
31
32
/* Create list over available network adapters.
33
* @return First element in linked list of adapters
34
*/
35
ec_adaptert
*
oshw_find_adapters
(
void
)
36
{
37
int
i = 0;
38
int
ret = 0;
39
pcap_if_t
*alldevs;
40
pcap_if_t
*d;
41
ec_adaptert
* adapter;
42
ec_adaptert
* prev_adapter;
43
ec_adaptert
* ret_adapter = NULL;
44
char
errbuf
[
PCAP_ERRBUF_SIZE
];
45
size_t
string_len;
46
47
/* find all devices */
48
if
(
pcap_findalldevs
(&alldevs,
errbuf
) == -1)
49
{
50
fprintf(stderr,
"Error in pcap_findalldevs_ex: %s\n"
,
errbuf
);
51
return
(NULL);
52
}
53
/* Iterate all devices and create a local copy holding the name and
54
* description.
55
*/
56
for
(d= alldevs; d != NULL; d= d->
next
)
57
{
58
adapter = (
ec_adaptert
*)malloc(
sizeof
(
ec_adaptert
));
59
/* If we got more than one adapter save link list pointer to previous
60
* adapter.
61
* Else save as pointer to return.
62
*/
63
if
(i)
64
{
65
prev_adapter->
next
= adapter;
66
}
67
else
68
{
69
ret_adapter = adapter;
70
}
71
72
/* fetch description and name of the device from libpcap */
73
adapter->
next
= NULL;
74
if
(d->
name
)
75
{
76
string_len = strlen(d->
name
);
77
if
(string_len > (
EC_MAXLEN_ADAPTERNAME
- 1))
78
{
79
string_len =
EC_MAXLEN_ADAPTERNAME
- 1;
80
}
81
strncpy(adapter->
name
, d->
name
,string_len);
82
adapter->
name
[string_len] =
'\0'
;
83
}
84
else
85
{
86
adapter->
name
[0] =
'\0'
;
87
}
88
if
(d->
description
)
89
{
90
string_len = strlen(d->
description
);
91
if
(string_len > (
EC_MAXLEN_ADAPTERNAME
- 1))
92
{
93
string_len =
EC_MAXLEN_ADAPTERNAME
- 1;
94
}
95
strncpy(adapter->
desc
, d->
description
,string_len);
96
adapter->
desc
[string_len] =
'\0'
;
97
}
98
else
99
{
100
adapter->
desc
[0] =
'\0'
;
101
}
102
prev_adapter = adapter;
103
i++;
104
}
105
/* free all devices allocated */
106
pcap_freealldevs
(alldevs);
107
108
return
ret_adapter;
109
}
110
115
void
oshw_free_adapters
(
ec_adaptert
* adapter)
116
{
117
ec_adaptert
* next_adapter;
118
/* Iterate the linked list and free all elements holding
119
* adapter information
120
*/
121
if
(adapter)
122
{
123
next_adapter = adapter->
next
;
124
free (adapter);
125
while
(next_adapter)
126
{
127
adapter = next_adapter;
128
next_adapter = adapter->
next
;
129
free (adapter);
130
}
131
}
132
}
EC_MAXLEN_ADAPTERNAME
#define EC_MAXLEN_ADAPTERNAME
Definition:
ethercatmain.h:39
oshw.h
Headerfile for ethercatbase.c.
ec_adapter
Definition:
ethercatmain.h:44
oshw_htons
uint16 oshw_htons(uint16 host)
Definition:
win32/oshw.c:14
oshw_ntohs
uint16 oshw_ntohs(uint16 network)
Definition:
win32/oshw.c:26
ec_adapter::next
ec_adaptert * next
Definition:
ethercatmain.h:48
ec_adapter::desc
char desc[EC_MAXLEN_ADAPTERNAME]
Definition:
ethercatmain.h:47
oshw_find_adapters
ec_adaptert * oshw_find_adapters(void)
Definition:
win32/oshw.c:35
uint16
uint16_t uint16
Definition:
osal.h:29
errbuf
static char errbuf[PCAP_ERRBUF_SIZE]
Definition:
macosx/nicdrv.c:68
pcap_if::description
char * description
Definition:
pcap/pcap.h:226
pcap_if::name
char * name
Definition:
pcap/pcap.h:225
pcap_freealldevs
void pcap_freealldevs(pcap_if_t *)
pcap_if
Definition:
pcap/pcap.h:223
ec_adapter::name
char name[EC_MAXLEN_ADAPTERNAME]
Definition:
ethercatmain.h:46
pcap_if::next
struct pcap_if * next
Definition:
pcap/pcap.h:224
PCAP_ERRBUF_SIZE
#define PCAP_ERRBUF_SIZE
Definition:
pcap/pcap.h:76
pcap_findalldevs
int pcap_findalldevs(pcap_if_t **, char *)
oshw_free_adapters
void oshw_free_adapters(ec_adaptert *adapter)
Definition:
win32/oshw.c:115
soem
Author(s): Arthur Ketels and M.J.G. van den Molengraft
autogenerated on Wed Mar 2 2022 01:01:49