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
d01c88a1
Commit
d01c88a1
authored
7 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
more prototype code, gets ifname (unsuccessfully allocates memory for it though), gets IP & mask
parent
bf0605e6
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
common.c
+0
-1
0 additions, 1 deletion
common.c
dongle.c
+2
-2
2 additions, 2 deletions
dongle.c
dongle_infrastructure.c
+104
-60
104 additions, 60 deletions
dongle_infrastructure.c
with
106 additions
and
63 deletions
common.c
+
0
−
1
View file @
d01c88a1
...
@@ -15,7 +15,6 @@ TODO:
...
@@ -15,7 +15,6 @@ TODO:
char
*
get_ip
(
char
*
if_name
)
char
*
get_ip
(
char
*
if_name
)
{
{
char
response
[
1024
]
=
{
0
};
char
response
[
1024
]
=
{
0
};
size_t
filesize
;
int
rv
;
int
rv
;
FILE
*
fp
=
popen
(
"ubus call router.net ipv4_routes | grep -B 7
\"
usb0
\"
| grep
\"
flag.*H
\"
-B 4 | grep destination | cut -d ' ' -f2 | cut -d '
\"
' -f2"
,
"r"
);
FILE
*
fp
=
popen
(
"ubus call router.net ipv4_routes | grep -B 7
\"
usb0
\"
| grep
\"
flag.*H
\"
-B 4 | grep destination | cut -d ' ' -f2 | cut -d '
\"
' -f2"
,
"r"
);
...
...
This diff is collapsed.
Click to expand it.
dongle.c
+
2
−
2
View file @
d01c88a1
...
@@ -28,10 +28,10 @@ int parse_args(int argc, char **argv)
...
@@ -28,10 +28,10 @@ int parse_args(int argc, char **argv)
}
}
goto
done
;
goto
done
;
case
':'
:
case
':'
:
printf
(
stderr
,
"%s: option '-%c' requires an argument
\n
"
,
argv
[
0
],
optopt
);
f
printf
(
stderr
,
"%s: option '-%c' requires an argument
\n
"
,
argv
[
0
],
optopt
);
goto
fail
;
goto
fail
;
case
'?'
:
case
'?'
:
printf
(
stderr
,
"%s: option '-%c' is invalid: ignored
\n
"
,
argv
[
0
],
optopt
);
f
printf
(
stderr
,
"%s: option '-%c' is invalid: ignored
\n
"
,
argv
[
0
],
optopt
);
goto
fail
;
goto
fail
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
dongle_infrastructure.c
+
104
−
60
View file @
d01c88a1
...
@@ -2,10 +2,16 @@
...
@@ -2,10 +2,16 @@
#include
<dirent.h>
#include
<dirent.h>
#include
<sys/stat.h>
#include
<sys/stat.h>
#include
<stdlib.h>
#include
<stdlib.h>
#include
<sys/types.h>
#include
<sys/socket.h>
#include
<sys/ioctl.h>
#include
<netinet/in.h>
#include
<net/if.h>
#include
<arpa/inet.h>
#include
"dongle_infrastructure.h"
#include
"dongle_infrastructure.h"
char
*
dongle_ip
,
*
if_name
;
char
*
dongle_ip
;
/*int test_get_ip(struct ubus_context *ctx, struct ubus_object *obj,
/*int test_get_ip(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct ubus_request_data *req, const char *method,
...
@@ -24,6 +30,100 @@ char *dongle_ip, *if_name;
...
@@ -24,6 +30,100 @@ char *dongle_ip, *if_name;
return 0;
return 0;
}*/
}*/
char
*
get_device
(
void
)
{
char
*
path
,
*
device_name
,
device_path
[
1024
]
=
{
0
};
struct
dirent
*
de
;
DIR
*
dr
;
FILE
*
fp
;
struct
stat
st
;
fp
=
popen
(
"find /sys/devices/platform -type d -name
\"
net
\"
"
,
"r"
);
while
((
fgets
(
path
,
1024
,
fp
))
!=
NULL
)
{
printf
(
"11%s
\n
"
,
path
);
strncpy
(
device_path
,
path
,
(
strlen
(
path
)
-
1
));
printf
(
"%s%s
\n
"
,
path
,
device_path
);
dr
=
opendir
(
device_path
);
//free(device_path);
if
(
!
dr
)
{
perror
(
"opendir"
);
goto
fail
;
}
while
((
de
=
readdir
(
dr
))
!=
NULL
)
{
printf
(
"device name found %s!
\n
"
,
de
->
d_name
);
if
(
strcmp
(
de
->
d_name
,
"."
)
==
0
||
strcmp
(
de
->
d_name
,
".."
)
==
0
)
continue
;
if
(
fstatat
(
dirfd
(
dr
),
de
->
d_name
,
&
st
,
0
)
<
0
)
{
perror
(
"fstatat"
);
continue
;
}
if
(
!
S_ISDIR
(
st
.
st_mode
))
continue
;
if
(
!
strstr
(
de
->
d_name
,
"eth"
)
&&
!
strstr
(
de
->
d_name
,
"usb"
))
continue
;
/*device_name = (char *)calloc(strlen(de->d_name), sizeof(char));
if (!device_path) {
perror("calloc");
goto fail;
}*/
//free(device_name);
//strncpy(device_name, de->d_name, strlen(de->d_name));
goto
success
;
}
closedir
(
dr
);
}
fail:
pclose
(
fp
);
return
NULL
;
success:
closedir
(
dr
);
pclose
(
fp
);
return
NULL
;
}
char
*
get_device_ip
(
void
)
{
int
fd
;
struct
ifreq
ifr
;
char
*
device_name
,
*
device_ip
,
*
device_mask
;
//device_name = get_device();
//printf("device_name %s\n", device_name);
strncpy
(
ifr
.
ifr_name
,
"usb0"
,
IFNAMSIZ
-
1
);
fd
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
);
ifr
.
ifr_addr
.
sa_family
=
AF_INET
;
ifr
.
ifr_netmask
.
sa_family
=
AF_INET
;
//maybe?
ioctl
(
fd
,
SIOCGIFADDR
,
&
ifr
);
device_ip
=
strdup
(
inet_ntoa
(((
struct
sockaddr_in
*
)
&
ifr
.
ifr_addr
)
->
sin_addr
));
ioctl
(
fd
,
SIOCGIFNETMASK
,
&
ifr
);
device_mask
=
strdup
(
inet_ntoa
(((
struct
sockaddr_in
*
)
&
ifr
.
ifr_netmask
)
->
sin_addr
));
close
(
fd
);
/*device_ip = malloc(strlen(inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr)));
if (!device_ip) {
perror("malloc");
goto fail;
}*/
printf
(
"ip %s, mask %s
\n
"
,
device_ip
,
device_mask
);
free
(
device_ip
);
free
(
device_name
);
return
NULL
;
fail:
//free(device_name);
return
NULL
;
}
static
void
parse_devices
(
struct
ubus_request
*
req
,
int
type
,
struct
blob_attr
*
msg
)
static
void
parse_devices
(
struct
ubus_request
*
req
,
int
type
,
struct
blob_attr
*
msg
)
{
{
char
*
json_str
,
*
flags
,
*
ip
;
char
*
json_str
,
*
flags
,
*
ip
;
...
@@ -94,73 +194,17 @@ fail:
...
@@ -94,73 +194,17 @@ fail:
return
0
;
return
0
;
}
}
int
get_ifname
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
int
get_ifname
_ip
(
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
)
{
{
char
*
path
,
*
device_name
,
device_path
[
1024
]
=
{
0
};
get_device_ip
();
struct
dirent
*
de
;
DIR
*
dr
;
FILE
*
fp
,
*
inner_fp
;
struct
stat
st
;
fp
=
popen
(
"find /sys/devices/platform -type d -name
\"
net
\"
"
,
"r"
);
while
((
fgets
(
path
,
1024
,
fp
))
!=
NULL
)
{
/* why doesn't this work...
device_name = (char *) calloc(strlen(path), sizeof(char));
if (!device_path) {
perror("calloc");
goto fail;
}
*/
printf
(
"%s
\n
"
,
path
);
strncpy
(
device_path
,
path
,
(
strlen
(
path
)
-
1
));
printf
(
"%s%s
\n
"
,
path
,
device_path
);
dr
=
opendir
(
device_path
);
free
(
device_path
);
if
(
!
dr
)
{
perror
(
"opendir"
);
goto
fail
;
}
while
((
de
=
readdir
(
dr
))
!=
NULL
)
{
printf
(
"device name found %s!
\n
"
,
de
->
d_name
);
if
(
strcmp
(
de
->
d_name
,
"."
)
==
0
||
strcmp
(
de
->
d_name
,
".."
)
==
0
)
continue
;
if
(
fstatat
(
dirfd
(
dr
),
de
->
d_name
,
&
st
,
0
)
<
0
)
{
perror
(
"fstatat"
);
continue
;
}
if
(
!
S_ISDIR
(
st
.
st_mode
))
continue
;
if
(
!
strstr
(
de
->
d_name
,
"eth"
)
&&
!
strstr
(
de
->
d_name
,
"usb"
))
continue
;
//if_name = strdup(de->d_name);
printf
(
"And we have a winner %s!
\n
"
,
de
->
d_name
);
goto
success
;
}
printf
(
"and null it is!
\n
"
);
closedir
(
dr
);
}
fail:
pclose
(
fp
);
return
-
1
;
success:
closedir
(
dr
);
pclose
(
fp
);
return
0
;
return
0
;
}
}
struct
ubus_method
infrastructure_object_methods
[]
=
{
struct
ubus_method
infrastructure_object_methods
[]
=
{
//UBUS_METHOD("get_ip", test_get_ip, ip_policy),
UBUS_METHOD_NOARG
(
"get_ip_invoke"
,
get_ip_invoke
),
UBUS_METHOD_NOARG
(
"get_ip_invoke"
,
get_ip_invoke
),
UBUS_METHOD_NOARG
(
"get_ifname"
,
get_ifname
)
,
UBUS_METHOD_NOARG
(
"get_ifname
_ip
"
,
get_ifname
_ip
)
};
};
struct
ubus_object_type
infrastructure_object_type
=
UBUS_OBJECT_TYPE
(
"dongle"
,
infrastructure_object_methods
);
struct
ubus_object_type
infrastructure_object_type
=
UBUS_OBJECT_TYPE
(
"dongle"
,
infrastructure_object_methods
);
...
...
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