Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mdmngr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
IOPSYS
mdmngr
Commits
d1074c34
Commit
d1074c34
authored
7 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
clean up & refactor getting device ip address through route
parent
6e733777
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dongle_infrastructure.c
+11
-22
11 additions, 22 deletions
dongle_infrastructure.c
dongle_infrastructure.h
+1
-1
1 addition, 1 deletion
dongle_infrastructure.h
with
12 additions
and
23 deletions
dongle_infrastructure.c
+
11
−
22
View file @
d1074c34
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
#include
<sys/types.h>
#include
<sys/types.h>
#include
<dirent.h>
#include
<dirent.h>
#include
<sys/stat.h>
#include
<sys/stat.h>
#include
<stdlib.h>
#include
<sys/types.h>
#include
<sys/types.h>
#include
<sys/socket.h>
#include
<sys/socket.h>
#include
<sys/ioctl.h>
#include
<sys/ioctl.h>
...
@@ -381,8 +380,7 @@ fail:
...
@@ -381,8 +380,7 @@ fail:
return
NULL
;
return
NULL
;
}
}
/*for testing, taken from stackoverflow*/
char
*
string_to_binary
(
char
*
s
)
{
char
*
stringToBinary
(
char
*
s
)
{
size_t
len
;
size_t
len
;
char
*
binary
,
ch
;
char
*
binary
,
ch
;
int
i
,
j
;
int
i
,
j
;
...
@@ -413,7 +411,8 @@ fail:
...
@@ -413,7 +411,8 @@ fail:
char
*
get_device_ip_alt
(
char
*
device_name
)
char
*
get_device_ip_alt
(
char
*
device_name
)
{
{
char
*
iface
,
*
destination
,
*
gateway
,
*
flags
,
*
route
;
char
*
iface
,
*
destination
,
*
gateway
,
*
flags
,
*
route
,
*
binary
,
ipv4_addr
[
IPV4_MAX
];
uint32_t
dec_addr
;
FILE
*
fp
;
FILE
*
fp
;
fp
=
fopen
(
"/proc/net/route"
,
"r"
);
fp
=
fopen
(
"/proc/net/route"
,
"r"
);
...
@@ -426,11 +425,6 @@ char *get_device_ip_alt(char *device_name)
...
@@ -426,11 +425,6 @@ char *get_device_ip_alt(char *device_name)
memset
(
route
,
0
,
1024
);
memset
(
route
,
0
,
1024
);
while
((
fgets
(
route
,
1024
,
fp
))
!=
NULL
)
{
while
((
fgets
(
route
,
1024
,
fp
))
!=
NULL
)
{
remove_newline
(
route
);
remove_newline
(
route
);
/*
1. delimiter on first tab, check if = usb0, else continue
2. delimiter on 4th tab, convert to binary, check if 3rd bit = 1, else continue
3. get destintion ip
*/
iface
=
lexer
(
&
route
,
"
\t
"
);
iface
=
lexer
(
&
route
,
"
\t
"
);
destination
=
lexer
(
&
route
,
"
\t
"
);
destination
=
lexer
(
&
route
,
"
\t
"
);
...
@@ -440,18 +434,13 @@ char *get_device_ip_alt(char *device_name)
...
@@ -440,18 +434,13 @@ char *get_device_ip_alt(char *device_name)
if
(
strncmp
(
iface
,
device_name
,
10
)
!=
0
)
if
(
strncmp
(
iface
,
device_name
,
10
)
!=
0
)
continue
;
continue
;
char
*
tmp_var_
;
binary
=
string_to_binary
(
flags
);
tmp_var_
=
stringToBinary
(
flags
);
printf
(
"%s %c
\n
"
,
binary
,
binary
[(
strlen
(
binary
)
-
3
)]);
printf
(
"%s %c
\n
"
,
tmp_var_
,
tmp_var_
[(
strlen
(
tmp_var_
)
-
3
)]);
if
(
binary
[(
strlen
(
binary
)
-
3
)]
==
'1'
)
{
if
(
tmp_var_
[(
strlen
(
tmp_var_
)
-
3
)]
==
'1'
)
{
dec_addr
=
strtoul
(
destination
,
NULL
,
IPV4_MAX
);
printf
(
"host addr %s
\n
"
,
destination
);
inet_ntop
(
AF_INET
,
&
dec_addr
,
ipv4_addr
,
IPV4_MAX
);
char
*
ptr
;
printf
(
"ipv4_addr %s
\n
"
,
ipv4_addr
);
char
test2
[
1024
];
uint32_t
test
=
strtoul
(
destination
,
&
ptr
,
16
);
test
=
strtoul
(
destination
,
&
ptr
,
16
);
inet_ntop
(
AF_INET
,
&
test
,
test2
,
1024
);
printf
(
"%s
\n
"
,
test2
);
}
}
}
}
fclose
(
fp
);
fclose
(
fp
);
...
@@ -582,7 +571,7 @@ int test(struct ubus_context *ctx, struct ubus_object *obj,
...
@@ -582,7 +571,7 @@ int test(struct ubus_context *ctx, struct ubus_object *obj,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
)
struct
blob_attr
*
msg
)
{
{
get_device_ip_alt
(
"
eth0.1
"
);
get_device_ip_alt
(
"
usb0
"
);
return
0
;
return
0
;
}
}
...
...
This diff is collapsed.
Click to expand it.
dongle_infrastructure.h
+
1
−
1
View file @
d1074c34
#ifndef INFRASTRUCTURE_H
#ifndef INFRASTRUCTURE_H
#define INFRASTRUCTURE_H
#define INFRASTRUCTURE_H
#include
"common.h"
#include
"common.h"
#define IPV4_MAX 16
struct
USB
{
struct
USB
{
char
*
product
;
char
*
product
;
char
*
product_id
;
char
*
product_id
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment