Skip to content
Snippets Groups Projects
Commit 6f6fc320 authored by Jakob Olsson's avatar Jakob Olsson
Browse files

prepare for get ip from if_name, small error fixes

parent bb272ad8
Branches
No related tags found
No related merge requests found
#include "common.h"
int get_ip(char *if_name)
{
struct ifaddrs *ifaddr, *ifa;
int s;
char host[NI_MAXHOST];
if (strlen(if_name) == 0)
return -1;
if (getifaddrs(&ifaddr) == -1) {
perror("getifaddrs");
return -1;
}
ifa = ifaddr;
while (ifa != NULL) {
if (strncmp(ifa->ifa_name, if_name, 10) != 0) {
ifa = ifa->ifa_next;
continue;
}
s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
if (s != 0) {
printf("hello %s\n", ifa->ifa_addr->sa_data);
printf("getnameinfo() failed12312323: %s\n", gai_strerror(s));
return -1;
}
if(ifa->ifa_addr->sa_family == AF_INET) {
printf("ip %s\n", host);
}
}
return 0;
}
int print_to_ubus(struct json_object *parsed_response, struct ubus_context *ctx, struct ubus_request_data *req)
{
struct blob_buf bb;
......
......@@ -12,6 +12,9 @@
#include <time.h>
#include <limits.h>
#include <libubox/list.h>
#include <ifaddrs.h>
#include <sys/socket.h>
#include <netdb.h>
#include "libmobile.h"
#include <json-c/json.h>
......@@ -22,11 +25,12 @@
extern int debug;
#define debug_print(...) \
do \
{ \
do { \
if (debug) \
fprintf(stderr, __VA_ARGS__); \
} while (0)
int get_ip(char *if_name);
/**
* Function: print_to_ubus
*
......@@ -56,6 +60,4 @@ int print_to_ubus(struct json_object *parsed_response, struct ubus_context *ctx,
* Blob buffer containing the replicated json_object.
*/
struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb);
void check_debug(void);
#endif
......@@ -60,8 +60,6 @@ int main(int argc, char **argv)
if (rv < 0)
goto fail;
printf("hello\n");
uloop_init();
init_ubus();
......
......@@ -2,13 +2,14 @@
static enum {
IP,
__IP_MAX,
DEV,
__IP_MAX
};
enum {
IP1,
APN_NAME,
__APN_MAX,
__APN_MAX
};
enum {
......@@ -16,23 +17,24 @@ enum {
PROFILE_NAME,
WAN_APN,
PDP_TYPE,
__CREATE_MAX,
__CREATE_MAX
};
static const struct blobmsg_policy ip_policy[__IP_MAX] = {
[IP] = {.name = "ip_addr", .type = BLOBMSG_TYPE_STRING},
[DEV] = {.name = "if_name", .type = BLOBMSG_TYPE_STRING}
};
const struct blobmsg_policy apn_policy[__APN_MAX] = {
[IP1] = {.name = "ip_addr", .type = BLOBMSG_TYPE_STRING},
[APN_NAME] = {.name = "profile_name", .type = BLOBMSG_TYPE_STRING},
[APN_NAME] = {.name = "profile_name", .type = BLOBMSG_TYPE_STRING}
};
const struct blobmsg_policy create_apn_policy[__CREATE_MAX] = {
[IP2] = {.name = "ip_addr", .type = BLOBMSG_TYPE_STRING},
[PROFILE_NAME] = {.name = "profile_name", .type = BLOBMSG_TYPE_STRING},
[WAN_APN] = {.name = "wan_apn", .type = BLOBMSG_TYPE_STRING},
[PDP_TYPE] = {.name = "pdp_type", .type = BLOBMSG_TYPE_STRING},
[PDP_TYPE] = {.name = "pdp_type", .type = BLOBMSG_TYPE_STRING}
};
int list_apn_profiles(struct ubus_context *ctx, struct ubus_object *obj,
......@@ -40,19 +42,23 @@ int list_apn_profiles(struct ubus_context *ctx, struct ubus_object *obj,
struct blob_attr *msg)
{
struct blob_attr *tb[__IP_MAX];
char *ip_addr;
char *ip_addr, *dev;
struct json_object *response;
blobmsg_parse(ip_policy, __IP_MAX, tb, blob_data(msg), blob_len(msg));
if (!tb[IP]) {
debug_print("Please enter both an IP address!\n");
debug_print("Please enter an IP or DEV!\n");
goto fail_argument;
}
ip_addr = (char *)blobmsg_data(tb[IP]);
} else
ip_addr = (char *)blobmsg_data(tb[IP]);
if (tb[DEV]) {
printf("hello\n");
dev = (char *)blobmsg_data(tb[DEV]);
get_ip(dev);
}
response = mobile_get_apn_profiles(ip_addr);
if (!response)
goto fail_unknown;
......
......@@ -2,11 +2,11 @@
static enum {
IP,
__IP_MAX,
__IP_MAX
};
static const struct blobmsg_policy ip_policy[__IP_MAX] = {
[IP] = {.name = "ip_addr", .type = BLOBMSG_TYPE_STRING},
[IP] = {.name = "ip_addr", .type = BLOBMSG_TYPE_STRING}
};
int get_signal_strength(struct ubus_context *ctx, struct ubus_object *obj,
......
......@@ -7,25 +7,25 @@ enum {
IP1,
NEW_PIN,
CURRENT_PIN,
__SET_PIN_MAX,
__SET_PIN_MAX
};
enum {
IP2,
PIN,
__PIN_MAX,
__PIN_MAX
};
enum {
IP3,
__TRY_MAX,
__TRY_MAX
};
enum {
IP4,
UNLOCK_PIN,
PUK,
__UNLOCK_MAX,
__UNLOCK_MAX
};
const struct blobmsg_policy set_pin_policy[__SET_PIN_MAX] = {
......@@ -403,7 +403,7 @@ int unlock_sim(struct ubus_context *ctx, struct ubus_object *obj,
struct blob_attr *msg)
{
struct blob_attr *tb[__UNLOCK_MAX];
char *pin, *puk, ip_addr;
char *pin, *puk, *ip_addr;
struct json_object *response, *rv_json;
int rv;
......@@ -419,7 +419,7 @@ int unlock_sim(struct ubus_context *ctx, struct ubus_object *obj,
if (!response)
goto fail_unknown;
json_object_object_get_ex(response, "pinnumber", rv_json);
json_object_object_get_ex(response, "pinnumber", &rv_json);
if (json_object_get_int(rv_json) > 0)
goto fail_unknown;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment