aboutsummaryrefslogtreecommitdiffstats
path: root/samsung-ipc/misc.c
blob: b766b3c524d8f0cf2f7724901b7c0013200be7fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * This file is part of libsamsung-ipc.
 *
 * Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
 * Copyright (C) 2014 Paul Kocialkowski <contact@paulk.fr>
 *
 * libsamsung-ipc is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * libsamsung-ipc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with libsamsung-ipc.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdlib.h>
#include <string.h>

#include <samsung-ipc.h>

char *ipc_misc_me_imsi_imsi_extract(const void *data, size_t size)
{
    struct ipc_misc_me_imsi_header *header;
    char *imsi;
    size_t imsi_length;

    if (data == NULL || size < sizeof(struct ipc_misc_me_imsi_header))
        return NULL;

    header = (struct ipc_misc_me_imsi_header *) data;

    // header->length doesn't count the final null character
    imsi_length = header->length + sizeof(char);

    imsi = (char *) calloc(1, imsi_length);

    strncpy(imsi, (char *) data + sizeof(struct ipc_misc_me_imsi_header), header->length);
    imsi[header->length] = '\0';

    return imsi;
}

// vim:ts=4:sw=4:expandtab