Remove WPA2 and WPA3 service together
[platform/upstream/connman.git] / gdhcp / ipv4ll.c
1 /*
2  *
3  *  IPV4 Local Link library with GLib integration
4  *
5  *  Copyright (C) 2009-2010  Aldebaran Robotics. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21 #include <string.h>
22 #include <stdlib.h>
23 #include <errno.h>
24 #include <unistd.h>
25
26 #include <sys/time.h>
27 #include <sys/socket.h>
28 #include <sys/types.h>
29 #include <netpacket/packet.h>
30 #include <net/ethernet.h>
31 #include <netinet/if_ether.h>
32
33 #include <arpa/inet.h>
34
35 #include <glib.h>
36 #include "ipv4ll.h"
37 #include "common.h"
38 #include "../src/connman.h"
39
40 /**
41  * Return a random link local IP (in host byte order)
42  */
43 uint32_t ipv4ll_random_ip(void)
44 {
45         unsigned tmp;
46         uint64_t rand;
47
48         do {
49                 __connman_util_get_random(&rand);
50                 tmp = rand;
51                 tmp = tmp & IN_CLASSB_HOST;
52         } while (tmp > (IN_CLASSB_HOST - 0x0200));
53         return ((LINKLOCAL_ADDR + 0x0100) + tmp);
54 }
55