Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
soem
oshw
linux
linux/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 282 2012-09-25 10:52:42Z rtlaka $
18
*------------------------------------------------------------------------------
19
*/
20
21
#include <sys/ioctl.h>
22
#include <net/if.h>
23
#include <sys/socket.h>
24
#include <arpa/inet.h>
25
#include <stdio.h>
26
#include <stdlib.h>
27
#include <string.h>
28
#include "oshw.h"
29
36
uint16
oshw_htons
(
uint16
host)
37
{
38
uint16
network = htons (host);
39
return
network;
40
}
41
48
uint16
oshw_ntohs
(
uint16
network)
49
{
50
uint16
host = ntohs (network);
51
return
host;
52
}
53
57
ec_adaptert
*
oshw_find_adapters
(
void
)
58
{
59
int
i;
60
int
string_len;
61
struct
if_nameindex *ids;
62
ec_adaptert
* adapter;
63
ec_adaptert
* prev_adapter;
64
ec_adaptert
* ret_adapter = NULL;
65
66
67
/* Iterate all devices and create a local copy holding the name and
68
* decsription.
69
*/
70
71
ids = if_nameindex ();
72
for
(i = 0; ids[i].if_index != 0; i++)
73
{
74
adapter = (
ec_adaptert
*)malloc(
sizeof
(
ec_adaptert
));
75
/* If we got more than one adapter save link list pointer to previous
76
* adapter.
77
* Else save as pointer to return.
78
*/
79
if
(i)
80
{
81
prev_adapter->
next
= adapter;
82
}
83
else
84
{
85
ret_adapter = adapter;
86
}
87
88
/* fetch description and name, in linux we use the same on both */
89
adapter->
next
= NULL;
90
91
if
(ids[i].if_name)
92
{
93
string_len = strlen(ids[i].if_name);
94
if
(string_len > (
EC_MAXLEN_ADAPTERNAME
- 1))
95
{
96
string_len =
EC_MAXLEN_ADAPTERNAME
- 1;
97
}
98
strncpy(adapter->
name
, ids[i].if_name,string_len);
99
adapter->
name
[string_len] =
'\0'
;
100
strncpy(adapter->
desc
, ids[i].if_name,string_len);
101
adapter->
desc
[string_len] =
'\0'
;
102
}
103
else
104
{
105
adapter->
name
[0] =
'\0'
;
106
adapter->
desc
[0] =
'\0'
;
107
}
108
109
prev_adapter = adapter;
110
}
111
112
if_freenameindex (ids);
113
114
return
ret_adapter;
115
}
116
121
void
oshw_free_adapters
(
ec_adaptert
* adapter)
122
{
123
ec_adaptert
* next_adapter;
124
/* Iterate the linked list and free all elemnts holding
125
* adapter information
126
*/
127
if
(adapter)
128
{
129
next_adapter = adapter->
next
;
130
free (adapter);
131
while
(next_adapter)
132
{
133
adapter = next_adapter;
134
next_adapter = adapter->
next
;
135
free (adapter);
136
}
137
}
138
}
EC_MAXLEN_ADAPTERNAME
#define EC_MAXLEN_ADAPTERNAME
Definition:
ethercatmain.h:74
oshw_ntohs
uint16 oshw_ntohs(uint16 network)
Definition:
linux/oshw.c:48
ec_adapter::name
char name[EC_MAXLEN_ADAPTERNAME]
Definition:
ethercatmain.h:79
ec_adapter::next
ec_adaptert * next
Definition:
ethercatmain.h:81
oshw_find_adapters
ec_adaptert * oshw_find_adapters(void)
Definition:
linux/oshw.c:57
oshw_free_adapters
void oshw_free_adapters(ec_adaptert *adapter)
Definition:
linux/oshw.c:121
uint16
uint16_t uint16
Definition:
osal.h:34
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:
linux/oshw.c:36
youbot_driver
Author(s): Jan Paulus
autogenerated on Mon Jun 10 2019 15:46:24