Main Page
Related Pages
Modules
Classes
Files
File List
File Members
oshw
win32
win32/oshw.c
Go to the documentation of this file.
1
/******************************************************************************
2
* * *** ***
3
* *** *** ***
4
* *** **** ********** *** ***** *** **** *****
5
* ********* ********** *** ********* ************ *********
6
* **** *** *** *** *** **** ***
7
* *** *** ****** *** *********** *** **** *****
8
* *** *** ****** *** ************* *** **** *****
9
* *** **** **** *** *** *** **** ***
10
* *** ******* ***** ************** ************* *********
11
* *** ***** *** ******* ** ** ****** *****
12
* t h e r e a l t i m e t a r g e t e x p e r t s
13
*
14
* http://www.rt-labs.com
15
* Copyright (C) 2009. rt-labs AB, Sweden. All rights reserved.
16
*------------------------------------------------------------------------------
17
* $Id: oshw.c 411 2012-12-02 20:16:39Z rtlaka $
18
*------------------------------------------------------------------------------
19
*/
20
21
#include "
oshw.h
"
22
29
uint16
oshw_htons
(
uint16
host)
30
{
31
uint16
network = htons (host);
32
return
network;
33
}
34
41
uint16
oshw_ntohs
(
uint16
network)
42
{
43
uint16
host = ntohs (network);
44
return
host;
45
}
46
47
/* Create list over available network adapters.
48
* @return First element in linked list of adapters
49
*/
50
ec_adaptert
*
oshw_find_adapters
(
void
)
51
{
52
int
i = 0;
53
int
ret = 0;
54
pcap_if_t
*alldevs;
55
pcap_if_t
*d;
56
ec_adaptert
* adapter;
57
ec_adaptert
* prev_adapter;
58
ec_adaptert
* ret_adapter = NULL;
59
char
errbuf
[
PCAP_ERRBUF_SIZE
];
60
size_t
string_len;
61
62
/* find all devices */
63
if
(
pcap_findalldevs
(&alldevs, errbuf) == -1)
64
{
65
fprintf(stderr,
"Error in pcap_findalldevs_ex: %s\n"
, errbuf);
66
return
(NULL);
67
}
68
/* Iterate all devices and create a local copy holding the name and
69
* decsription.
70
*/
71
for
(d= alldevs; d != NULL; d= d->
next
)
72
{
73
adapter = (
ec_adaptert
*)malloc(
sizeof
(
ec_adaptert
));
74
/* If we got more than one adapter save link list pointer to previous
75
* adapter.
76
* Else save as pointer to return.
77
*/
78
if
(i)
79
{
80
prev_adapter->
next
= adapter;
81
}
82
else
83
{
84
ret_adapter = adapter;
85
}
86
87
/* fetch description and name of the divice from libpcap */
88
adapter->
next
= NULL;
89
if
(d->
name
)
90
{
91
string_len = strlen(d->
name
);
92
if
(string_len > (
EC_MAXLEN_ADAPTERNAME
- 1))
93
{
94
string_len =
EC_MAXLEN_ADAPTERNAME
- 1;
95
}
96
strncpy(adapter->
name
, d->
name
,string_len);
97
adapter->
name
[string_len] =
'\0'
;
98
}
99
else
100
{
101
adapter->
name
[0] =
'\0'
;
102
}
103
if
(d->
description
)
104
{
105
string_len = strlen(d->
description
);
106
if
(string_len > (
EC_MAXLEN_ADAPTERNAME
- 1))
107
{
108
string_len =
EC_MAXLEN_ADAPTERNAME
- 1;
109
}
110
strncpy(adapter->
desc
, d->
description
,string_len);
111
adapter->
desc
[string_len] =
'\0'
;
112
}
113
else
114
{
115
adapter->
desc
[0] =
'\0'
;
116
}
117
prev_adapter = adapter;
118
i++;
119
}
120
/* free all devices allocated */
121
pcap_freealldevs
(alldevs);
122
123
return
ret_adapter;
124
}
125
130
void
oshw_free_adapters
(
ec_adaptert
* adapter)
131
{
132
ec_adaptert
* next_adapter;
133
/* Iterate the linked list and free all elemnts holding
134
* adapter information
135
*/
136
if
(adapter)
137
{
138
next_adapter = adapter->
next
;
139
free (adapter);
140
while
(next_adapter)
141
{
142
adapter = next_adapter;
143
next_adapter = adapter->
next
;
144
free (adapter);
145
}
146
}
147
}
pcap_findalldevs
int pcap_findalldevs(pcap_if_t **, char *)
EC_MAXLEN_ADAPTERNAME
#define EC_MAXLEN_ADAPTERNAME
Definition:
ethercatmain.h:74
ec_adapter::name
char name[EC_MAXLEN_ADAPTERNAME]
Definition:
ethercatmain.h:79
ec_adapter::next
ec_adaptert * next
Definition:
ethercatmain.h:81
errbuf
static char errbuf[PCAP_ERRBUF_SIZE]
Definition:
win32/nicdrv.c:108
pcap_if::name
char * name
Definition:
pcap/pcap.h:225
uint16
uint16_t uint16
Definition:
osal.h:34
pcap_if::description
char * description
Definition:
pcap/pcap.h:226
oshw.h
Headerfile for ethercatbase.c.
ec_adapter::desc
char desc[EC_MAXLEN_ADAPTERNAME]
Definition:
ethercatmain.h:80
ec_adapter
Definition:
ethercatmain.h:77
oshw_htons
uint16 oshw_htons(uint16 host)
Definition:
win32/oshw.c:29
oshw_free_adapters
void oshw_free_adapters(ec_adaptert *adapter)
Definition:
win32/oshw.c:130
pcap_if::next
struct pcap_if * next
Definition:
pcap/pcap.h:224
pcap_if
Definition:
pcap/pcap.h:223
pcap_freealldevs
void pcap_freealldevs(pcap_if_t *)
oshw_ntohs
uint16 oshw_ntohs(uint16 network)
Definition:
win32/oshw.c:41
oshw_find_adapters
ec_adaptert * oshw_find_adapters(void)
Definition:
win32/oshw.c:50
PCAP_ERRBUF_SIZE
#define PCAP_ERRBUF_SIZE
Definition:
pcap/pcap.h:76
soem
Author(s): Arthur Ketels and M.J.G. van den Molengraft
autogenerated on Sat Jun 8 2019 18:02:17