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
, 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(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(uuid_t
*uuid
, const unsigned char *hash
)
71 memcpy(uuid
, hash
, sizeof(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(uuid_t
));
87 printf("have epid == NULL? %i\n", epid
== NULL
);
88 printf("have epid: '%s'\n", epid
);
89 printf("have sizeof uuid_t: %d\n", sizeof(uuid_t
));
90 sprintf(&buf
[sizeof(uuid_t
)], epid
);
92 ctx
= purple_cipher_context_new_by_name("sha1", NULL
);
93 purple_cipher_context_append(ctx
, buf
, strlen(buf
));
94 purple_cipher_context_digest(ctx
, sizeof(hash
), hash
, NULL
);
95 purple_cipher_context_destroy(ctx
);
97 createUUIDfromHash(&result
, hash
);
98 printUUID(&result
, buf
);
102 long mac_addr_sys (const char *addr
)
104 /* implementation for Linux */
112 s
= socket(AF_INET
, SOCK_DGRAM
, 0);
117 ifc
.ifc_len
= sizeof(buf
);
119 ioctl(s
, SIOCGIFCONF
, &ifc
);
122 for (i
= ifc
.ifc_len
/ sizeof(struct ifreq
); --i
>= 0; IFR
++) {
124 strcpy(ifr
.ifr_name
, IFR
->ifr_name
);
125 if (ioctl(s
, SIOCGIFFLAGS
, &ifr
) == 0) {
126 if (! (ifr
.ifr_flags
& IFF_LOOPBACK
)) {
127 if (ioctl(s
, SIOCGIFHWADDR
, &ifr
) == 0) {
137 bcopy( ifr
.ifr_hwaddr
.sa_data
, addr
, 6);
145 gchar
* sipe_uuid_get_macaddr()
148 long mac_add
= mac_addr_sys(addr
);
153 for (i
= 0,j
=0; i
< 6; i
++,j
+=2) {
154 g_sprintf(&nmac
[j
], "%02X", addr
[i
]);
156 printf("Returning mac: '%s'\n", nmac
);
157 return g_strdup(nmac
);
159 printf("Returning default mac\n");
160 return g_strdup_printf("01010101"); //Default