4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <sys/ioctl.h>
26 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <netinet/in.h>
35 static const char *epid_ns_uuid
= "fcacfb03-8a73-46ef-91b1-e5ebeeaba4fe";
37 #define UUID_OFFSET_TO_LAST_SEGMENT 24
39 void readUUID(const char *string
, sipe_uuid_t
*uuid
)
42 sscanf(string
, "%08x-%04hx-%04hx-%02hhx%02hhx-", &uuid
->time_low
43 , &uuid
->time_mid
, &uuid
->time_hi_and_version
44 , &uuid
->clock_seq_hi_and_reserved
45 , &uuid
->clock_seq_low
);
49 sscanf(&string
[UUID_OFFSET_TO_LAST_SEGMENT
+i
*2], "%02hhx", &uuid
->node
[i
]);
53 void printUUID(sipe_uuid_t
*uuid
, char *string
)
57 sprintf(string
, "%08x-%04x-%04x-%02x%02x-", uuid
->time_low
58 , uuid
->time_mid
, uuid
->time_hi_and_version
59 , uuid
->clock_seq_hi_and_reserved
65 pos
+= sprintf(&string
[pos
], "%02x", uuid
->node
[i
]);
69 void createUUIDfromHash(sipe_uuid_t
*uuid
, const unsigned char *hash
)
71 memcpy(uuid
, hash
, sizeof(sipe_uuid_t
));
72 uuid
->time_hi_and_version
&= 0x0FFF;
73 uuid
->time_hi_and_version
|= 0x5000;
74 uuid
->clock_seq_hi_and_reserved
&= 0x3F;
75 uuid
->clock_seq_hi_and_reserved
|= 0x80;
78 char *generateUUIDfromEPID(const gchar
*epid
)
81 PurpleCipherContext
*ctx
;
82 unsigned char hash
[20];
85 readUUID(epid_ns_uuid
, &result
);
86 memcpy(buf
, &result
, sizeof(sipe_uuid_t
));
87 sprintf(&buf
[sizeof(sipe_uuid_t
)], epid
);
89 ctx
= purple_cipher_context_new_by_name("sha1", NULL
);
90 purple_cipher_context_append(ctx
, buf
, strlen(buf
));
91 purple_cipher_context_digest(ctx
, sizeof(hash
), hash
, NULL
);
92 purple_cipher_context_destroy(ctx
);
94 createUUIDfromHash(&result
, hash
);
95 printUUID(&result
, buf
);
99 long mac_addr_sys (const char *addr
)
101 /* implementation for Linux */
109 s
= socket(AF_INET
, SOCK_DGRAM
, 0);
114 ifc
.ifc_len
= sizeof(buf
);
116 ioctl(s
, SIOCGIFCONF
, &ifc
);
119 for (i
= ifc
.ifc_len
/ sizeof(struct ifreq
); --i
>= 0; IFR
++) {
121 strcpy(ifr
.ifr_name
, IFR
->ifr_name
);
122 if (ioctl(s
, SIOCGIFFLAGS
, &ifr
) == 0) {
123 if (! (ifr
.ifr_flags
& IFF_LOOPBACK
)) {
124 if (ioctl(s
, SIOCGIFHWADDR
, &ifr
) == 0) {
134 memmove( addr
, ifr
.ifr_hwaddr
.sa_data
, 6);
142 gchar
* sipe_uuid_get_macaddr()
145 long mac_add
= mac_addr_sys(addr
);
150 for (i
= 0,j
=0; i
< 6; i
++,j
+=2) {
151 g_sprintf(&nmac
[j
], "%02X", addr
[i
]);
153 return g_strdup(nmac
);
155 return g_strdup_printf("01010101"); //Default